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

1"""

2 Define the unit tests for the

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

4"""

5

6 import numpy as np

7

8 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

9 from colour.models.rgb.transfer_functions.canon import (

10 log_decoding_CanonLog2_v1,

11 log_decoding_CanonLog2_v1_2,

12 log_decoding_CanonLog3_v1,

13 log_decoding_CanonLog3_v1_2,

14 log_decoding_CanonLog_v1,

15 log_decoding_CanonLog_v1_2,

16 log_encoding_CanonLog2_v1,

17 log_encoding_CanonLog2_v1_2,

18 log_encoding_CanonLog3_v1,

19 log_encoding_CanonLog3_v1_2,

20 log_encoding_CanonLog_v1,

21 log_encoding_CanonLog_v1_2,

22)

23 from colour.utilities import domain_range_scale, ignore_numpy_errors

24

25 __author__ = "Colour Developers"

26 __copyright__ = "Copyright 2013 Colour Developers"

27 __license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"

28 __maintainer__ = "Colour Developers"

29 __email__ = "colour-developers@colour-science.org"

30 __status__ = "Production"

31

32 __all__ = [

33 "TestLogEncoding_CanonLog_v1",

34 "TestLogDecoding_CanonLog_v1",

35 "TestLogEncoding_CanonLog_v1_2",

36 "TestLogDecoding_CanonLog_v1_2",

37 "TestLogEncoding_CanonLog2_v1",

38 "TestLogDecoding_CanonLog2_v1",

39 "TestLogEncoding_CanonLog2_v1_2",

40 "TestLogDecoding_CanonLog2_v1_2",

41 "TestLogEncoding_CanonLog3_v1",

42 "TestLogDecoding_CanonLog3_v1",

43 "TestLogEncoding_CanonLog3_v1_2",

44 "TestLogDecoding_CanonLog3_v1_2",

45]

46

47

48 class TestLogEncoding_CanonLog_v1:

49 """

50 Define :func:`colour.models.rgb.transfer_functions.canon.\

51 log_encoding_CanonLog_v1` definition unit tests methods.

52 """

53

54 def test_log_encoding_CanonLog_v1(self) -> None:

55 """

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

57 log_encoding_CanonLog_v1` definition.

58 """

59

60 np.testing.assert_allclose(

61 log_encoding_CanonLog_v1(-0.1),

62 -0.023560122781997,

63 atol=TOLERANCE_ABSOLUTE_TESTS,

64 )

65

66 np.testing.assert_allclose(

67 log_encoding_CanonLog_v1(0.0),

68 0.125122480156403,

69 atol=TOLERANCE_ABSOLUTE_TESTS,

70 )

71

72 np.testing.assert_allclose(

73 log_encoding_CanonLog_v1(0.18),

74 0.343389651726069,

75 atol=TOLERANCE_ABSOLUTE_TESTS,

76 )

77

78 np.testing.assert_allclose(

79 log_encoding_CanonLog_v1(0.18, 12),

80 0.343138084215647,

81 atol=TOLERANCE_ABSOLUTE_TESTS,

82 )

83

84 np.testing.assert_allclose(

85 log_encoding_CanonLog_v1(0.18, 10, False),

86 0.327953896935809,

87 atol=TOLERANCE_ABSOLUTE_TESTS,

88 )

89

90 np.testing.assert_allclose(

91 log_encoding_CanonLog_v1(0.18, 10, False, False),

92 0.312012855550395,

93 atol=TOLERANCE_ABSOLUTE_TESTS,

94 )

95

96 np.testing.assert_allclose(

97 log_encoding_CanonLog_v1(1.0),

98 0.618775485598649,

99 atol=TOLERANCE_ABSOLUTE_TESTS,

100 )

101

102 def test_n_dimensional_log_encoding_CanonLog_v1(self) -> None:

103 """

104 Test :func:`colour.models.rgb.transfer_functions.canon.\

105 log_encoding_CanonLog_v1` definition n-dimensional arrays support.

106 """

107

108 x = 0.18

109 clog = log_encoding_CanonLog_v1(x)

110

111 x = np.tile(x, 6)

112 clog = np.tile(clog, 6)

113 np.testing.assert_allclose(

114 log_encoding_CanonLog_v1(x), clog, atol=TOLERANCE_ABSOLUTE_TESTS

115 )

116

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

118 clog = np.reshape(clog, (2, 3))

119 np.testing.assert_allclose(

120 log_encoding_CanonLog_v1(x), clog, atol=TOLERANCE_ABSOLUTE_TESTS

121 )

122

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

124 clog = np.reshape(clog, (2, 3, 1))

125 np.testing.assert_allclose(

126 log_encoding_CanonLog_v1(x), clog, atol=TOLERANCE_ABSOLUTE_TESTS

127 )

128

129 def test_domain_range_scale_log_encoding_CanonLog_v1(self) -> None:

130 """

131 Test :func:`colour.models.rgb.transfer_functions.canon.\

132 log_encoding_CanonLog_v1` definition domain and range scale support.

133 """

134

135 x = 0.18

136 clog = log_encoding_CanonLog_v1(x)

137

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

139 for scale, factor in d_r:

140 with domain_range_scale(scale):

141 np.testing.assert_allclose(

142 log_encoding_CanonLog_v1(x * factor),

143 clog * factor,

144 atol=TOLERANCE_ABSOLUTE_TESTS,

145 )

146

147 @ignore_numpy_errors

148 def test_nan_log_encoding_CanonLog_v1(self) -> None:

149 """

150 Test :func:`colour.models.rgb.transfer_functions.canon.\

151 log_encoding_CanonLog_v1` definition nan support.

152 """

153

