简体   繁体   English

`numpy.dot`中的数组顺序

[英]Array order in `numpy.dot`

In Python's numerical library NumPy , how does the numpy.dot function deal with arrays of different memory-order? 在Python的数值库NumPy中numpy.dot函数如何处理不同内存顺序的数组? numpy.dot(c-order, f-order) vs. dot(f-order, c-order) etc. numpy.dot(c-order, f-order)dot(f-order, c-order)等。

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. 我问的原因是很久以前(numpy 1.0.4?),我做了一些测试,并注意到numpy.dot表现比直接从scipy.linalg调用dgemm更糟,带有正确的换位标志,尽管它们都调用相同的BLAS库内部。 (I suspected the reason was copying of the input matrices inside numpy.dot , which is tragic if the input is large.) (我怀疑原因是在numpy.dot复制输入矩阵,如果输入很大,这是很悲惨的。)

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. 现在我再次尝试并且实际上numpy.dot执行与dgemm相同的dgemm ,因此没有理由按特定顺序保持数组并手动设置转置标志。 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? 所以我的问题是,最近(让我们说1.6.0) numpy.dot工作,保证什么时候复制,什么时候不复制? I'm concerned about 1) memory 2) performance here. 我关心的是1)记忆2)这里的表现。 Cheers. 干杯。

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) 您可能看到的可能是与静默捕获和处理的blas优化点导入错误相关(此代码段来自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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM