0

I recently switched from numpy compiled with open blas to numpy compiled with mkl. In pure numeric operations there was a clear speed up for matrix multiplication. However when I ran some code I have been using which multiplies matrices containing sympy variables, I now get the error

'Object arrays are not currently supported'

Does anyone have information on why this is the case for mkl and not for open blas?

shaun252
  • 61
  • 4
  • Matrix multiplications using MKL only works on Float arrays in single (np.float32,np.complex64) or double precision (np.float64,np.complex128). All other are not supported by MKL, but there are C/Cython implementations in Numpy which work with some other dtypes too. (but quite a lot slower) https://software.intel.com/en-us/mkl-developer-reference-c-cblas-gemm – max9111 Apr 14 '20 at 16:12

1 Answers1

1

Release notes for 1.17.0

Support of object arrays in matmul
It is now possible to use matmul (or the @ operator) with object arrays. For instance, it is now possible to do:

from fractions import Fraction
a = np.array([[Fraction(1, 2), Fraction(1, 3)], [Fraction(1, 3), Fraction(1, 2)]])
b = a @ a

Are you using @ (matmul or dot)? A numpy array containing sympy objects will be object dtype. Math on object arrays depends on delegating the action to the object's own methods. It cannot be performed by the fast compiled libraries, which only work with c types such as float and double.

As a general rule you should not be trying to mix numpy and sympy. Math is hit-or-miss, and never fast. Use sympy's own Matrix module, or lambdify the sympy expressions for numeric work.

What's the mkl version? You may have to explore this with creator of that compilation.

hpaulj
  • 221,503
  • 14
  • 230
  • 353
  • I was using @. I think I compared timings using the sympy matrix module vs numpy @ and found @ faster for this particular use when I originally wrote the code. https://pypi.org/project/intel-numpy/#files was what I was using. I guess the numpy version is just too old. – shaun252 Apr 12 '20 at 22:50