[SciPy-dev] matrixmultiply!=dot when dotblas is present
Fernando Perez
Fernando.Perez at colorado.edu
Tue Sep 28 14:36:19 CDT 2004
Hi all,
I just reported a Numpy bug to the numpy list, but scipy can work around it
trivially. The problem is the following (I'm copy/pasting my original msg):
I found something today a bit unpleasant: if you install numeric without
any BLAS support, 'matrixmultiply is dot==True', so they are fully
interchangeable. However, to my surprise, if you build numeric with the blas
optimizations, they are NOT identical. The reason is a bug in Numeric.py.
After they define dot, they do this:
#This is obsolete, don't use in new code
matrixmultiply = dot
and at the very end of the file, they do:
# try to import blas optimized dot, innerproduct and vdot, if available
try:
from dotblas import dot, innerproduct, vdot
except ImportError: pass
Obviously this means that matrixmultiply is stuck with the _old_ definition of
dot, and does not benefit from the blas optimizations. This is BAD, as for a
1024x1024 matrix the difference is staggering:
planck[Numeric]> pylab
In [1]: a=rand(1024,1024)
In [2]: b=rand(1024,1024)
In [3]: from IPython.genutils import timing
In [4]: timing 1,dot,a,b
------> timing(1,dot,a,b)
Out[4]: 0.55591500000000005
In [5]: timing 1,matrixmultiply,a,b
------> timing(1,matrixmultiply,a,b)
Out[5]: 68.142640999999998
In [6]: _/__
Out[6]: 122.57744619231356
Pretty significant difference, eh? :)
Scipy can work around this problem (which is still there in Numpy 23.4) by
manually doing 'matrixmultiply=dot' AFTER dot has been imported from Numeric.
This will guarantee that users of scipy.matrixmultiply() actually get the
fast version.
Cheers,
f
More information about the Scipy-dev
mailing list