Possible bug in in numpy_interface.algorithms.matmul?

Hello!!!

I’m using VTK 9.4 with Python 3.12

I’m trying to use the numpy_interface.algorithms.matmul method on a vtkCompositeDataArray and finding that it’s not doing what I expect.

IMO, there’s either an error in matmul or I’m misunderatding the intention of the function

My vtkCompositeDataArray is an array of point coordinates - so each array in the composite is an n*3 float array and I want to multiply each 3 tuple in every array by a 3x3 matrix.

Currently the method fails with a broadcast error fro the underlying einsum method that implements matmul.

If I look at the implementation of matmul in internal_algorithms.py I see that for each array in the composite (assuming the arrays are nx3) it’s constructing einsum subscripts ‘..j,..j’ which will never give me matrix mutiply.

If I change the subscrpts to ‘ij,jk->ik’ all is well

So my question is whether or not this is a bug or if I’m misunderstanding the intent?

According to this, to do a matrix multiplication with NumPy’s einsum(), the call would be indeed np.einsum("ij, jk -> ik", A, B) supposing A is nx3 and B is 3x3. Notice the two ‘k’ trailing, not following the usual matrix multiplication notation. I guess that was a coding mistake that went unnoticed/not tested.