我一直在将MATLAB代码移植到Python上,经过大量工作后,我发现了一些有用的东西.然而,缺点是Python运行我的代码比MATLAB运行得慢.我知道使用优化的ATLAS库会加快速度,但实际上实现这一点会让我感到困惑.这是发生了什么:
我启动了没有安装BLAS的ipython会话:
import numpy.distutils.system_info as sysinfo
import time
In [11]: sysinfo.get_info('atlas')
Out[11]: {}
timeit( eig(randn(1E2,1E2)) )
100 loops, best of 3: 13.4 ms per loop
Matlab中的相同代码运行速度是原来的两倍
tic,eig(randn(1E2));toc*1000
    6.5650   
我从Ubuntu存储库安装了非优化的ATAS deb.重新启动ipython,现在我得到:
In [2]: sysinfo.get_info('atlas')
 ...
Out[2]: 
{'define_macros': [('ATLAS_INFO', '"\\"3.8.4\\""')],
 'include_dirs': ['/usr/include/atlas'],
 'language': 'f77',
 'libraries': ['lapack', 'f77blas', 'cblas', 'atlas'],
 'library_dirs': ['/usr/lib/atlas-base/atlas', '/usr/lib/atlas-base']}
和测试代码:
In [4]: timeit( eig(randn(1E2,1E2)) )
100 loops, best of 3: 16.8 ms per loop
所以没有更快.如果有任何触摸速度较慢.但我还没有切换到优化的BLAS.我按照这些说明操作:http://danielnouri.org/notes/category/python/我构建库并用这些库覆盖非优化版本.我重新开始ipython但是没有变化:
In [4]: timeit( eig(randn(1E2,1E2)) )
100 loops, best of 3: …