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

121 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-15 19:01 +1300

1""" 

2Define the unit tests for the 

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

4""" 

5 

6import numpy as np 

7 

8from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

9from colour.models.rgb.transfer_functions import ( 

10 exponent_function_basic, 

11 exponent_function_monitor_curve, 

12) 

13from colour.utilities import 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 "TestExponentFunctionBasic", 

24 "TestExponentFunctionMonitorCurve", 

25] 

26 

27 

28class TestExponentFunctionBasic: 

29 """ 

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

31exponent_function_basic` definition unit tests methods. 

32 """ 

33 

34 def test_exponent_function_basic(self) -> None: 

35 """ 

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

37exponent_function_basic` definition. 

38 """ 

39 

40 a = 0.18 

41 a_p = 0.0229932049927 

42 np.testing.assert_allclose( 

43 exponent_function_basic(a, 2.2), a_p, atol=TOLERANCE_ABSOLUTE_TESTS 

44 ) 

45 

46 np.testing.assert_allclose( 

47 exponent_function_basic(a, 2.2, "basicMirrorFwd"), 

48 a_p, 

49 atol=TOLERANCE_ABSOLUTE_TESTS, 

50 ) 

51 

52 np.testing.assert_allclose( 

53 exponent_function_basic(a, 2.2, "basicPassThruFwd"), 

54 a_p, 

55 atol=TOLERANCE_ABSOLUTE_TESTS, 

56 ) 

57 

58 a = 0.0229932049927 

59 a_p = 0.18 

60 np.testing.assert_allclose( 

61 exponent_function_basic(a, 2.2, "basicRev"), 

62 a_p, 

63 atol=TOLERANCE_ABSOLUTE_TESTS, 

64 ) 

65 

66 np.testing.assert_allclose( 

67 exponent_function_basic(a, 2.2, "basicMirrorRev"), 

68 a_p, 

69 atol=TOLERANCE_ABSOLUTE_TESTS, 

70 ) 

71 

72 np.testing.assert_allclose( 

73 exponent_function_basic(a, 2.2, "basicPassThruRev"), 

74 a_p, 

75 atol=TOLERANCE_ABSOLUTE_TESTS, 

76 ) 

77 

78 a = -0.18 

79 np.testing.assert_allclose( 

80 exponent_function_basic(a, 2.2), 0.0, atol=TOLERANCE_ABSOLUTE_TESTS 

81 ) 

82 

83 np.testing.assert_allclose( 

84 exponent_function_basic(a, 2.2, "basicMirrorFwd"), 

85 -0.0229932049927, 

86 atol=TOLERANCE_ABSOLUTE_TESTS, 

87 ) 

88 

89 np.testing.assert_allclose( 

90 exponent_function_basic(a, 2.2, "basicPassThruFwd"), 

91 -0.18, 

92 atol=TOLERANCE_ABSOLUTE_TESTS, 

93 ) 

94 

95 a = -0.0229932049927 

96 np.testing.assert_allclose( 

97 exponent_function_basic(a, 2.2, "basicRev"), 

98 0.0, 

99 atol=TOLERANCE_ABSOLUTE_TESTS, 

100 ) 

101 

102 np.testing.assert_allclose( 

103 exponent_function_basic(a, 2.2, "basicMirrorRev"), 

104 -0.18, 

105 atol=TOLERANCE_ABSOLUTE_TESTS, 

106 ) 

107 

108 np.testing.assert_allclose( 

109 exponent_function_basic(a, 2.2, "basicPassThruRev"), 

110 -0.0229932049927, 

111 atol=TOLERANCE_ABSOLUTE_TESTS, 

112 ) 

113 

114 def test_n_dimensional_exponent_function_basic(self) -> None: 

115 """ 

116 Test :func:`colour.models.rgb.transfer_functions.exponent.\ 

117exponent_function_basic` definition n-dimensional arrays support. 

118 """ 

119 

120 a = 0.18 

121 a_p = 0.0229932049927 

122 

123 a = np.tile(a, 6) 

124 a_p = np.tile(a_p, 6) 

125 np.testing.assert_allclose( 

126 exponent_function_basic(a, 2.2), a_p, atol=TOLERANCE_ABSOLUTE_TESTS 

127 ) 

128 np.testing.assert_allclose( 

129 exponent_function_basic(a, 2.2, "basicMirrorFwd"), 

130 a_p, 

131 atol=TOLERANCE_ABSOLUTE_TESTS, 

132 ) 

133 np.testing.assert_allclose( 

134 exponent_function_basic(a, 2.2, "basicPassThruFwd"), 

135 a_p, 

136 atol=TOLERANCE_ABSOLUTE_TESTS, 

137 ) 

138 

139 a = np.reshape(a, (2, 3)) 

140 a_p = np.reshape(a_p, (2, 3)) 

141 np.testing.assert_allclose( 

142 exponent_function_basic(a, 2.2), a_p, atol=TOLERANCE_ABSOLUTE_TESTS 

143 ) 

