Coverage for models/rgb/transfer_functions/tests/test_viper_log.py: 100%

65 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-16 22:49 +1300

1""" 

2Define the unit tests for the 

3:mod:`colour.models.rgb.transfer_functions.viper_log` module. 

4""" 

5 

6import numpy as np 

7 

8from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

9from colour.models.rgb.transfer_functions import ( 

10 log_decoding_ViperLog, 

11 log_encoding_ViperLog, 

12) 

13from colour.utilities import domain_range_scale, ignore_numpy_errors 

14 

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" 

21 

22__all__ = [ 

23 "TestLogEncoding_ViperLog", 

24 "TestLogDecoding_ViperLog", 

25] 

26 

27 

28class TestLogEncoding_ViperLog: 

29 """ 

30 Define :func:`colour.models.rgb.transfer_functions.viper_log.\ 

31log_encoding_ViperLog` definition unit tests methods. 

32 """ 

33 

34 def test_log_encoding_ViperLog(self) -> None: 

35 """ 

36 Test :func:`colour.models.rgb.transfer_functions.viper_log.\ 

37log_encoding_ViperLog` definition. 

38 """ 

39 

40 np.testing.assert_allclose( 

41 log_encoding_ViperLog(0.0), -np.inf, atol=TOLERANCE_ABSOLUTE_TESTS 

42 ) 

43 

44 np.testing.assert_allclose( 

45 log_encoding_ViperLog(0.18), 

46 0.636008067010413, 

47 atol=TOLERANCE_ABSOLUTE_TESTS, 

48 ) 

49 

50 np.testing.assert_allclose( 

51 log_encoding_ViperLog(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS 

52 ) 

53 

54 def test_n_dimensional_log_encoding_ViperLog(self) -> None: 

55 """ 

56 Test :func:`colour.models.rgb.transfer_functions.viper_log.\ 

57log_encoding_ViperLog` definition n-dimensional arrays support. 

58 """ 

59 

60 x = 0.18 

61 y = log_encoding_ViperLog(x) 

62 

63 x = np.tile(x, 6) 

64 y = np.tile(y, 6) 

65 np.testing.assert_allclose( 

66 log_encoding_ViperLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS 

67 ) 

68 

69 x = np.reshape(x, (2, 3)) 

70 y = np.reshape(y, (2, 3)) 

71 np.testing.assert_allclose( 

72 log_encoding_ViperLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS 

73 ) 

74 

75 x = np.reshape(x, (2, 3, 1)) 

76 y = np.reshape(y, (2, 3, 1)) 

77 np.testing.assert_allclose( 

78 log_encoding_ViperLog(x), y, atol=TOLERANCE_ABSOLUTE_TESTS 

79 ) 

80 

81 def test_domain_range_scale_log_encoding_ViperLog(self) -> None: 

82 """ 

83 Test :func:`colour.models.rgb.transfer_functions.viper_log.\ 

84log_encoding_ViperLog` definition domain and range scale support. 

85 """ 

86 

87 x = 0.18 

88 y = log_encoding_ViperLog(x) 

89 

90 d_r = (("reference", 1), ("1", 1), ("100", 100)) 

91 for scale, factor in d_r: 

92 with domain_range_scale(scale): 

93 np.testing.assert_allclose( 

94 log_encoding_ViperLog(x * factor), 

95 y * factor, 

96 atol=TOLERANCE_ABSOLUTE_TESTS, 

97 ) 

98 

99 @ignore_numpy_errors 

100 def test_nan_log_encoding_ViperLog(self) -> None: 

101 """ 

102 Test :func:`colour.models.rgb.transfer_functions.viper_log.\ 

103log_encoding_ViperLog` definition nan support. 

104 """ 

105 

106 log_encoding_ViperLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan])) 

107 

108 

109class TestLogDecoding_ViperLog: 

110 """ 

111 Define :func:`colour.models.rgb.transfer_functions.viper_log.\ 

112log_decoding_ViperLog` definition unit tests methods. 

113 """ 

114 

115 def test_log_decoding_ViperLog(self) -> None: 

116 """ 

117 Test :func:`colour.models.rgb.transfer_functions.viper_log.\ 

118log_decoding_ViperLog` definition. 

119 """ 

120 

121 np.testing.assert_allclose( 

122 log_decoding_ViperLog(-np.inf), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS 

123 ) 

124 

125 np.testing.assert_allclose( 

126 log_decoding_ViperLog(0.636008067010413), 

127 0.18, 

128 atol=TOLERANCE_ABSOLUTE_TESTS, 

129 ) 

130 

131 np.testing.assert_allclose( 

132 log_decoding_ViperLog(1.0), 1.0, atol=TOLERANCE_ABSOLUTE_TESTS 

133 ) 

134 

135 def test_n_dimensional_log_decoding_ViperLog(self) -> None: 

136 """ 

137 Test :func:`colour.models.rgb.transfer_functions.viper_log.\ 

138log_decoding_ViperLog` definition n-dimensional arrays support. 

139 """ 

140 

141 y = 0.636008067010413 

142 x = log_decoding_ViperLog(y) 

143 

144 y = np.tile(y, 6) 

145 x = np.tile(x, 6) 

146 np.testing.assert_allclose( 

147 log_decoding_ViperLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS 

148 ) 

149 

150 y = np.reshape(y, (2, 3)) 

151 x = np.reshape(x, (2, 3)) 

152 np.testing.assert_allclose( 

153 log_decoding_ViperLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS 

154 ) 

155 

156 y = np.reshape(y, (2, 3, 1)) 

157 x = np.reshape(x, (2, 3, 1)) 

158 np.testing.assert_allclose( 

159 log_decoding_ViperLog(y), x, atol=TOLERANCE_ABSOLUTE_TESTS 

160 ) 

161 

162 def test_domain_range_scale_log_decoding_ViperLog(self) -> None: 

163 """ 

164 Test :func:`colour.models.rgb.transfer_functions.viper_log.\ 

165log_decoding_ViperLog` definition domain and range scale support. 

166 """ 

167 

168 y = 0.636008067010413 

169 x = log_decoding_ViperLog(y) 

170 

171 d_r = (("reference", 1), ("1", 1), ("100", 100)) 

172 for scale, factor in d_r: 

173 with domain_range_scale(scale): 

174 np.testing.assert_allclose( 

175 log_decoding_ViperLog(y * factor), 

176 x * factor, 

177 atol=TOLERANCE_ABSOLUTE_TESTS, 

178 ) 

179 

180 @ignore_numpy_errors 

181 def test_nan_log_decoding_ViperLog(self) -> None: 

182 """ 

183 Test :func:`colour.models.rgb.transfer_functions.viper_log.\ 

184log_decoding_ViperLog` definition nan support. 

185 """ 

186 

187 log_decoding_ViperLog(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))