Feature: einsum
xtipacko opened this issue · comments
Good day!
Could you please Implement something like numpy.einsum (for OpenCL and CUDA)?
In particular, I'm interested in row/column-wise outer product, like this, but einsum is very universal and useful thing...
A = np.random.randint(1,7, size=(3,2))
B = np.random.randint(1,7, size=(2,3))
X = np.einsum('ik,kj->kij', A,B)
X
array([[[ 8, 16, 12],
[ 8, 16, 12],
[ 4, 8, 6]],
[[15, 3, 12],
[ 5, 1, 4],
[ 5, 1, 4]]])
That would be amazing! Or alternatively (and arguably simpler than parsing a small expression DSL like einsum does) a tensordot
function that allows summing an arbitrary number of dimensions would provide all the same functionality. FWIW, I am working on autodiff of tensor valued functions for an ML application; in general, derivatives of matrix valued functions can't be expressed only in terms of matrix multiplications efficiently.