144 np.testing.assert_allclose( 

145 exponent_function_basic(a, 2.2, "basicMirrorFwd"), 

146 a_p, 

147 atol=TOLERANCE_ABSOLUTE_TESTS, 

148 ) 

149 np.testing.assert_allclose( 

150 exponent_function_basic(a, 2.2, "basicPassThruFwd"), 

151 a_p, 

152 atol=TOLERANCE_ABSOLUTE_TESTS, 

153 ) 

154 

155 a = np.reshape(a, (2, 3, 1)) 

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

157 np.testing.assert_allclose( 

158 exponent_function_basic(a, 2.2), a_p, atol=TOLERANCE_ABSOLUTE_TESTS 

159 ) 

160 np.testing.assert_allclose( 

161 exponent_function_basic(a, 2.2, "basicMirrorFwd"), 

162 a_p, 

163 atol=TOLERANCE_ABSOLUTE_TESTS, 

164 ) 

165 np.testing.assert_allclose( 

166 exponent_function_basic(a, 2.2, "basicPassThruFwd"), 

167 a_p, 

168 atol=TOLERANCE_ABSOLUTE_TESTS, 

169 ) 

170 

171 a = 0.0229932049927 

172 a_p = 0.18 

173 

174 a = np.tile(a, 6) 

175 a_p = np.tile(a_p, 6) 

176 np.testing.assert_allclose( 

177 exponent_function_basic(a, 2.2, "basicRev"), 

178 a_p, 

179 atol=TOLERANCE_ABSOLUTE_TESTS, 

180 ) 

181 np.testing.assert_allclose( 

182 exponent_function_basic(a, 2.2, "basicMirrorRev"), 

183 a_p, 

184 atol=TOLERANCE_ABSOLUTE_TESTS, 

185 ) 

186 np.testing.assert_allclose( 

187 exponent_function_basic(a, 2.2, "basicPassThruRev"), 

188 a_p, 

189 atol=TOLERANCE_ABSOLUTE_TESTS, 

190 ) 

191 

192 a = np.reshape(a, (2, 3)) 

193 a_p = np.reshape(a_p, (2, 3)) 

194 np.testing.assert_allclose( 

195 exponent_function_basic(a, 2.2, "basicRev"), 

196 a_p, 

197 atol=TOLERANCE_ABSOLUTE_TESTS, 

198 ) 

199 np.testing.assert_allclose( 

200 exponent_function_basic(a, 2.2, "basicMirrorRev"), 

201 a_p, 

202 atol=TOLERANCE_ABSOLUTE_TESTS, 

203 ) 

204 np.testing.assert_allclose( 

205 exponent_function_basic(a, 2.2, "basicPassThruRev"), 

206 a_p, 

207 atol=TOLERANCE_ABSOLUTE_TESTS, 

208 ) 

209 

210 a = np.reshape(a, (2, 3, 1)) 

211 a_p = np.reshape(a_p, (2, 3, 1)) 

212 np.testing.assert_allclose( 

213 exponent_function_basic(a, 2.2, "basicRev"), 

214 a_p, 

215 atol=TOLERANCE_ABSOLUTE_TESTS, 

216 ) 

217 np.testing.assert_allclose( 

218 exponent_function_basic(a, 2.2, "basicMirrorRev"), 

219 a_p, 

220 atol=TOLERANCE_ABSOLUTE_TESTS, 

221 ) 

222 np.testing.assert_allclose( 

223 exponent_function_basic(a, 2.2, "basicPassThruRev"), 

224 a_p, 

225 atol=TOLERANCE_ABSOLUTE_TESTS, 

226 ) 

227 

228 @ignore_numpy_errors 

229 def test_nan_exponent_function_basic(self) -> None: 

230 """ 

231 Test :func:`colour.models.rgb.transfer_functions.exponent.\ 

232exponent_function_basic` definition nan support. 

233 """ 

234 

235 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] 

236 for case in cases: 

237 exponent_function_basic(case, case) 

238 

239 

240class TestExponentFunctionMonitorCurve: 

241 """ 

242 Define :func:`colour.models.rgb.transfer_functions.exponent.\ 

243exponent_function_monitor_curve` definition unit tests methods. 

244 """ 

245 

246 def test_exponent_function_monitor_curve(self) -> None: 

247 """ 

248 Test :func:`colour.models.rgb.transfer_functions.exponent.\ 

249exponent_function_monitor_curve` definition. 

250 """ 

251 

252 a = 0.18 

253 a_p = 0.0232240466001 

254 np.testing.assert_allclose( 

255 exponent_function_monitor_curve(a, 2.2, 0.001), 

256 a_p, 

257 atol=TOLERANCE_ABSOLUTE_TESTS, 

258 ) 

259 

260 np.testing.assert_allclose( 

261 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveMirrorFwd"), 

262 a_p, 

263 atol=TOLERANCE_ABSOLUTE_TESTS, 

264 ) 

265 

266 a = 0.0232240466001 

267 a_p = 0.18 

268 np.testing.assert_allclose( 

269 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveRev"), 

270 a_p, 

271 atol=TOLERANCE_ABSOLUTE_TESTS, 

272 ) 

