我正在构建基于 blas 和 lapack 的 numpy/scipy 环境,或多或少基于此演练。
完成后,如何检查我的 numpy/scipy 函数是否确实使用了先前构建的 blas/lapack 功能?
该方法numpy.show_config()
(或numpy.__config__.show()
)输出有关在构建时收集的链接的信息。我的输出看起来像这样。我认为这意味着我正在使用 Mac OS 附带的 BLAS/LAPACK。
>>> import numpy as np
>>> np.show_config()
lapack_opt_info:
extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
extra_compile_args = ['-msse3']
define_macros = [('NO_ATLAS_INFO', 3)]
blas_opt_info:
extra_link_args = ['-Wl,-framework', '-Wl,Accelerate']
extra_compile_args = ['-msse3', '-I/System/Library/Frameworks/vecLib.framework/Headers']
define_macros = [('NO_ATLAS_INFO', 3)]
您正在搜索的是: 系统信息
我用 atlas 编译了 numpy/scipy,我可以通过以下方式检查:
import numpy.distutils.system_info as sysinfo
sysinfo.get_info('atlas')
查看文档以获取更多命令。
您可以使用链接加载器依赖工具查看构建的 C 级挂钩组件,并查看它们是否对您选择的 blas 和 lapack 有外部依赖。我现在不在 linux 机器附近,但是在 OS X 机器上,您可以在包含安装的 site-packages 目录中执行此操作:
$ otool -L numpy/core/_dotblas.so
numpy/core/_dotblas.so:
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
/System/Library/Frameworks/vecLib.framework/Versions/A/vecLib (compatibility version 1.0.0, current version 268.0.1)
$ otool -L scipy/linalg/flapack.so
scipy/linalg/flapack.so (architecture i386):
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/local/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
/System/Library/Frameworks/vecLib.framework/Versions/A/vecLib (compatibility version 1.0.0, current version 242.0.0)
scipy/linalg/flapack.so (architecture ppc):
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/local/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
$ otool -L scipy/linalg/fblas.so
scipy/linalg/fblas.so (architecture i386):
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/local/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
/System/Library/Frameworks/vecLib.framework/Versions/A/vecLib (compatibility version 1.0.0, current version 242.0.0)
scipy/linalg/fblas.so (architecture ppc):
/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
/usr/local/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
代替gnu/Linux 系统ldd
,otool
你应该得到你需要的答案。
您可以使用以下方式显示 BLAS、LAPACK、MKL 链接show_config()
:
import numpy as np
np.show_config()
这对我来说给出了输出:
mkl_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/my/environment/path/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/my/environment/path/include']
blas_mkl_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/my/environment/path/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/my/environment/path/include']
blas_opt_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/my/environment/path/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/my/environment/path/include']
lapack_mkl_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/my/environment/path/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/my/environment/path/include']
lapack_opt_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/my/environment/path/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/my/environment/path/include']
如果您安装了 anaconda-navigator(在 www.anaconda.com/anaconda/install/ 上适用于 linux、Windows 或 macOS) - blas、scipy 和 numpy 都将被安装,您可以通过单击导航器主页左侧的环境选项卡来查看它们页面(按 alpha 顺序查找每个目录)。安装完整的 anaconda(相对于 miniconda 或单个软件包)将负责安装数据科学所需的许多基本软件包。