Skip to content

Commit

Permalink
Implement support for "Numpy" 1.24.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Dec 21, 2022
1 parent 607f928 commit 359dae3
Show file tree
Hide file tree
Showing 18 changed files with 445 additions and 424 deletions.
19 changes: 10 additions & 9 deletions colour/characterisation/correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
from colour.hints import ArrayLike, Any, Literal, NDArrayFloat, Union
from colour.utilities import (
CanonicalMapping,
as_float,
as_float_array,
as_int,
closest,
Expand Down Expand Up @@ -414,9 +415,9 @@ def polynomial_expansion_Finlayson2015(
if root_polynomial_expansion:
return tstack(
[
R,
G,
B,
as_float(R),
as_float(G),
as_float(B),
spow(R * G, 1 / 2),
spow(G * B, 1 / 2),
spow(R * B, 1 / 2),
Expand All @@ -441,9 +442,9 @@ def polynomial_expansion_Finlayson2015(
if root_polynomial_expansion:
return tstack(
[
R,
G,
B,
as_float(R),
as_float(G),
as_float(B),
spow(R * G, 1 / 2),
spow(G * B, 1 / 2),
spow(R * B, 1 / 2),
Expand Down Expand Up @@ -484,9 +485,9 @@ def polynomial_expansion_Finlayson2015(
if root_polynomial_expansion:
return tstack(
[
R,
G,
B,
as_float(R),
as_float(G),
as_float(B),
spow(R * G, 1 / 2),
spow(G * B, 1 / 2),
spow(R * B, 1 / 2),
Expand Down
24 changes: 12 additions & 12 deletions colour/characterisation/tests/test_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,8 @@ def test_nan_matrix_colour_correction_Cheung2004(self): # pragma: no cover
matrix_colour_correction_Cheung2004` definition nan support.
"""

# NOTE: Hangs on "Linux".
if platform.system() == "Linux":
# NOTE: Hangs on "macOS" and "Linux".
if platform.system() in ("Darwin", "Linux"):
return

cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
Expand Down Expand Up @@ -790,8 +790,8 @@ def test_nan_matrix_colour_correction_Finlayson2015(
matrix_colour_correction_Finlayson2015` definition nan support.
"""

# NOTE: Hangs on "Linux".
if platform.system() == "Linux":
# NOTE: Hangs on "macOS" and "Linux".
if platform.system() in ("Darwin", "Linux"):
return

cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
Expand Down Expand Up @@ -888,8 +888,8 @@ def test_nan_matrix_colour_correction_Vandermonde(
matrix_colour_correction_Vandermonde` definition nan support.
"""

# NOTE: Hangs on "Linux".
if platform.system() == "Linux":
# NOTE: Hangs on "macOS" and "Linux".
if platform.system() in ("Darwin", "Linux"):
return

cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
Expand Down Expand Up @@ -966,8 +966,8 @@ def test_nan_colour_correction_Cheung2004(self): # pragma: no cover
colour_correction_Cheung2004` definition nan support.
"""

# NOTE: Hangs on "Linux".
if platform.system() == "Linux":
# NOTE: Hangs on "macOS" and "Linux".
if platform.system() in ("Darwin", "Linux"):
return

cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
Expand Down Expand Up @@ -1051,8 +1051,8 @@ def test_nan_colour_correction_Finlayson2015(self): # pragma: no cover
colour_correction_Finlayson2015` definition nan support.
"""

# NOTE: Hangs on "Linux".
if platform.system() == "Linux":
# NOTE: Hangs on "macOS" and "Linux".
if platform.system() in ("Darwin", "Linux"):
return

cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
Expand Down Expand Up @@ -1130,8 +1130,8 @@ def test_nan_colour_correction_Vandermonde(self): # pragma: no cover
colour_correction_Vandermonde` definition nan support.
"""

# NOTE: Hangs on "Linux".
if platform.system() == "Linux":
# NOTE: Hangs on "macOS" and "Linux".
if platform.system() in ("Darwin", "Linux"):
return

cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
Expand Down
14 changes: 10 additions & 4 deletions colour/io/luts/lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
cast,
)
from colour.utilities import (
as_array,
as_float_array,
as_int,
as_int_array,
Expand Down Expand Up @@ -2118,10 +2119,15 @@ def linear_table(
if domain.shape != (2, 3):
samples = list(
np.flip(
[
axes[: (~np.isnan(axes)).cumsum().argmax() + 1]
for axes in np.transpose(domain)
],
# NOTE: "dtype=object" is required for ragged array support
# in "Numpy" 1.24.0.
as_array(
[
axes[: (~np.isnan(axes)).cumsum().argmax() + 1]
for axes in np.transpose(domain)
],
dtype=object, # pyright: ignore
),
-1,
)
)
Expand Down
2 changes: 1 addition & 1 deletion colour/models/rgb/transfer_functions/canon.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def log_encoding_CanonLog(
are obtained as follows:
>>> x = np.array([0, 2, 18, 90, 720]) / 100
>>> np.around(log_encoding_CanonLog(x) * (2**10 - 1)).astype(np.int)
>>> np.around(log_encoding_CanonLog(x) * (2**10 - 1)).astype(np.int_)
array([ 128, 169, 351, 614, 1016])
>>> np.around(log_encoding_CanonLog(x, 10, False) * 100, 1)
array([ 7.3, 12. , 32.8, 62.7, 108.7])
Expand Down
4 changes: 2 additions & 2 deletions colour/models/rgb/transfer_functions/fujifilm_f_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def log_encoding_FLog(
>>> x = np.array([0, 18, 90]) / 100
>>> np.around(log_encoding_FLog(x, 10, False) * 100, 1)
array([ 3.5, 46.3, 73.2])
>>> np.around(log_encoding_FLog(x) * (2**10 - 1)).astype(np.int)
>>> np.around(log_encoding_FLog(x) * (2**10 - 1)).astype(np.int_)
array([ 95, 470, 705])
"""

Expand Down Expand Up @@ -294,7 +294,7 @@ def log_encoding_FLog2(
>>> x = np.array([0, 18, 90]) / 100
>>> np.around(log_encoding_FLog2(x, 10, False) * 100, 1)
array([ 3.5, 38.4, 57.8])
>>> np.around(log_encoding_FLog2(x) * (2**10 - 1)).astype(np.int)
>>> np.around(log_encoding_FLog2(x) * (2**10 - 1)).astype(np.int_)
array([ 95, 400, 570])
"""

Expand Down
6 changes: 3 additions & 3 deletions colour/models/rgb/transfer_functions/panasonic_v_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ def log_encoding_VLog(
are obtained as follows:
>>> L_in = np.array([0, 18, 90]) / 100
>>> np.around(log_encoding_VLog(L_in, 10, False) * 100).astype(np.int)
>>> np.around(log_encoding_VLog(L_in, 10, False) * 100).astype(np.int_)
array([ 7, 42, 61])
>>> np.around(log_encoding_VLog(L_in) * (2**10 - 1)).astype(np.int)
>>> np.around(log_encoding_VLog(L_in) * (2**10 - 1)).astype(np.int_)
array([128, 433, 602])
>>> np.around(log_encoding_VLog(L_in) * (2**12 - 1)).astype(np.int)
>>> np.around(log_encoding_VLog(L_in) * (2**12 - 1)).astype(np.int_)
array([ 512, 1733, 2409])
Note that some values in the last column values of
Expand Down
12 changes: 6 additions & 6 deletions colour/models/rgb/transfer_functions/sony.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def log_encoding_SLog(
:cite:`SonyCorporation2012a` are obtained as follows:
>>> x = np.array([0, 18, 90]) / 100
>>> np.around(log_encoding_SLog(x, 10, False) * 100).astype(np.int)
>>> np.around(log_encoding_SLog(x, 10, False) * 100).astype(np.int_)
array([ 3, 38, 65])
>>> np.around(log_encoding_SLog(x) * (2**10 - 1)).astype(np.int)
>>> np.around(log_encoding_SLog(x) * (2**10 - 1)).astype(np.int_)
array([ 90, 394, 636])
"""

Expand Down Expand Up @@ -257,9 +257,9 @@ def log_encoding_SLog2(
:cite:`SonyCorporation2012a` are obtained as follows:
>>> x = np.array([0, 18, 90]) / 100
>>> np.around(log_encoding_SLog2(x, 10, False) * 100).astype(np.int)
>>> np.around(log_encoding_SLog2(x, 10, False) * 100).astype(np.int_)
array([ 3, 32, 59])
>>> np.around(log_encoding_SLog2(x) * (2**10 - 1)).astype(np.int)
>>> np.around(log_encoding_SLog2(x) * (2**10 - 1)).astype(np.int_)
array([ 90, 347, 582])
"""

Expand Down Expand Up @@ -386,9 +386,9 @@ def log_encoding_SLog3(
:cite:`SonyCorporationd` are obtained as follows:
>>> x = np.array([0, 18, 90]) / 100
>>> np.around(log_encoding_SLog3(x, 10, False) * 100).astype(np.int)
>>> np.around(log_encoding_SLog3(x, 10, False) * 100).astype(np.int_)
array([ 4, 41, 61])
>>> np.around(log_encoding_SLog3(x) * (2**10 - 1)).astype(np.int)
>>> np.around(log_encoding_SLog3(x) * (2**10 - 1)).astype(np.int_)
array([ 95, 420, 598])
"""

Expand Down
16 changes: 9 additions & 7 deletions colour/notation/munsell.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,8 @@ def _munsell_specification_to_xyY(specification: ArrayLike) -> NDArrayFloat:
x_plus, y_plus = tsplit(munsell_specification_to_xy(specification_plus))

if value_minus == value_plus:
x = x_minus
y = y_minus
x = as_float(x_minus)
y = as_float(y_minus)
else:
with domain_range_scale("ignore"):
Y_minus = luminance_ASTMD1535(value_minus)
Expand All @@ -917,10 +917,12 @@ def _munsell_specification_to_xyY(specification: ArrayLike) -> NDArrayFloat:
x_minus_plus = np.squeeze([x_minus, x_plus])
y_minus_plus = np.squeeze([y_minus, y_plus])

x = LinearInterpolator(Y_minus_plus, x_minus_plus)(Y)
y = LinearInterpolator(Y_minus_plus, y_minus_plus)(Y)
x = as_float(LinearInterpolator(Y_minus_plus, x_minus_plus)(Y))
y = as_float(LinearInterpolator(Y_minus_plus, y_minus_plus)(Y))

return tstack([x, y, from_range_1(Y / 100)])
Y = from_range_1(Y / 100)

return tstack([x, y, Y])


def munsell_specification_to_xyY(specification: ArrayLike) -> NDArrayFloat:
Expand Down Expand Up @@ -1293,12 +1295,12 @@ def _xyY_to_munsell_specification(xyY: ArrayLike) -> NDArrayFloat:
if chroma_inner > chroma_maximum:
chroma_inner = specification_current[2] = chroma_maximum

specification_inner = (
specification_inner = [
hue_current,
value,
chroma_inner,
code_current,
)
]

with domain_range_scale("ignore"):
x_inner, y_inner, _Y_inner = _munsell_specification_to_xyY(
Expand Down
18 changes: 11 additions & 7 deletions colour/notation/tests/test_munsell.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
munsell_value_ASTMD1535,
)
from colour.utilities import (
as_array,
as_float_array,
domain_range_scale,
ignore_numpy_errors,
Expand Down Expand Up @@ -154,7 +155,7 @@ def _generate_unit_tests_specifications() -> tuple: # pragma: no cover
return specifications, specifications_r


MUNSELL_SPECIFICATIONS: NDArrayFloat = np.array(
MUNSELL_SPECIFICATIONS: NDArrayFloat = as_array(
[
[
[7.18927191, 5.34025196, 16.05861170, 3.00000000],
Expand Down Expand Up @@ -556,10 +557,11 @@ def _generate_unit_tests_specifications() -> tuple: # pragma: no cover
[3.40490668, 6.59689139, 9.20874115, 7.00000000],
[0.41967010, 0.31821655, 0.36537324],
],
]
],
dtype=object, # pyright: ignore
)

MUNSELL_GREYS_SPECIFICATIONS: NDArrayFloat = np.array(
MUNSELL_GREYS_SPECIFICATIONS: NDArrayFloat = as_array(
list(
zip(
np.linspace(0, 10, 25)[:, None],
Expand Down Expand Up @@ -591,10 +593,11 @@ def _generate_unit_tests_specifications() -> tuple: # pragma: no cover
[0.31006, 0.31616, 1.00000000],
),
)
)
),
dtype=object, # pyright: ignore
)

MUNSELL_EVEN_SPECIFICATIONS: NDArrayFloat = np.array(
MUNSELL_EVEN_SPECIFICATIONS: NDArrayFloat = as_array(
[
[(7.5, 6.0, 16.0, 3), [0.18320000, 0.44140000, 0.29301153]],
[(7.5, 9.0, 12.0, 3), [0.24190000, 0.39850000, 0.76695586]],
Expand Down Expand Up @@ -697,10 +700,11 @@ def _generate_unit_tests_specifications() -> tuple: # pragma: no cover
[(7.5, 5.0, 4.0, 5), [0.38500000, 0.41200000, 0.19271844]],
[(2.5, 6.0, 10.0, 7), [0.43200000, 0.31180000, 0.29301153]],
[(8.0, 2, 14.0, 1), [0.07257382, 0.10413956, 0.03048116]],
] # pyright: ignore
],
dtype=object, # pyright: ignore
)

MUNSELL_BOUNDING_HUES: NDArrayFloat = np.array(
MUNSELL_BOUNDING_HUES: NDArrayFloat = as_float_array(
[
((5.0, 3.0), (7.5, 3.0)),
((5.0, 3.0), (7.5, 3.0)),
Expand Down
Loading

0 comments on commit 359dae3

Please sign in to comment.