Coverage for colour/algebra/tests/test_regression.py: 100%
20 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""Define the unit tests for the :mod:`colour.algebra.regression` module."""
3from __future__ import annotations
5import numpy as np
7from colour.algebra import least_square_mapping_MoorePenrose
8from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10__author__ = "Colour Developers"
11__copyright__ = "Copyright 2013 Colour Developers"
12__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
13__maintainer__ = "Colour Developers"
14__email__ = "colour-developers@colour-science.org"
15__status__ = "Production"
17__all__ = [
18 "TestLeastSquareMappingMoorePenrose",
19]
22class TestLeastSquareMappingMoorePenrose:
23 """
24 Define :func:`colour.algebra.regression.\
25least_square_mapping_MoorePenrose` definition unit tests methods.
26 """
28 def test_least_square_mapping_MoorePenrose(self) -> None:
29 """
30 Test :func:`colour.algebra.regression.\
31least_square_mapping_MoorePenrose` definition.
32 """
34 prng = np.random.RandomState(2)
35 y = prng.random_sample((24, 3))
36 x = y + (prng.random_sample((24, 3)) - 0.5) * 0.5
38 np.testing.assert_allclose(
39 least_square_mapping_MoorePenrose(y, x),
40 np.array(
41 [
42 [1.05263767, 0.13780789, -0.22763399],
43 [0.07395843, 1.02939945, -0.10601150],
44 [0.05725508, -0.20526336, 1.10151945],
45 ]
46 ),
47 atol=TOLERANCE_ABSOLUTE_TESTS,
48 )
50 y = prng.random_sample((4, 3, 2))
51 x = y + (prng.random_sample((4, 3, 2)) - 0.5) * 0.5
52 np.testing.assert_allclose(
53 least_square_mapping_MoorePenrose(y, x),
54 np.array(
55 [
56 [
57 [
58 [1.05968114, -0.0896093, -0.02923021],
59 [3.77254737, 0.06682885, -2.78161763],
60 ],
61 [
62 [-0.77388532, 1.78761209, -0.44050114],
63 [-4.1282882, 0.55185528, 5.049136],
64 ],
65 [
66 [0.36246422, -0.56421525, 1.4208154],
67 [2.07589501, 0.40261387, -1.47059455],
68 ],
69 ],
70 [
71 [
72 [0.237067, 0.4794514, 0.04004058],
73 [0.67778963, 0.15901967, 0.23854131],
74 ],
75 [
76 [-0.4225357, 0.99316309, -0.14598921],
77 [-3.46789045, 1.09102153, 3.31051434],
78 ],
79 [
80 [-0.91661817, 1.49060435, -0.45074387],
81 [-4.18896905, 0.25487186, 4.75951391],
82 ],
83 ],
84 ]
85 ),
86 atol=TOLERANCE_ABSOLUTE_TESTS,
87 )