154 log_encoding_CanonLog_v1(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

155

156

157 class TestLogDecoding_CanonLog_v1:

158 """

159 Define :func:`colour.models.rgb.transfer_functions.canon.\

160 log_decoding_CanonLog_v1` definition unit tests methods.

161 """

162

163 def test_log_decoding_CanonLog_v1(self) -> None:

164 """

165 Test :func:`colour.models.rgb.transfer_functions.canon.\

166 log_decoding_CanonLog_v1` definition.

167 """

168

169 np.testing.assert_allclose(

170 log_decoding_CanonLog_v1(-0.023560122781997),

171 -0.1,

172 atol=TOLERANCE_ABSOLUTE_TESTS,

173 )

174

175 np.testing.assert_allclose(

176 log_decoding_CanonLog_v1(0.125122480156403),

177 0.0,

178 atol=TOLERANCE_ABSOLUTE_TESTS,

179 )

180

181 np.testing.assert_allclose(

182 log_decoding_CanonLog_v1(0.343389651726069),

183 0.18,

184 atol=TOLERANCE_ABSOLUTE_TESTS,

185 )

186

187 np.testing.assert_allclose(

188 log_decoding_CanonLog_v1(0.343138084215647, 12),

189 0.18,

190 atol=TOLERANCE_ABSOLUTE_TESTS,

191 )

192

193 np.testing.assert_allclose(

194 log_decoding_CanonLog_v1(0.327953896935809, 10, False),

195 0.18,

196 atol=TOLERANCE_ABSOLUTE_TESTS,

197 )

198

199 np.testing.assert_allclose(

200 log_decoding_CanonLog_v1(0.312012855550395, 10, False, False),

201 0.18,

202 atol=TOLERANCE_ABSOLUTE_TESTS,

203 )

204

205 np.testing.assert_allclose(

206 log_decoding_CanonLog_v1(0.618775485598649),

207 1.0,

208 atol=TOLERANCE_ABSOLUTE_TESTS,

209 )

210

211 def test_n_dimensional_log_decoding_CanonLog_v1(self) -> None:

212 """

213 Test :func:`colour.models.rgb.transfer_functions.canon.\

214 log_decoding_CanonLog_v1` definition n-dimensional arrays support.

215 """

216

217 clog = 0.343389651726069

218 x = log_decoding_CanonLog_v1(clog)

219

220 clog = np.tile(clog, 6)

221 x = np.tile(x, 6)

222 np.testing.assert_allclose(

223 log_decoding_CanonLog_v1(clog), x, atol=TOLERANCE_ABSOLUTE_TESTS

224 )

225

226 clog = np.reshape(clog, (2, 3))

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

228 np.testing.assert_allclose(

229 log_decoding_CanonLog_v1(clog), x, atol=TOLERANCE_ABSOLUTE_TESTS

230 )

231

232 clog = np.reshape(clog, (2, 3, 1))

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

234 np.testing.assert_allclose(

235 log_decoding_CanonLog_v1(clog), x, atol=TOLERANCE_ABSOLUTE_TESTS

236 )

237

238 def test_domain_range_scale_log_decoding_CanonLog_v1(self) -> None:

239 """

240 Test :func:`colour.models.rgb.transfer_functions.canon.\

241 log_decoding_CanonLog_v1` definition domain and range scale support.

242 """

243

244 clog = 0.343389651726069

245 x = log_decoding_CanonLog_v1(clog)

246

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

248 for scale, factor in d_r:

249 with domain_range_scale(scale):

250 np.testing.assert_allclose(

251 log_decoding_CanonLog_v1(clog * factor),

252 x * factor,

253 atol=TOLERANCE_ABSOLUTE_TESTS,

254 )

255

256 @ignore_numpy_errors

257 def test_nan_log_decoding_CanonLog_v1(self) -> None:

258 """

259 Test :func:`colour.models.rgb.transfer_functions.canon.\

260 log_decoding_CanonLog_v1` definition nan support.

261 """

262

263 log_decoding_CanonLog_v1(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

264

265

266 class TestLogEncoding_CanonLog_v1_2:

267 """

268 Define :func:`colour.models.rgb.transfer_functions.canon.\

269 log_encoding_CanonLog_v1_2` definition unit tests methods.

270 """

271

272 def test_log_encoding_CanonLog_v1_2(self) -> None:

273 """

274 Test :func:`colour.models.rgb.transfer_functions.canon.\

275 log_encoding_CanonLog_v1_2` definition.

276 """

277

278 np.testing.assert_allclose(

279 log_encoding_CanonLog_v1_2(-0.1),

280 -0.023560121389098,

281 atol=TOLERANCE_ABSOLUTE_TESTS,

282 )

283

284 np.testing.assert_allclose(

285 log_encoding_CanonLog_v1_2(0.0),

286 0.125122480000000,

287 atol=TOLERANCE_ABSOLUTE_TESTS,

288 )

289

290 np.testing.assert_allclose(

291 log_encoding_CanonLog_v1_2(0.18),

292 0.343389649295280,

293 atol=TOLERANCE_ABSOLUTE_TESTS,

294 )

295

296 np.testing.assert_allclose(

297 log_encoding_CanonLog_v1_2(0.18, 12),

298 0.343389649295281,

299 atol=TOLERANCE_ABSOLUTE_TESTS,

300 )

301

302 np.testing.assert_allclose(

303 log_encoding_CanonLog_v1_2(0.18, 10, False),

304 0.327953894097114,

305 atol=TOLERANCE_ABSOLUTE_TESTS,

306 )

307

308 np.testing.assert_allclose(

309 log_encoding_CanonLog_v1_2(0.18, 10, False, False),

310 0.312012852877809,

311 atol=TOLERANCE_ABSOLUTE_TESTS,

312 )

313

314 np.testing.assert_allclose(

315 log_encoding_CanonLog_v1_2(1.0),

316 0.618775480298287,

317 atol=TOLERANCE_ABSOLUTE_TESTS,

318 )

319

320 samples = np.linspace(0, 1, 10000)

321

322 np.testing.assert_allclose(

323 log_encoding_CanonLog_v1(samples),

324 log_encoding_CanonLog_v1_2(samples),

325 atol=TOLERANCE_ABSOLUTE_TESTS,

326 )

327

328 np.testing.assert_allclose(

329 log_encoding_CanonLog_v1(samples),

330 log_encoding_CanonLog_v1_2(samples),

331 atol=TOLERANCE_ABSOLUTE_TESTS,

332 )

333

334 np.testing.assert_allclose(

335 log_encoding_CanonLog_v1(samples, out_normalised_code_value=False),

336 log_encoding_CanonLog_v1_2(samples, out_normalised_code_value=False),

337 atol=TOLERANCE_ABSOLUTE_TESTS,

338 )

339 np.testing.assert_allclose(

340 log_encoding_CanonLog_v1(samples, in_reflection=False),

341 log_encoding_CanonLog_v1_2(samples, in_reflection=False),

342 atol=TOLERANCE_ABSOLUTE_TESTS,

343 )

344

345 def test_n_dimensional_log_encoding_CanonLog_v1_2(self) -> None:

346 """

347 Test :func:`colour.models.rgb.transfer_functions.canon.\

348 log_encoding_CanonLog_v1_2` definition n-dimensional arrays support.

349 """

350

351 x = 0.18

352 clog = log_encoding_CanonLog_v1_2(x)

353

354 x = np.tile(x, 6)

355 clog = np.tile(clog, 6)

356 np.testing.assert_allclose(

357 log_encoding_CanonLog_v1_2(x), clog, atol=TOLERANCE_ABSOLUTE_TESTS

358 )

359

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

361 clog = np.reshape(clog, (2, 3))

362 np.testing.assert_allclose(

363 log_encoding_CanonLog_v1_2(x), clog, atol=TOLERANCE_ABSOLUTE_TESTS

364 )

365

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

367 clog = np.reshape(clog, (2, 3, 1))

368 np.testing.assert_allclose(

369 log_encoding_CanonLog_v1_2(x), clog, atol=TOLERANCE_ABSOLUTE_TESTS

370 )

371

372 def test_domain_range_scale_log_encoding_CanonLog_v1_2(self) -> None:

373 """

374 Test :func:`colour.models.rgb.transfer_functions.canon.\

375 log_encoding_CanonLog_v1_2` definition domain and range scale support.

376 """

377

378 x = 0.18

379 clog = log_encoding_CanonLog_v1_2(x)

380

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

382 for scale, factor in d_r:

383 with domain_range_scale(scale):

384 np.testing.assert_allclose(

385 log_encoding_CanonLog_v1_2(x * factor),

386 clog * factor,

387 atol=TOLERANCE_ABSOLUTE_TESTS,

388 )

389

390 @ignore_numpy_errors

391 def test_nan_log_encoding_CanonLog_v1_2(self) -> None:

392 """

393 Test :func:`colour.models.rgb.transfer_functions.canon.\

394 log_encoding_CanonLog_v1_2` definition nan support.

395 """

396

397 log_encoding_CanonLog_v1_2(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

398

399

400 class TestLogDecoding_CanonLog_v1_2:

401 """

402 Define :func:`colour.models.rgb.transfer_functions.canon.\

403 log_decoding_CanonLog_v1_2` definition unit tests methods.

404 """

405

406 def test_log_decoding_CanonLog_v1_2(self) -> None:

407 """

408 Test :func:`colour.models.rgb.transfer_functions.canon.\

409 log_decoding_CanonLog_v1_2` definition.

410 """

411

412 np.testing.assert_allclose(

413 log_decoding_CanonLog_v1_2(-0.023560121389098),

414 -0.1,

415 atol=TOLERANCE_ABSOLUTE_TESTS,

416 )

417

418 np.testing.assert_allclose(

419 log_decoding_CanonLog_v1_2(0.125122480000000),

420 0.0,

421 atol=TOLERANCE_ABSOLUTE_TESTS,

422 )

423

424 np.testing.assert_allclose(

425 log_decoding_CanonLog_v1_2(0.343389649295280),

426 0.18,

427 atol=TOLERANCE_ABSOLUTE_TESTS,

428 )

429

430 np.testing.assert_allclose(

431 log_decoding_CanonLog_v1_2(0.343389649295281, 12),

432 0.18,

433 atol=TOLERANCE_ABSOLUTE_TESTS,

434 )

435

436 np.testing.assert_allclose(

437 log_decoding_CanonLog_v1_2(0.327953894097114, 10, False),

438 0.18,

439 atol=TOLERANCE_ABSOLUTE_TESTS,

440 )

441

442 np.testing.assert_allclose(

443 log_decoding_CanonLog_v1_2(0.312012852877809, 10, False, False),

444 0.18,

445 atol=TOLERANCE_ABSOLUTE_TESTS,

446 )

447

448 np.testing.assert_allclose(

449 log_decoding_CanonLog_v1_2(0.618775480298287),

450 1.0,

451 atol=TOLERANCE_ABSOLUTE_TESTS,

452 )

453

454 samples = np.linspace(0, 1, 10000)

455

456 np.testing.assert_allclose(

457 log_decoding_CanonLog_v1(samples),

458 log_decoding_CanonLog_v1_2(samples),

459 atol=TOLERANCE_ABSOLUTE_TESTS,

460 )

461

462 np.testing.assert_allclose(

463 log_decoding_CanonLog_v1(samples),

464 log_decoding_CanonLog_v1_2(samples),

465 atol=TOLERANCE_ABSOLUTE_TESTS,

466 )

467

468 np.testing.assert_allclose(

469 log_decoding_CanonLog_v1(samples, in_normalised_code_value=False),

470 log_decoding_CanonLog_v1_2(samples, in_normalised_code_value=False),

471 atol=TOLERANCE_ABSOLUTE_TESTS,

472 )

473 np.testing.assert_allclose(

474 log_decoding_CanonLog_v1(samples, out_reflection=False),

475 log_decoding_CanonLog_v1_2(samples, out_reflection=False),

476 atol=TOLERANCE_ABSOLUTE_TESTS,

477 )

478

479 def test_n_dimensional_log_decoding_CanonLog_v1_2(self) -> None:

480 """

481 Test :func:`colour.models.rgb.transfer_functions.canon.\

482 log_decoding_CanonLog_v1_2` definition n-dimensional arrays support.

483 """

484

485 clog = 0.343389649295280

486 x = log_decoding_CanonLog_v1_2(clog)

487

488 clog = np.tile(clog, 6)

489 x = np.tile(x, 6)

490 np.testing.assert_allclose(

491 log_decoding_CanonLog_v1_2(clog), x, atol=TOLERANCE_ABSOLUTE_TESTS

492 )

493

494 clog = np.reshape(clog, (2, 3))

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

496 np.testing.assert_allclose(

497 log_decoding_CanonLog_v1_2(clog), x, atol=TOLERANCE_ABSOLUTE_TESTS

498 )

499

500 clog = np.reshape(clog, (2, 3, 1))

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

502 np.testing.assert_allclose(

503 log_decoding_CanonLog_v1_2(clog), x, atol=TOLERANCE_ABSOLUTE_TESTS

504 )

505

506 def test_domain_range_scale_log_decoding_CanonLog_v1_2(self) -> None:

507 """

508 Test :func:`colour.models.rgb.transfer_functions.canon.\

509 log_decoding_CanonLog_v1_2` definition domain and range scale support.

510 """

511

512 clog = 0.343389649295280

513 x = log_decoding_CanonLog_v1_2(clog)

514

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

516 for scale, factor in d_r:

517 with domain_range_scale(scale):

518 np.testing.assert_allclose(

519 log_decoding_CanonLog_v1_2(clog * factor),

520 x * factor,

521 atol=TOLERANCE_ABSOLUTE_TESTS,

522 )

523

524 @ignore_numpy_errors

525 def test_nan_log_decoding_CanonLog_v1_2(self) -> None:

526 """

527 Test :func:`colour.models.rgb.transfer_functions.canon.\

528 log_decoding_CanonLog_v1_2` definition nan support.

529 """

530

531 log_decoding_CanonLog_v1_2(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

532

533

534 class TestLogEncoding_CanonLog2_v1:

535 """

536 Define :func:`colour.models.rgb.transfer_functions.canon.\

537 log_encoding_CanonLog2_v1` definition unit tests methods.

538 """

539

540 def test_log_encoding_CanonLog2_v1(self) -> None:

541 """

542 Test :func:`colour.models.rgb.transfer_functions.canon.\

543 log_encoding_CanonLog2_v1` definition.

544 """

545

546 np.testing.assert_allclose(

547 log_encoding_CanonLog2_v1(-0.1),

548 -0.155370131996824,

549 atol=TOLERANCE_ABSOLUTE_TESTS,

550 )

551

552 np.testing.assert_allclose(

553 log_encoding_CanonLog2_v1(0.0),

554 0.092864125247312,

555 atol=TOLERANCE_ABSOLUTE_TESTS,

556 )

557

558 np.testing.assert_allclose(

559 log_encoding_CanonLog2_v1(0.18),

560 0.398254694983167,

561 atol=TOLERANCE_ABSOLUTE_TESTS,

562 )

563

564 np.testing.assert_allclose(

565 log_encoding_CanonLog2_v1(0.18, 12),

566 0.397962933301861,

567 atol=TOLERANCE_ABSOLUTE_TESTS,

568 )

569

570 np.testing.assert_allclose(

571 log_encoding_CanonLog2_v1(0.18, 10, False),

572 0.392025745397009,

573 atol=TOLERANCE_ABSOLUTE_TESTS,

574 )

575

576 np.testing.assert_allclose(

577 log_encoding_CanonLog2_v1(0.18, 10, False, False),

578 0.379864582222983,

579 atol=TOLERANCE_ABSOLUTE_TESTS,

580 )

581

582 np.testing.assert_allclose(

583 log_encoding_CanonLog2_v1(1.0),

584 0.573229282897641,

585 atol=TOLERANCE_ABSOLUTE_TESTS,

586 )

587

588 def test_n_dimensional_log_encoding_CanonLog2_v1(self) -> None:

589 """

590 Test :func:`colour.models.rgb.transfer_functions.canon.\

591 log_encoding_CanonLog2_v1` definition n-dimensional arrays support.

592 """

593

594 x = 0.18

595 clog2 = log_encoding_CanonLog2_v1(x)

596

597 x = np.tile(x, 6)

598 clog2 = np.tile(clog2, 6)

599 np.testing.assert_allclose(

600 log_encoding_CanonLog2_v1(x), clog2, atol=TOLERANCE_ABSOLUTE_TESTS

601 )

602

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

604 clog2 = np.reshape(clog2, (2, 3))

605 np.testing.assert_allclose(

606 log_encoding_CanonLog2_v1(x), clog2, atol=TOLERANCE_ABSOLUTE_TESTS

607 )

608

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

610 clog2 = np.reshape(clog2, (2, 3, 1))

611 np.testing.assert_allclose(

612 log_encoding_CanonLog2_v1(x), clog2, atol=TOLERANCE_ABSOLUTE_TESTS

613 )

614

615 def test_domain_range_scale_log_encoding_CanonLog2_v1(self) -> None:

616 """

617 Test :func:`colour.models.rgb.transfer_functions.canon.\

618 log_encoding_CanonLog2_v1` definition domain and range scale support.

619 """

620

621 x = 0.18

622 clog2 = log_encoding_CanonLog2_v1(x)

623

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

625 for scale, factor in d_r:

626 with domain_range_scale(scale):

627 np.testing.assert_allclose(

628 log_encoding_CanonLog2_v1(x * factor),

629 clog2 * factor,

630 atol=TOLERANCE_ABSOLUTE_TESTS,

631 )

632

633 @ignore_numpy_errors

634 def test_nan_log_encoding_CanonLog2_v1(self) -> None:

635 """

636 Test :func:`colour.models.rgb.transfer_functions.canon.\

637 log_encoding_CanonLog2_v1` definition nan support.

638 """

639

640 log_encoding_CanonLog2_v1(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

641

642

643 class TestLogDecoding_CanonLog2_v1:

644 """

645 Define :func:`colour.models.rgb.transfer_functions.canon.\

646 log_decoding_CanonLog2_v1` definition unit tests methods.

647 """

648

649 def test_log_decoding_CanonLog2_v1(self) -> None:

650 """

651 Test :func:`colour.models.rgb.transfer_functions.canon.\

652 log_decoding_CanonLog2_v1` definition.

653 """

654

655 np.testing.assert_allclose(

656 log_decoding_CanonLog2_v1(-0.155370131996824),

657 -0.1,

658 atol=TOLERANCE_ABSOLUTE_TESTS,

659 )

660

661 np.testing.assert_allclose(

662 log_decoding_CanonLog2_v1(0.092864125247312),

663 0.0,

664 atol=TOLERANCE_ABSOLUTE_TESTS,

665 )

666

667 np.testing.assert_allclose(

668 log_decoding_CanonLog2_v1(0.398254694983167),

669 0.18,

670 atol=TOLERANCE_ABSOLUTE_TESTS,

671 )

672

673 np.testing.assert_allclose(

674 log_decoding_CanonLog2_v1(0.397962933301861, 12),

675 0.18,

676 atol=TOLERANCE_ABSOLUTE_TESTS,

677 )

678

679 np.testing.assert_allclose(

680 log_decoding_CanonLog2_v1(0.392025745397009, 10, False),

681 0.18,

682 atol=TOLERANCE_ABSOLUTE_TESTS,

683 )

684

685 np.testing.assert_allclose(

686 log_decoding_CanonLog2_v1(0.379864582222983, 10, False, False),

687 0.18,

688 atol=TOLERANCE_ABSOLUTE_TESTS,

689 )

690

691 np.testing.assert_allclose(

692 log_decoding_CanonLog2_v1(0.573229282897641),

693 1.0,

694 atol=TOLERANCE_ABSOLUTE_TESTS,

695 )

696

697 def test_n_dimensional_log_decoding_CanonLog2_v1(self) -> None:

698 """

699 Test :func:`colour.models.rgb.transfer_functions.canon.\

700 log_decoding_CanonLog2_v1` definition n-dimensional arrays support.

701 """

702

703 clog2 = 0.398254694983167

704 x = log_decoding_CanonLog2_v1(clog2)

705

706 clog2 = np.tile(clog2, 6)

707 x = np.tile(x, 6)

708 np.testing.assert_allclose(

709 log_decoding_CanonLog2_v1(clog2), x, atol=TOLERANCE_ABSOLUTE_TESTS

710 )

711

712 clog2 = np.reshape(clog2, (2, 3))

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

714 np.testing.assert_allclose(

715 log_decoding_CanonLog2_v1(clog2), x, atol=TOLERANCE_ABSOLUTE_TESTS

716 )

717

718 clog2 = np.reshape(clog2, (2, 3, 1))

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

720 np.testing.assert_allclose(

721 log_decoding_CanonLog2_v1(clog2), x, atol=TOLERANCE_ABSOLUTE_TESTS

722 )

723

724 def test_domain_range_scale_log_decoding_CanonLog2_v1(self) -> None:

725 """

726 Test :func:`colour.models.rgb.transfer_functions.canon.\

727 log_decoding_CanonLog2_v1` definition domain and range scale support.

728 """

729

730 clog = 0.398254694983167

731 x = log_decoding_CanonLog2_v1(clog)

732

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

734 for scale, factor in d_r:

735 with domain_range_scale(scale):

736 np.testing.assert_allclose(

737 log_decoding_CanonLog2_v1(clog * factor),

738 x * factor,

739 atol=TOLERANCE_ABSOLUTE_TESTS,

740 )

741

742 @ignore_numpy_errors

743 def test_nan_log_decoding_CanonLog2_v1(self) -> None:

744 """

745 Test :func:`colour.models.rgb.transfer_functions.canon.\

746 log_decoding_CanonLog2_v1` definition nan support.

747 """

748

749 log_decoding_CanonLog2_v1(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

750

751

752 class TestLogEncoding_CanonLog2_v1_2:

753 """

754 Define :func:`colour.models.rgb.transfer_functions.canon.\

755 log_encoding_CanonLog2_v1_2` definition unit tests methods.

756 """

757

758 def test_log_encoding_CanonLog2_v1_2(self) -> None:

759 """

760 Test :func:`colour.models.rgb.transfer_functions.canon.\

761 log_encoding_CanonLog2_v1_2` definition.

762 """

763

764 np.testing.assert_allclose(

765 log_encoding_CanonLog2_v1_2(-0.1),

766 -0.155370130476722,

767 atol=TOLERANCE_ABSOLUTE_TESTS,

768 )

769

770 np.testing.assert_allclose(

771 log_encoding_CanonLog2_v1_2(0.0),

772 0.092864125000000,

773 atol=TOLERANCE_ABSOLUTE_TESTS,

774 )

775

776 np.testing.assert_allclose(

777 log_encoding_CanonLog2_v1_2(0.18),

778 0.398254692561492,

779 atol=TOLERANCE_ABSOLUTE_TESTS,

780 )

781

782 np.testing.assert_allclose(

783 log_encoding_CanonLog2_v1_2(0.18, 12),

784 0.398254692561492,

785 atol=TOLERANCE_ABSOLUTE_TESTS,

786 )

787

788 np.testing.assert_allclose(

789 log_encoding_CanonLog2_v1_2(0.18, 10, False),

790 0.392025742568957,

791 atol=TOLERANCE_ABSOLUTE_TESTS,

792 )

793

794 np.testing.assert_allclose(

795 log_encoding_CanonLog2_v1_2(0.18, 10, False, False),

796 0.379864579481518,

797 atol=TOLERANCE_ABSOLUTE_TESTS,

798 )

799

800 np.testing.assert_allclose(

801 log_encoding_CanonLog2_v1_2(1.0),

802 0.573229279230156,

803 atol=TOLERANCE_ABSOLUTE_TESTS,

804 )

805

806 samples = np.linspace(0, 1, 10000)

807

808 np.testing.assert_allclose(

809 log_encoding_CanonLog2_v1(samples),

810 log_encoding_CanonLog2_v1_2(samples),

811 atol=TOLERANCE_ABSOLUTE_TESTS,

812 )

813

814 np.testing.assert_allclose(

815 log_encoding_CanonLog2_v1(samples),

816 log_encoding_CanonLog2_v1_2(samples),

817 atol=TOLERANCE_ABSOLUTE_TESTS,

818 )

819

820 np.testing.assert_allclose(

821 log_encoding_CanonLog2_v1(samples, out_normalised_code_value=False),

822 log_encoding_CanonLog2_v1_2(samples, out_normalised_code_value=False),

823 atol=TOLERANCE_ABSOLUTE_TESTS,

824 )

825 np.testing.assert_allclose(

826 log_encoding_CanonLog2_v1(samples, in_reflection=False),

827 log_encoding_CanonLog2_v1_2(samples, in_reflection=False),

828 atol=TOLERANCE_ABSOLUTE_TESTS,

829 )

830

831 def test_n_dimensional_log_encoding_CanonLog2_v1_2(self) -> None:

832 """

833 Test :func:`colour.models.rgb.transfer_functions.canon.\

834 log_encoding_CanonLog2_v1_2` definition n-dimensional arrays support.

835 """

836

837 x = 0.18

838 clog2 = log_encoding_CanonLog2_v1_2(x)

839

840 x = np.tile(x, 6)

841 clog2 = np.tile(clog2, 6)

842 np.testing.assert_allclose(

843 log_encoding_CanonLog2_v1_2(x),

844 clog2,

845 atol=TOLERANCE_ABSOLUTE_TESTS,

846 )

847

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

849 clog2 = np.reshape(clog2, (2, 3))

850 np.testing.assert_allclose(

851 log_encoding_CanonLog2_v1_2(x),

852 clog2,

853 atol=TOLERANCE_ABSOLUTE_TESTS,

854 )

855

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

857 clog2 = np.reshape(clog2, (2, 3, 1))

858 np.testing.assert_allclose(

859 log_encoding_CanonLog2_v1_2(x),

860 clog2,

861 atol=TOLERANCE_ABSOLUTE_TESTS,

862 )

863

864 def test_domain_range_scale_log_encoding_CanonLog2_v1_2(self) -> None:

865 """

866 Test :func:`colour.models.rgb.transfer_functions.canon.\

867 log_encoding_CanonLog2_v1_2` definition domain and range scale support.

868 """

869

870 x = 0.18

871 clog2 = log_encoding_CanonLog2_v1_2(x)

872

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

874 for scale, factor in d_r:

875 with domain_range_scale(scale):

876 np.testing.assert_allclose(

877 log_encoding_CanonLog2_v1_2(x * factor),

878 clog2 * factor,

879 atol=TOLERANCE_ABSOLUTE_TESTS,

880 )

881

882 @ignore_numpy_errors

883 def test_nan_log_encoding_CanonLog2_v1_2(self) -> None:

884 """

885 Test :func:`colour.models.rgb.transfer_functions.canon.\

886 log_encoding_CanonLog2_v1_2` definition nan support.

887 """

888

889 log_encoding_CanonLog2_v1_2(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

890

891

892 class TestLogDecoding_CanonLog2_v1_2:

893 """

894 Define :func:`colour.models.rgb.transfer_functions.canon.\

895 log_decoding_CanonLog2_v1_2` definition unit tests methods.

896 """

897

898 def test_log_decoding_CanonLog2_v1_2(self) -> None:

899 """

900 Test :func:`colour.models.rgb.transfer_functions.canon.\

901 log_decoding_CanonLog2_v1_2` definition.

902 """

903

904 np.testing.assert_allclose(

905 log_decoding_CanonLog2_v1_2(-0.155370130476722),

906 -0.1,

907 atol=TOLERANCE_ABSOLUTE_TESTS,

908 )

909

910 np.testing.assert_allclose(

911 log_decoding_CanonLog2_v1_2(0.092864125000000),

912 0.0,

913 atol=TOLERANCE_ABSOLUTE_TESTS,

914 )

915

916 np.testing.assert_allclose(

917 log_decoding_CanonLog2_v1_2(0.398254692561492),

918 0.18,

919 atol=TOLERANCE_ABSOLUTE_TESTS,

920 )

921

922 np.testing.assert_allclose(

923 log_decoding_CanonLog2_v1_2(0.398254692561492, 12),

924 0.18,

925 atol=TOLERANCE_ABSOLUTE_TESTS,

926 )

927

928 np.testing.assert_allclose(

929 log_decoding_CanonLog2_v1_2(0.392025742568957, 10, False),

930 0.18,

931 atol=TOLERANCE_ABSOLUTE_TESTS,

932 )

933

934 np.testing.assert_allclose(

935 log_decoding_CanonLog2_v1_2(0.379864579481518, 10, False, False),

936 0.18,

937 atol=TOLERANCE_ABSOLUTE_TESTS,

938 )

939

940 np.testing.assert_allclose(

941 log_decoding_CanonLog2_v1_2(0.573229279230156),

942 1.0,

943 atol=TOLERANCE_ABSOLUTE_TESTS,

944 )

945

946 samples = np.linspace(0, 1, 10000)

947

948 np.testing.assert_allclose(

949 log_decoding_CanonLog_v1(samples),

950 log_decoding_CanonLog_v1_2(samples),

951 atol=TOLERANCE_ABSOLUTE_TESTS,

952 )

953

954 np.testing.assert_allclose(

955 log_decoding_CanonLog_v1(samples),

956 log_decoding_CanonLog_v1_2(samples),

957 atol=TOLERANCE_ABSOLUTE_TESTS,

958 )

959

960 np.testing.assert_allclose(

961 log_decoding_CanonLog_v1(samples, in_normalised_code_value=False),

962 log_decoding_CanonLog_v1_2(samples, in_normalised_code_value=False),

963 atol=TOLERANCE_ABSOLUTE_TESTS,

964 )

965 np.testing.assert_allclose(

966 log_decoding_CanonLog_v1(samples, out_reflection=False),

967 log_decoding_CanonLog_v1_2(samples, out_reflection=False),

968 atol=TOLERANCE_ABSOLUTE_TESTS,

969 )

970

971 def test_n_dimensional_log_decoding_CanonLog2_v1_2(self) -> None:

972 """

973 Test :func:`colour.models.rgb.transfer_functions.canon.\

974 log_decoding_CanonLog2_v1_2` definition n-dimensional arrays support.

975 """

976

977 clog2 = 0.398254692561492

978 x = log_decoding_CanonLog2_v1_2(clog2)

979

980 clog2 = np.tile(clog2, 6)

981 x = np.tile(x, 6)

982 np.testing.assert_allclose(

983 log_decoding_CanonLog2_v1_2(clog2),

984 x,

985 atol=TOLERANCE_ABSOLUTE_TESTS,

986 )

987

988 clog2 = np.reshape(clog2, (2, 3))

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

990 np.testing.assert_allclose(

991 log_decoding_CanonLog2_v1_2(clog2),

992 x,

993 atol=TOLERANCE_ABSOLUTE_TESTS,

994 )

995

996 clog2 = np.reshape(clog2, (2, 3, 1))

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

998 np.testing.assert_allclose(

999 log_decoding_CanonLog2_v1_2(clog2),

1000 x,

1001 atol=TOLERANCE_ABSOLUTE_TESTS,

1002 )

1003

1004 def test_domain_range_scale_log_decoding_CanonLog2_v1_2(self) -> None:

1005 """

1006 Test :func:`colour.models.rgb.transfer_functions.canon.\

1007 log_decoding_CanonLog2_v1_2` definition domain and range scale support.

1008 """

1009

1010 clog = 0.398254692561492

1011 x = log_decoding_CanonLog2_v1_2(clog)

1012

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

1014 for scale, factor in d_r:

1015 with domain_range_scale(scale):

1016 np.testing.assert_allclose(

1017 log_decoding_CanonLog2_v1_2(clog * factor),

1018 x * factor,

1019 atol=TOLERANCE_ABSOLUTE_TESTS,

1020 )

1021

1022 @ignore_numpy_errors

1023 def test_nan_log_decoding_CanonLog2_v1_2(self) -> None:

1024 """

1025 Test :func:`colour.models.rgb.transfer_functions.canon.\

1026 log_decoding_CanonLog2_v1_2` definition nan support.

1027 """

1028

1029 log_decoding_CanonLog2_v1_2(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

1030

1031

1032 class TestLogEncoding_CanonLog3_v1:

1033 """

1034 Define :func:`colour.models.rgb.transfer_functions.canon.\

1035 log_encoding_CanonLog3_v1` definition unit tests methods.

1036 """

1037

1038 def test_log_encoding_CanonLog3_v1(self) -> None:

1039 """

1040 Test :func:`colour.models.rgb.transfer_functions.canon.\

1041 log_encoding_CanonLog3_v1` definition.

1042 """

1043

1044 np.testing.assert_allclose(

1045 log_encoding_CanonLog3_v1(-0.1),

1046 -0.028494506076432,

1047 atol=TOLERANCE_ABSOLUTE_TESTS,

1048 )

1049

1050 np.testing.assert_allclose(

1051 log_encoding_CanonLog3_v1(0.0),

1052 0.125122189869013,

1053 atol=TOLERANCE_ABSOLUTE_TESTS,

1054 )

1055

1056 np.testing.assert_allclose(

1057 log_encoding_CanonLog3_v1(0.18),

1058 0.343389369388687,

1059 atol=TOLERANCE_ABSOLUTE_TESTS,

1060 )

1061

1062 np.testing.assert_allclose(

1063 log_encoding_CanonLog3_v1(0.18, 12),

1064 0.343137802085105,

1065 atol=TOLERANCE_ABSOLUTE_TESTS,

1066 )

1067

1068 np.testing.assert_allclose(

1069 log_encoding_CanonLog3_v1(0.18, 10, False),

1070 0.327953567219893,

1071 atol=TOLERANCE_ABSOLUTE_TESTS,

1072 )

1073

1074 np.testing.assert_allclose(

1075 log_encoding_CanonLog3_v1(0.18, 10, False, False),

1076 0.313436005886328,

1077 atol=TOLERANCE_ABSOLUTE_TESTS,

1078 )

1079

1080 np.testing.assert_allclose(

1081 log_encoding_CanonLog3_v1(1.0),

1082 0.580277796238604,

1083 atol=TOLERANCE_ABSOLUTE_TESTS,

1084 )

1085

1086 def test_n_dimensional_log_encoding_CanonLog3_v1(self) -> None:

1087 """

1088 Test :func:`colour.models.rgb.transfer_functions.canon.\

1089 log_encoding_CanonLog3_v1` definition n-dimensional arrays support.

1090 """

1091

1092 x = 0.18

1093 clog3 = log_encoding_CanonLog3_v1(x)

1094

1095 x = np.tile(x, 6)

1096 clog3 = np.tile(clog3, 6)

1097 np.testing.assert_allclose(

1098 log_encoding_CanonLog3_v1(x), clog3, atol=TOLERANCE_ABSOLUTE_TESTS

1099 )

1100

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

1102 clog3 = np.reshape(clog3, (2, 3))

1103 np.testing.assert_allclose(

1104 log_encoding_CanonLog3_v1(x), clog3, atol=TOLERANCE_ABSOLUTE_TESTS

1105 )

1106

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

1108 clog3 = np.reshape(clog3, (2, 3, 1))

1109 np.testing.assert_allclose(

1110 log_encoding_CanonLog3_v1(x), clog3, atol=TOLERANCE_ABSOLUTE_TESTS

1111 )

1112

1113 def test_domain_range_scale_log_encoding_CanonLog3_v1(self) -> None:

1114 """

1115 Test :func:`colour.models.rgb.transfer_functions.canon.\

1116 log_encoding_CanonLog3_v1` definition domain and range scale support.

1117 """

1118

1119 x = 0.18

1120 clog3 = log_encoding_CanonLog3_v1(x)

1121

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

1123 for scale, factor in d_r:

1124 with domain_range_scale(scale):

1125 np.testing.assert_allclose(

1126 log_encoding_CanonLog3_v1(x * factor),

1127 clog3 * factor,

1128 atol=TOLERANCE_ABSOLUTE_TESTS,

1129 )

1130

1131 @ignore_numpy_errors

1132 def test_nan_log_encoding_CanonLog3_v1(self) -> None:

1133 """

1134 Test :func:`colour.models.rgb.transfer_functions.canon.\

1135 log_encoding_CanonLog3_v1` definition nan support.

1136 """

1137

1138 log_encoding_CanonLog3_v1(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

1139

1140

1141 class TestLogDecoding_CanonLog3_v1:

1142 """

1143 Define :func:`colour.models.rgb.transfer_functions.canon.\

1144 log_decoding_CanonLog3_v1` definition unit tests methods.

1145 """

1146

1147 def test_log_decoding_CanonLog3_v1(self) -> None:

1148 """

1149 Test :func:`colour.models.rgb.transfer_functions.canon.\

1150 log_decoding_CanonLog3_v1` definition.

1151 """

1152

1153 np.testing.assert_allclose(

1154 log_decoding_CanonLog3_v1(-0.028494506076432),

1155 -0.1,

1156 atol=TOLERANCE_ABSOLUTE_TESTS,

1157 )

1158

1159 np.testing.assert_allclose(

1160 log_decoding_CanonLog3_v1(0.125122189869013),

1161 0.0,

1162 atol=TOLERANCE_ABSOLUTE_TESTS,

1163 )

1164

1165 np.testing.assert_allclose(

1166 log_decoding_CanonLog3_v1(0.343389369388687),

1167 0.18,

1168 atol=TOLERANCE_ABSOLUTE_TESTS,

1169 )

1170

1171 np.testing.assert_allclose(

1172 log_decoding_CanonLog3_v1(0.343137802085105, 12),

1173 0.18,

1174 atol=TOLERANCE_ABSOLUTE_TESTS,

1175 )

1176

1177 np.testing.assert_allclose(

1178 log_decoding_CanonLog3_v1(0.327953567219893, 10, False),

1179 0.18,

1180 atol=TOLERANCE_ABSOLUTE_TESTS,

1181 )

1182

1183 np.testing.assert_allclose(

1184 log_decoding_CanonLog3_v1(0.313436005886328, 10, False, False),

1185 0.18,

1186 atol=TOLERANCE_ABSOLUTE_TESTS,

1187 )

1188

1189 np.testing.assert_allclose(

1190 log_decoding_CanonLog3_v1(0.580277796238604),

1191 1.0,

1192 atol=TOLERANCE_ABSOLUTE_TESTS,

1193 )

1194

1195 def test_n_dimensional_log_decoding_CanonLog3_v1(self) -> None:

1196 """

1197 Test :func:`colour.models.rgb.transfer_functions.canon.\

1198 log_decoding_CanonLog3_v1` definition n-dimensional arrays support.

1199 """

1200

1201 clog3 = 0.343389369388687

1202 x = log_decoding_CanonLog3_v1(clog3)

1203

1204 clog3 = np.tile(clog3, 6)

1205 x = np.tile(x, 6)

1206 np.testing.assert_allclose(

1207 log_decoding_CanonLog3_v1(clog3), x, atol=TOLERANCE_ABSOLUTE_TESTS

1208 )

1209

1210 clog3 = np.reshape(clog3, (2, 3))

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

1212 np.testing.assert_allclose(

1213 log_decoding_CanonLog3_v1(clog3), x, atol=TOLERANCE_ABSOLUTE_TESTS

1214 )

1215

1216 clog3 = np.reshape(clog3, (2, 3, 1))

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

1218 np.testing.assert_allclose(

1219 log_decoding_CanonLog3_v1(clog3), x, atol=TOLERANCE_ABSOLUTE_TESTS

1220 )

1221

1222 def test_domain_range_scale_log_decoding_CanonLog3_v1(self) -> None:

1223 """

1224 Test :func:`colour.models.rgb.transfer_functions.canon.\

1225 log_decoding_CanonLog3_v1` definition domain and range scale support.

1226 """

1227

1228 clog = 0.343389369388687

1229 x = log_decoding_CanonLog3_v1(clog)

1230

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

1232 for scale, factor in d_r:

1233 with domain_range_scale(scale):

1234 np.testing.assert_allclose(

1235 log_decoding_CanonLog3_v1(clog * factor),

1236 x * factor,

1237 atol=TOLERANCE_ABSOLUTE_TESTS,

1238 )

1239

1240 @ignore_numpy_errors

1241 def test_nan_log_decoding_CanonLog3_v1(self) -> None:

1242 """

1243 Test :func:`colour.models.rgb.transfer_functions.canon.\

1244 log_decoding_CanonLog3_v1` definition nan support.

1245 """

1246

1247 log_decoding_CanonLog3_v1(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

1248

1249

1250 class TestLogEncoding_CanonLog3_v1_2:

1251 """

1252 Define :func:`colour.models.rgb.transfer_functions.canon.\

1253 log_encoding_CanonLog3_v1_2` definition unit tests methods.

1254 """

1255

1256 def test_log_encoding_CanonLog3_v1_2(self) -> None:

1257 """

1258 Test :func:`colour.models.rgb.transfer_functions.canon.\

1259 log_encoding_CanonLog3_v1_2` definition.

1260 """

1261

1262 np.testing.assert_allclose(

1263 log_encoding_CanonLog3_v1_2(-0.1),

1264 -0.028494507620494,

1265 atol=TOLERANCE_ABSOLUTE_TESTS,

1266 )

1267

1268 np.testing.assert_allclose(

1269 log_encoding_CanonLog3_v1_2(0.0),

1270 0.125122189999999,

1271 atol=TOLERANCE_ABSOLUTE_TESTS,

1272 )

1273

1274 np.testing.assert_allclose(

1275 log_encoding_CanonLog3_v1_2(0.18),

1276 0.343389370373936,

1277 atol=TOLERANCE_ABSOLUTE_TESTS,

1278 )

1279

1280 np.testing.assert_allclose(

1281 log_encoding_CanonLog3_v1_2(0.18, 12),

1282 0.343389370373936,

1283 atol=TOLERANCE_ABSOLUTE_TESTS,

1284 )

1285

1286 np.testing.assert_allclose(

1287 log_encoding_CanonLog3_v1_2(0.18, 10, False),

1288 0.327953568370475,

1289 atol=TOLERANCE_ABSOLUTE_TESTS,

1290 )

1291

1292 np.testing.assert_allclose(

1293 log_encoding_CanonLog3_v1_2(0.18, 10, False, False),

1294 0.313436007221221,

1295 atol=TOLERANCE_ABSOLUTE_TESTS,

1296 )

1297

1298 np.testing.assert_allclose(

1299 log_encoding_CanonLog3_v1_2(1.0),

1300 0.580277794216371,

1301 atol=TOLERANCE_ABSOLUTE_TESTS,

1302 )

1303

1304 samples = np.linspace(0, 1, 10000)

1305

1306 np.testing.assert_allclose(

1307 log_encoding_CanonLog3_v1(samples),

1308 log_encoding_CanonLog3_v1_2(samples),

1309 atol=TOLERANCE_ABSOLUTE_TESTS,

1310 )

1311

1312 np.testing.assert_allclose(

1313 log_encoding_CanonLog3_v1(samples),

1314 log_encoding_CanonLog3_v1_2(samples),

1315 atol=TOLERANCE_ABSOLUTE_TESTS,

1316 )

1317

1318 np.testing.assert_allclose(

1319 log_encoding_CanonLog3_v1(samples, out_normalised_code_value=False),

1320 log_encoding_CanonLog3_v1_2(samples, out_normalised_code_value=False),

1321 atol=TOLERANCE_ABSOLUTE_TESTS,

1322 )

1323 np.testing.assert_allclose(

1324 log_encoding_CanonLog3_v1(samples, in_reflection=False),

1325 log_encoding_CanonLog3_v1_2(samples, in_reflection=False),

1326 atol=TOLERANCE_ABSOLUTE_TESTS,

1327 )

1328

1329 def test_n_dimensional_log_encoding_CanonLog3_v1_2(self) -> None:

1330 """

1331 Test :func:`colour.models.rgb.transfer_functions.canon.\

1332 log_encoding_CanonLog3_v1_2` definition n-dimensional arrays support.

1333 """

1334

1335 x = 0.18

1336 clog3 = log_encoding_CanonLog3_v1_2(x)

1337

1338 x = np.tile(x, 6)

1339 clog3 = np.tile(clog3, 6)

1340 np.testing.assert_allclose(

1341 log_encoding_CanonLog3_v1_2(x),

1342 clog3,

1343 atol=TOLERANCE_ABSOLUTE_TESTS,

1344 )

1345

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

1347 clog3 = np.reshape(clog3, (2, 3))

1348 np.testing.assert_allclose(

1349 log_encoding_CanonLog3_v1_2(x),

1350 clog3,

1351 atol=TOLERANCE_ABSOLUTE_TESTS,

1352 )

1353

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

1355 clog3 = np.reshape(clog3, (2, 3, 1))

1356 np.testing.assert_allclose(

1357 log_encoding_CanonLog3_v1_2(x),

1358 clog3,

1359 atol=TOLERANCE_ABSOLUTE_TESTS,

1360 )

1361

1362 def test_domain_range_scale_log_encoding_CanonLog3_v1_2(self) -> None:

1363 """

1364 Test :func:`colour.models.rgb.transfer_functions.canon.\

1365 log_encoding_CanonLog3_v1_2` definition domain and range scale support.

1366 """

1367

1368 x = 0.18

1369 clog3 = log_encoding_CanonLog3_v1_2(x)

1370

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

1372 for scale, factor in d_r:

1373 with domain_range_scale(scale):

1374 np.testing.assert_allclose(

1375 log_encoding_CanonLog3_v1_2(x * factor),

1376 clog3 * factor,

1377 atol=TOLERANCE_ABSOLUTE_TESTS,

1378 )

1379

1380 @ignore_numpy_errors

1381 def test_nan_log_encoding_CanonLog3_v1_2(self) -> None:

1382 """

1383 Test :func:`colour.models.rgb.transfer_functions.canon.\

1384 log_encoding_CanonLog3_v1_2` definition nan support.

1385 """

1386

1387 log_encoding_CanonLog3_v1_2(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))

1388

1389

1390 class TestLogDecoding_CanonLog3_v1_2:

1391 """

1392 Define :func:`colour.models.rgb.transfer_functions.canon.\

1393 log_decoding_CanonLog3_v1_2` definition unit tests methods.

1394 """

1395

1396 def test_log_decoding_CanonLog3_v1_2(self) -> None:

1397 """

1398 Test :func:`colour.models.rgb.transfer_functions.canon.\

1399 log_decoding_CanonLog3_v1_2` definition.

1400 """

1401

1402 np.testing.assert_allclose(

1403 log_decoding_CanonLog3_v1_2(-0.028494507620494),

1404 -0.1,

1405 atol=TOLERANCE_ABSOLUTE_TESTS,

1406 )

1407

1408 np.testing.assert_allclose(

1409 log_decoding_CanonLog3_v1_2(0.125122189999999),

1410 0.0,

1411 atol=TOLERANCE_ABSOLUTE_TESTS,

1412 )

1413

1414 np.testing.assert_allclose(

1415 log_decoding_CanonLog3_v1_2(0.343389370373936),

1416 0.18,

1417 atol=TOLERANCE_ABSOLUTE_TESTS,

1418 )

1419

1420 np.testing.assert_allclose(

1421 log_decoding_CanonLog3_v1_2(0.343389370373936, 12),

1422 0.18,

1423 atol=TOLERANCE_ABSOLUTE_TESTS,

1424 )

1425

1426 np.testing.assert_allclose(

1427 log_decoding_CanonLog3_v1_2(0.327953568370475, 10, False),

1428 0.18,

1429 atol=TOLERANCE_ABSOLUTE_TESTS,

1430 )

1431

1432 np.testing.assert_allclose(

1433 log_decoding_CanonLog3_v1_2(0.313436007221221, 10, False, False),

1434 0.18,

1435 atol=TOLERANCE_ABSOLUTE_TESTS,

1436 )

1437

1438 np.testing.assert_allclose(

1439 log_decoding_CanonLog3_v1_2(0.580277794216371),

1440 1.0,

1441 atol=TOLERANCE_ABSOLUTE_TESTS,

1442 )

1443

1444 samples = np.linspace(0, 1, 10000)

1445

1446 np.testing.assert_allclose(

1447 log_decoding_CanonLog3_v1(samples),

1448 log_decoding_CanonLog3_v1_2(samples),

1449 atol=TOLERANCE_ABSOLUTE_TESTS,

1450 )

1451

1452 np.testing.assert_allclose(

1453 log_decoding_CanonLog3_v1(samples),

1454 log_decoding_CanonLog3_v1_2(samples),

1455 atol=TOLERANCE_ABSOLUTE_TESTS,

1456 )

1457

1458 np.testing.assert_allclose(

1459 log_decoding_CanonLog3_v1(samples, in_normalised_code_value=False),

1460 log_decoding_CanonLog3_v1_2(samples, in_normalised_code_value=False),

1461 atol=TOLERANCE_ABSOLUTE_TESTS,

1462 )

1463 np.testing.assert_allclose(

1464 log_decoding_CanonLog3_v1(samples, out_reflection=False),

1465 log_decoding_CanonLog3_v1_2(samples, out_reflection=False),

1466 atol=TOLERANCE_ABSOLUTE_TESTS,

1467 )

1468

1469 def test_n_dimensional_log_decoding_CanonLog3_v1_2(self) -> None:

1470 """

1471 Test :func:`colour.models.rgb.transfer_functions.canon.\

1472 log_decoding_CanonLog3_v1_2` definition n-dimensional arrays support.

1473 """

1474

1475 clog3 = 0.343389370373936

1476 x = log_decoding_CanonLog3_v1_2(clog3)

1477

1478 clog3 = np.tile(clog3, 6)

1479 x = np.tile(x, 6)

1480 np.testing.assert_allclose(

1481 log_decoding_CanonLog3_v1_2(clog3),

1482 x,

1483 atol=TOLERANCE_ABSOLUTE_TESTS,

1484 )

1485

1486 clog3 = np.reshape(clog3, (2, 3))

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

1488 np.testing.assert_allclose(

1489 log_decoding_CanonLog3_v1_2(clog3),

1490 x,

1491 atol=TOLERANCE_ABSOLUTE_TESTS,

1492 )

1493

1494 clog3 = np.reshape(clog3, (2, 3, 1))

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

1496 np.testing.assert_allclose(

1497 log_decoding_CanonLog3_v1_2(clog3),

1498 x,

1499 atol=TOLERANCE_ABSOLUTE_TESTS,

1500 )

1501

1502 def test_domain_range_scale_log_decoding_CanonLog3_v1_2(self) -> None:

1503 """

1504 Test :func:`colour.models.rgb.transfer_functions.canon.\

1505 log_decoding_CanonLog3_v1_2` definition domain and range scale support.

1506 """

1507

1508 clog = 0.343389370373936

1509 x = log_decoding_CanonLog3_v1_2(clog)

1510

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

1512 for scale, factor in d_r:

1513 with domain_range_scale(scale):

1514 np.testing.assert_allclose(

1515 log_decoding_CanonLog3_v1_2(clog * factor),

1516 x * factor,

1517 atol=TOLERANCE_ABSOLUTE_TESTS,

1518 )

1519

1520 @ignore_numpy_errors

1521 def test_nan_log_decoding_CanonLog3_v1_2(self) -> None:

1522 """

1523 Test :func:`colour.models.rgb.transfer_functions.canon.\

1524 log_decoding_CanonLog3_v1_2` definition nan support.

1525 """

1526

1527 log_decoding_CanonLog3_v1_2(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))