273 

274 np.testing.assert_allclose( 

275 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveMirrorRev"), 

276 a_p, 

277 atol=TOLERANCE_ABSOLUTE_TESTS, 

278 ) 

279 

280 a = -0.18 

281 np.testing.assert_allclose( 

282 exponent_function_monitor_curve(a, 2.2, 0.001), 

283 -0.000205413951, 

284 atol=TOLERANCE_ABSOLUTE_TESTS, 

285 ) 

286 

287 np.testing.assert_allclose( 

288 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveMirrorFwd"), 

289 -0.0232240466001, 

290 atol=TOLERANCE_ABSOLUTE_TESTS, 

291 ) 

292 

293 a = -0.000205413951 

294 np.testing.assert_allclose( 

295 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveRev"), 

296 -0.18, 

297 atol=TOLERANCE_ABSOLUTE_TESTS, 

298 ) 

299 

300 np.testing.assert_allclose( 

301 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveMirrorRev"), 

302 -0.0201036111565, 

303 atol=TOLERANCE_ABSOLUTE_TESTS, 

304 ) 

305 

306 def test_n_dimensional_exponent_function_monitor_curve(self) -> None: 

307 """ 

308 Test :func:`colour.models.rgb.transfer_functions.exponent.\ 

309exponent_function_monitor_curve` definition n-dimensional arrays support. 

310 """ 

311 

312 a = 0.18 

313 a_p = 0.0232240466001 

314 

315 a = np.tile(a, 6) 

316 a_p = np.tile(a_p, 6) 

317 np.testing.assert_allclose( 

318 exponent_function_monitor_curve(a, 2.2, 0.001), 

319 a_p, 

320 atol=TOLERANCE_ABSOLUTE_TESTS, 

321 ) 

322 np.testing.assert_allclose( 

323 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveMirrorFwd"), 

324 a_p, 

325 atol=TOLERANCE_ABSOLUTE_TESTS, 

326 ) 

327 

328 a = np.reshape(a, (2, 3)) 

329 a_p = np.reshape(a_p, (2, 3)) 

330 np.testing.assert_allclose( 

331 exponent_function_monitor_curve(a, 2.2, 0.001), 

332 a_p, 

333 atol=TOLERANCE_ABSOLUTE_TESTS, 

334 ) 

335 np.testing.assert_allclose( 

336 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveMirrorFwd"), 

337 a_p, 

338 atol=TOLERANCE_ABSOLUTE_TESTS, 

339 ) 

340 

341 a = np.reshape(a, (2, 3, 1)) 

342 a_p = np.reshape(a_p, (2, 3, 1)) 

343 np.testing.assert_allclose( 

344 exponent_function_monitor_curve(a, 2.2, 0.001), 

345 a_p, 

346 atol=TOLERANCE_ABSOLUTE_TESTS, 

347 ) 

348 np.testing.assert_allclose( 

349 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveMirrorFwd"), 

350 a_p, 

351 atol=TOLERANCE_ABSOLUTE_TESTS, 

352 ) 

353 

354 a = 0.0232240466001 

355 a_p = 0.18 

356 

357 a = np.tile(a, 6) 

358 a_p = np.tile(a_p, 6) 

359 np.testing.assert_allclose( 

360 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveRev"), 

361 a_p, 

362 atol=TOLERANCE_ABSOLUTE_TESTS, 

363 ) 

364 np.testing.assert_allclose( 

365 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveMirrorRev"), 

366 a_p, 

367 atol=TOLERANCE_ABSOLUTE_TESTS, 

368 ) 

369 

370 a = np.reshape(a, (2, 3)) 

371 a_p = np.reshape(a_p, (2, 3)) 

372 np.testing.assert_allclose( 

373 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveRev"), 

374 a_p, 

375 atol=TOLERANCE_ABSOLUTE_TESTS, 

376 ) 

377 np.testing.assert_allclose( 

378 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveMirrorRev"), 

379 a_p, 

380 atol=TOLERANCE_ABSOLUTE_TESTS, 

381 ) 

382 

383 a = np.reshape(a, (2, 3, 1)) 

384 a_p = np.reshape(a_p, (2, 3, 1)) 

385 np.testing.assert_allclose( 

386 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveRev"), 

387 a_p, 

388 atol=TOLERANCE_ABSOLUTE_TESTS, 

389 ) 

390 np.testing.assert_allclose( 

391 exponent_function_monitor_curve(a, 2.2, 0.001, "monCurveMirrorRev"), 

392 a_p, 

393 atol=TOLERANCE_ABSOLUTE_TESTS, 

394 ) 

395 

396 @ignore_numpy_errors 

397 def test_nan_exponent_function_monitor_curve(self) -> None: 

398 """ 

399 Test :func:`colour.models.rgb.transfer_functions.exponent.\ 

400exponent_function_monitor_curve` definition nan support. 

401 """ 

402 

403 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] 

404 for case in cases: 

405 exponent_function_monitor_curve(case, case, case)