4 ms·
"It is slow and uses a lot of memory, but it only requires operations that are implemented for many array types(...)" Would @einsum c[i,j] = a[i,k] * b[k,j]
by savant_penguin 7y ago
"It is slow and uses a lot of memory, but it only requires operations that are implemented for many array types(...)"
Would
@einsum c[i,j] = a[i,k] * b[k,j]
be slower than direct matrix multiplication?
- eigenspace 7y agoDepends on the implementation of `@einsum`. If the macro is implemented well, that’ll actually just lower to a matrix multiplication call and you’ll have zero runtime overhead. Otherwise, you might end up lowering to a naïve for loop which would be significantly slower. TensorCast.jl and TensorOperations.jl know how to make matrix multiplication calls but currently Einsum isn't that smart. Macros are just syntax transformations.
- under-Peter 7y agoHeya, for standard arrays that are small, the einsum-macro from Einsum.jl can be faster than BLAS. Einsum.jl translates the code simply into three loops and if cache-access patterns (presumably what most of BLAS optimisation is concerned with) isn't an issue, the for-loops are very fast. A quick check shows that for a simple matrix multiplication, Einsum is faster for 5x5 matrices but slower for 10x10. (This is ignoring the compilation-time that calling a julia function for the first time incurs)