Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Optimisation in colour.utilities.tsplit definition sometimes produces a non-contiguous and non-copy output array. #1309

Closed
KelSolaar opened this issue Nov 2, 2024 · 1 comment

Comments

@KelSolaar
Copy link
Member

KelSolaar commented Nov 2, 2024

Description

The optimisation introduced in #1067 and specifically the if clause in colour.utilities.tsplit definition is causing some grief.

Transposition is done by flipping some flags in Numpy, thus in the case of 1D and 2D arrays, a different view rather than a copy of the input data is returned. The consequence is that the arrays returned by colour.utilities.tsplit are sometimes non-contiguous and it is causing issues with OCIO.

Another problem, which is arguably worse is that this sometimes causes the data passed to our functions to be modified in-place: Before, colour.utilities.tsplit was always returning a copy of the data, but now this is not always guaranteed . Earlier, as I was checking the unit tests of colour.difference.delta_E_ITP definition, I noticed that we did not have the multi-dimensional test cases. I decided to add them and they did not pass for some really odd reasons. It turns out that [this line] (

) now modifies the input data in-place because of the aforementioned optimisation.

Code for Reproduction

>>> import colour
>>> import numpy as np
>>> ICtCp_1 = np.array([0.4885468072, -0.04739350675, 0.07475401302])
>>> ICtCp_1 = np.tile(ICtCp_1, (6, 1))
>>> I_1, T_1, P_1 =  colour.utilities.tsplit(ICtCp_1)
>>> T_1 *= 0.5
>>> ICtCp_1
array([[0.48854681, -0.02369675, 0.07475401],
       [0.48854681, -0.02369675, 0.07475401],
       [0.48854681, -0.02369675, 0.07475401],
       [0.48854681, -0.02369675, 0.07475401],
       [0.48854681, -0.02369675, 0.07475401],
       [0.48854681, -0.02369675, 0.07475401]])

Expected:

>>> import colour
>>> import numpy as np
>>> ICtCp_1 = np.array([0.4885468072, -0.04739350675, 0.07475401302])
>>> ICtCp_1 = np.tile(ICtCp_1, (6, 1))
>>> I_1, T_1, P_1 =  colour.utilities.tsplit(ICtCp_1)
>>> T_1 *= 0.5
>>> ICtCp_1
array([[0.48854681, -0.04739351, 0.07475401],
       [0.48854681, -0.04739351, 0.07475401],
       [0.48854681, -0.04739351, 0.07475401],
       [0.48854681, -0.04739351, 0.07475401],
       [0.48854681, -0.04739351, 0.07475401],
       [0.48854681, -0.04739351, 0.07475401]])

Exception Message

N/A

Environment Information

===============================================================================
*                                                                             *
*   Interpreter :                                                             *
*       python : 3.13.0 (main, Oct  7 2024, 23:47:22) [Clang 18.1.8 ]         *
*                                                                             *
*   colour-science.org :                                                      *
*       colour : v0.4.6-6-gb669eedf5                                          *
*                                                                             *
*   Runtime :                                                                 *
*       imageio : 2.35.1                                                      *
*       matplotlib : 3.9.2                                                    *
*       networkx : 3.4                                                        *
*       numpy : 2.1.2                                                         *
*       pandas : 2.2.3                                                        *
*       pydot : 3.0.2                                                         *
*       PyOpenColorIO : 2.4.0                                                 *
*       scipy : 1.14.1                                                        *
*       tqdm : 4.66.5                                                         *
*       trimesh : 4.4.9                                                       *
*       xxhash : 3.5.0                                                        *
*                                                                             *
===============================================================================
defaultdict(<class 'dict'>, {'Interpreter': {'python': '3.13.0 (main, Oct  7 2024, 23:47:22) [Clang 18.1.8 ]'}, 'colour-science.org': {'colour': 'v0.4.6-6-gb669eedf5'}, 'Runtime': {'imageio': '2.35.1', 'matplotlib': '3.9.2', 'networkx': '3.4', 'numpy': '2.1.2', 'pandas': '2.2.3', 'pydot': '3.0.2', 'PyOpenColorIO': '2.4.0', 'scipy': '1.14.1', 'tqdm': '4.66.5', 'trimesh': '4.4.9', 'xxhash': '3.5.0'}})
@KelSolaar
Copy link
Member Author

@tjdcs for VIS.

KelSolaar added a commit that referenced this issue Nov 2, 2024
KelSolaar added a commit that referenced this issue Nov 9, 2024
KelSolaar added a commit that referenced this issue Nov 9, 2024
…tilities.tsplit` definition output is contiguous and independent.

References #1309.
@KelSolaar KelSolaar added this to the v0.4.7 milestone Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant