awkward
awkward copied to clipboard
Matrix multiplication (@ operator) is broken and needs to be ported to kernels (out of Numba)
Version of Awkward Array
1.7.0
Description and code to reproduce
While trying to use awkward arrays in matrix multiplication, I ran into two different kinds of unexpected behavior. The following code shows an example.
import awkward as ak
import numpy as np
v = np.asarray([1,2,3])
A = np.asarray([[1,0,0],[0,1,0],[0,0,1]])
vT1 = np.asarray([[1],[2],[3]])
vT2 = np.asarray([1,2,3])
print(v @ A @ vT1) # [14]
print(v @ A @ vT2) # 14
v = ak.Array([1,2,3])
A = ak.Array([[1,0,0],[0,1,0],[0,0,1]])
vT1 = ak.Array([[1],[2],[3]])
vT2 = ak.Array([1,2,3])
print(v @ A @ vT1) # output [[a], [b], [c]], different values for a, b, c each time
print(v @ A @ vT2) # ValueError: in ListOffsetArray64 attempting to get 3, stops[i] > len(content)
In the first case with vT1
, uninitialized data seems to be accessed, leading to different outputs every time. The output shape also changes when compared to the numpy
approach. I naively expected the second case with vT2
to also work, and to report the same result as numpy
. I believe the different treatment for this may be on purpose and a design choice, but wanted to include it here as well to be sure this is expected.
I made #1324 and mentioned @lukasheinrich in it, but that's a duplicate of this one, so I'll close that and prioritize this.
This is harder than we thought and should be deferred beyond the next release.
np.matmul
on Awkward Arrays should raise NotImplementedError
for now.