Reputation: 4266
In Python's numerical library NumPy, how does the numpy.dot
function deal with arrays of different memory-order? numpy.dot(c-order, f-order)
vs. dot(f-order, c-order)
etc.
The reason I ask is that long time ago (numpy 1.0.4?), I made some tests and noticed numpy.dot
performed worse than calling dgemm
from scipy.linalg
directly, with the correct transposition flags, though both call the same BLAS library internally. (I suspected the reason was copying of the input matrices inside numpy.dot
, which is tragic if the input is large.)
Now I tried again and actually numpy.dot
performs the same as dgemm
, so there is no reason to keep the arrays in specific order and set transposition flags manually. Much cleaner code.
So my question is, how does a recent (let's say 1.6.0) numpy.dot
work, guarantees on when things are copied and when not? I'm concerned about 1) memory 2) performance here. Cheers.
Upvotes: 15
Views: 1606
Reputation: 362617
Possibly what you were seeing may have been related to a blas-optimized dot import error being caught and handled silently (this code snippet is from numeric.py)
# try to import blas optimized dot if available
try:
# importing this changes the dot function for basic 4 types
# to blas-optimized versions.
from _dotblas import dot, vdot, inner, alterdot, restoredot
except ImportError:
# docstrings are in add_newdocs.py
inner = multiarray.inner
dot = multiarray.dot
Upvotes: 1