Coverage for constants/common.py: 0%

1"""

2 Common Constants

3================

4

5 Define common constants objects that don't belong to any specific

6 category.

7"""

8

9 from __future__ import annotations

10

11 import os

12

13 import numpy as np

14

15 from colour.hints import DTypeComplex, DTypeFloat, Type, cast

16 from colour.utilities.documentation import DocstringFloat, is_documentation_building

17

18 __author__ = "Colour Developers"

19 __copyright__ = "Copyright 2013 Colour Developers"

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

21 __maintainer__ = "Colour Developers"

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

23 __status__ = "Production"

24

25 __all__ = [

26 "PATTERN_FLOATING_POINT_NUMBER",

27 "THRESHOLD_INTEGER",

28 "EPSILON",

29 "DTYPE_INT_DEFAULT",

30 "DTYPE_FLOAT_DEFAULT",

31 "DTYPE_COMPLEX_DEFAULT",

32 "TOLERANCE_ABSOLUTE_DEFAULT",

33 "TOLERANCE_RELATIVE_DEFAULT",

34 "TOLERANCE_ABSOLUTE_TESTS",

35 "TOLERANCE_RELATIVE_TESTS",

36]

37

38 PATTERN_FLOATING_POINT_NUMBER: str = "[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?"

39"""Floating point number regex matching pattern."""

40

41 THRESHOLD_INTEGER: float = 1e-3

42 if is_documentation_building(): # pragma: no cover

43 THRESHOLD_INTEGER = DocstringFloat(THRESHOLD_INTEGER)

44 THRESHOLD_INTEGER.__doc__ = """

45 Integer threshold value when checking if a floating point number is almost an

46 integer.

47"""

48

49 EPSILON: float = cast("float", np.finfo(np.double).eps)

50"""

51 Default epsilon value for tolerance and singularities avoidance in various

52 computations.

53"""

54

55 DTYPE_INT_DEFAULT: Type[np.int32 | np.int64] = cast(

56 "Type[np.int32 | np.int64]",

57 np.sctypeDict.get(

58 os.environ.get("COLOUR_SCIENCE__DEFAULT_INT_DTYPE", "int64"), np.int64

59 ),

60)

61"""Default int number dtype."""

62

63

64 DTYPE_FLOAT_DEFAULT: Type[DTypeFloat] = cast(

65 "Type[DTypeFloat]",

66 np.sctypeDict.get(

67 os.environ.get("COLOUR_SCIENCE__DEFAULT_FLOAT_DTYPE", "float64"),

68 np.float64,

69 ),

70)

71"""Default floating point number dtype."""

72

73 DTYPE_COMPLEX_DEFAULT: Type[DTypeComplex] = cast(

74 "Type[DTypeComplex]",

75 np.sctypeDict.get(

76 os.environ.get("COLOUR_SCIENCE__DEFAULT_COMPLEX_DTYPE", "complex128"),

77 np.complex128,

78 ),

79)

80"""Default complex number dtype."""

81

82 TOLERANCE_ABSOLUTE_DEFAULT: float = 1e-8

83"""Default absolute tolerance for computations."""

84

85 TOLERANCE_RELATIVE_DEFAULT: float = 1e-8

86"""Default relative tolerance for computations."""

87

88 TOLERANCE_ABSOLUTE_TESTS: float = 1e-7

89"""Absolute tolerance for computations during unit tests."""

90

91 TOLERANCE_RELATIVE_TESTS: float = 1e-7

92"""Relative tolerance for computations during unit tests."""