ID 583396 - setArray in BlinkScript returns the wrong result

Follow

Problem summary
setArray in BlinkScript returns the wrong result.

NOTE: This is expected behaviour as invert() and transpose() were the only two matrix functions that did not perform their operations "in place", meaning that they apply the change to the object the method is called on. In 15.1, this was updated so that these two methods now match all the other matrix functions to provide consistency:
https://learn.foundry.com/nuke/developers/15.1/BlinkUserGuide/BlinkKernelAPIReference/Types.html#matrix-transformation-rotation-and-translation-methods 
 
Customer reported version
Nuke 15.1v1
 
Customer reported platform
Windows 11
 
Steps to reproduce
 
1) Open Nuke.
 
2) Create a CheckerBoard node.
 
3) Create a BlinkScript node downstream of the CheckerBoard.
 
4) Add the following code to the BlinkScript's Kernel Source and press Recompile:
kernel Test_Kernel : ImageComputationKernel<ePixelWise>{  Image<eRead, eAccessPoint, eEdgeClamped> src; // the input image  Image<eWrite>                            dst; // the output imagelocal:  float3x3 XYZ_to_RGB;  float3x3 RGB_to_XYZ;  void init()  {    float XYZ_to_AP1_ACES_matrix_data[]=    {       1.6410233797f, -0.3248032942f, -0.2364246952f,      -0.6636628587f,  1.6153315917f,  0.0167563477f,       0.0117218943f, -0.0082844420f,  0.9883948585f,    };    XYZ_to_RGB.setArray(XYZ_to_AP1_ACES_matrix_data);    RGB_to_XYZ = XYZ_to_RGB.invert();  }  float3 vector_dot(float3x3 m, float3 v)  {    float3 r;    r[0] = m[0][0] * v[0] + m[0][1] * v[1] + m[0][2] * v[2];    r[1] = m[1][0] * v[0] + m[1][1] * v[1] + m[1][2] * v[2];    r[2] = m[2][0] * v[0] + m[2][1] * v[1] + m[2][2] * v[2];    return r;  }  void process()  {    SampleType(src) source = src();    float3 input(source.x, source.y, source.z);    float3 out = input;    debugPrint(&XYZ_to_RGB[0][0], 1, 1);    debugPrint(&XYZ_to_RGB[0][1], 1, 1);    debugPrint(&XYZ_to_RGB[0][2], 1, 1);    debugPrint(&XYZ_to_RGB[1][0], 1, 1);    debugPrint(&XYZ_to_RGB[1][1], 1, 1);    debugPrint(&XYZ_to_RGB[1][2], 1, 1);    debugPrint(&XYZ_to_RGB[2][0], 1, 1);    debugPrint(&XYZ_to_RGB[2][1], 1, 1);    debugPrint(&XYZ_to_RGB[2][2], 1, 1);    debugPrint(&RGB_to_XYZ[0][0], 1, 1);    debugPrint(&RGB_to_XYZ[0][1], 1, 1);    debugPrint(&RGB_to_XYZ[0][2], 1, 1);    debugPrint(&RGB_to_XYZ[1][0], 1, 1);    debugPrint(&RGB_to_XYZ[1][1], 1, 1);    debugPrint(&RGB_to_XYZ[1][2], 1, 1);    debugPrint(&RGB_to_XYZ[2][0], 1, 1);    debugPrint(&RGB_to_XYZ[2][1], 1, 1);    debugPrint(&RGB_to_XYZ[2][2], 1, 1);//    out = vector_dot(RGB_to_XYZ, out);    out = vector_dot(XYZ_to_RGB, out);    dst() = float4(out.x, out.y, out.z, source.w);  }};
 
5) Look at what is printed in your command line window.
 
Expected behaviour
The matrix should be printed to command line like so:
&XYZ_to_RGB._data[0 * 3 + 0] = 1.641023 &XYZ_to_RGB._data[0 * 3 + 1] = -0.324803 &XYZ_to_RGB._data[0 * 3 + 2] = -0.236425 &XYZ_to_RGB._data[1 * 3 + 0] = -0.663663 &XYZ_to_RGB._data[1 * 3 + 1] = 1.615332 &XYZ_to_RGB._data[1 * 3 + 2] = 0.016756 &XYZ_to_RGB._data[2 * 3 + 0] = 0.011722 &XYZ_to_RGB._data[2 * 3 + 1] = -0.008284 &XYZ_to_RGB._data[2 * 3 + 2] = 0.988395
 
Actual behaviour
The following is printed to the terminal, which is the same as the inverse of the matrix data: 
&XYZ_to_RGB._data[0 * 3 + 0] = 0.662454&XYZ_to_RGB._data[0 * 3 + 1] = 0.134004&XYZ_to_RGB._data[0 * 3 + 2] = 0.156188&XYZ_to_RGB._data[1 * 3 + 0] = 0.272229&XYZ_to_RGB._data[1 * 3 + 1] = 0.674082&XYZ_to_RGB._data[1 * 3 + 2] = 0.053690&XYZ_to_RGB._data[2 * 3 + 0] = -0.005575&XYZ_to_RGB._data[2 * 3 + 1] = 0.004061&XYZ_to_RGB._data[2 * 3 + 2] = 1.010339
 
Workaround
In this example, you should get the results you are expecting by changing the init function to the following:
void init()  {    float XYZ_to_AP1_ACES_matrix_data[]=    {       1.6410233797f, -0.3248032942f, -0.2364246952f,      -0.6636628587f,  1.6153315917f,  0.0167563477f,       0.0117218943f, -0.0082844420f,  0.9883948585f,    };    XYZ_to_RGB.setArray(XYZ_to_AP1_ACES_matrix_data);    RGB_to_XYZ = XYZ_to_RGB;    RGB_to_XYZ.invert();  }

 
Reproduced by support
This bug has been reproduced in:
Nuke 15.1v2 - Windows 11 - macOS 12
Nuke 15.1v1 - Windows 11 - macOS 12 - REGRESSION
 
Unable to reproduce bug in:
Nuke 15.0v5 - Windows 11 - macOS 12
 
Earliest version tested
Nuke 15.0v4
- This issue doesn't appear in this version and has regressed
 

    We're sorry to hear that

    Please tell us why