我一直在将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中相同的代码运行速度是原来的两倍
^{pr2}$
我从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: 15.3 ms per loop
就不能比这更好吗?在这个简单的例子中,MATLAB的速度仍然是原来的两倍。在一个真实的例子中,我在Fourier域中进行图像注册,Matlab的等价物比Python版本快4到5倍。有人设法让纽比以MATLAB的速度工作吗?在