Coverage for colour/models/rgb/transfer_functions/tests/test_pivoted_log.py: 100%
65 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"""
2Define the unit tests for the :mod:`colour.models.rgb.transfer_functions.\
3pivoted_log` module.
4"""
6import numpy as np
8from colour.constants import TOLERANCE_ABSOLUTE_TESTS
9from colour.models.rgb.transfer_functions import (
10 log_decoding_PivotedLog,
11 log_encoding_PivotedLog,
12)
13from colour.utilities import domain_range_scale, ignore_numpy_errors
15__author__ = "Colour Developers"
16__copyright__ = "Copyright 2013 Colour Developers"
17__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
18__maintainer__ = "Colour Developers"
19__email__ = "colour-developers@colour-science.org"
20__status__ = "Production"
22__all__ = [
23 "TestLogEncoding_PivotedLog",
24 "TestLogDecoding_PivotedLog",
25]
28class TestLogEncoding_PivotedLog:
29 """
30 Define :func:`colour.models.rgb.transfer_functions.pivoted_log.\
31log_encoding_PivotedLog` definition unit tests methods.
32 """
34 def test_log_encoding_PivotedLog(self) -> None:
35 """
36 Test :func:`colour.models.rgb.transfer_functions.pivoted_log.\
37log_encoding_PivotedLog` definition.
38 """
40 np.testing.assert_allclose(
41 log_encoding_PivotedLog(0.0),
42 -np.inf,
43 atol=TOLERANCE_ABSOLUTE_TESTS,
44 )
46 np.testing.assert_allclose(
47 log_encoding_PivotedLog(0.18),
48 0.434995112414467,
49 atol=TOLERANCE_ABSOLUTE_TESTS,
50 )
52 np.testing.assert_allclose(
53 log_encoding_PivotedLog(1.0),
54 0.653390272208219,
55 atol=TOLERANCE_ABSOLUTE_TESTS,
56 )
58 def test_n_dimensional_log_encoding_PivotedLog(self) -> None:
59 """
60 Test :func:`colour.models.rgb.transfer_functions.pivoted_log.\
61log_encoding_PivotedLog` definition n-dimensional arrays support.
62 """
64 x = 0.18
65 y = log_encoding_PivotedLog(x)
67 x = np.tile(x, 6)
68 y = np.tile(y, 6)
69 np.testing.assert_allclose(
70 log_encoding_PivotedLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS
71 )
73 x = np.reshape(x, (2, 3))
74 y = np.reshape(y, (2, 3))
75 np.testing.assert_allclose(
76 log_encoding_PivotedLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS
77 )
79 x = np.reshape(x, (2, 3, 1))
80 y = np.reshape(y, (2, 3, 1))
81 np.testing.assert_allclose(
82 log_encoding_PivotedLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS
83 )
85 def test_domain_range_scale_log_encoding_PivotedLog(self) -> None:
86 """
87 Test :func:`colour.models.rgb.transfer_functions.pivoted_log.\
88log_encoding_PivotedLog` definition domain and range scale support.
89 """
91 x = 0.18
92 y = log_encoding_PivotedLog(x)
94 d_r = (("reference", 1), ("1", 1), ("100", 100))
95 for scale, factor in d_r:
96 with domain_range_scale(scale):
97 np.testing.assert_allclose(
98 log_encoding_PivotedLog(x * factor),
99 y * factor,
100 atol=TOLERANCE_ABSOLUTE_TESTS,
101 )
103 @ignore_numpy_errors
104 def test_nan_log_encoding_PivotedLog(self) -> None:
105 """
106 Test :func:`colour.models.rgb.transfer_functions.pivoted_log.\
107log_encoding_PivotedLog` definition nan support.
108 """
110 log_encoding_PivotedLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
113class TestLogDecoding_PivotedLog:
114 """
115 Define :func:`colour.models.rgb.transfer_functions.pivoted_log.\
116log_decoding_PivotedLog` definition unit tests methods.
117 """
119 def test_log_decoding_PivotedLog(self) -> None:
120 """
121 Test :func:`colour.models.rgb.transfer_functions.pivoted_log.\
122log_decoding_PivotedLog` definition.
123 """
125 np.testing.assert_allclose(
126 log_decoding_PivotedLog(-np.inf),
127 0.0,
128 atol=TOLERANCE_ABSOLUTE_TESTS,
129 )
131 np.testing.assert_allclose(
132 log_decoding_PivotedLog(0.434995112414467),
133 0.18,
134 atol=TOLERANCE_ABSOLUTE_TESTS,
135 )
137 np.testing.assert_allclose(
138 log_decoding_PivotedLog(0.653390272208219),
139 1.0,
140 atol=TOLERANCE_ABSOLUTE_TESTS,
141 )
143 def test_n_dimensional_log_decoding_PivotedLog(self) -> None:
144 """
145 Test :func:`colour.models.rgb.transfer_functions.pivoted_log.\
146log_decoding_PivotedLog` definition n-dimensional arrays support.
147 """
149 y = 0.434995112414467
150 x = log_decoding_PivotedLog(y)
152 y = np.tile(y, 6)
153 x = np.tile(x, 6)
154 np.testing.assert_allclose(
155 log_decoding_PivotedLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS
156 )
158 y = np.reshape(y, (2, 3))
159 x = np.reshape(x, (2, 3))
160 np.testing.assert_allclose(
161 log_decoding_PivotedLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS
162 )
164 y = np.reshape(y, (2, 3, 1))
165 x = np.reshape(x, (2, 3, 1))
166 np.testing.assert_allclose(
167 log_decoding_PivotedLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS
168 )
170 def test_domain_range_scale_log_decoding_PivotedLog(self) -> None:
171 """
172 Test :func:`colour.models.rgb.transfer_functions.pivoted_log.\
173log_decoding_PivotedLog` definition domain and range scale support.
174 """
176 y = 0.434995112414467
177 x = log_decoding_PivotedLog(y)
179 d_r = (("reference", 1), ("1", 1), ("100", 100))
180 for scale, factor in d_r:
181 with domain_range_scale(scale):
182 np.testing.assert_allclose(
183 log_decoding_PivotedLog(y * factor),
184 x * factor,
185 atol=TOLERANCE_ABSOLUTE_TESTS,
186 )
188 @ignore_numpy_errors
189 def test_nan_log_decoding_PivotedLog(self) -> None:
190 """
191 Test :func:`colour.models.rgb.transfer_functions.pivoted_log.\
192log_decoding_PivotedLog` definition nan support.
193 """
195 log_decoding_PivotedLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))