检查 scipy 和 numpy 中的 BLAS 和 LAPACK 库链接

Wil*_*bma 5 python macos numpy scipy openblas

我正在尝试将我的代码(尤其是 scipy.linalg.solve)链接到给定的库,例如 OpenBLAS。

我在虚拟环境中使用 python 3.7.7:

Python 3.7.7 (default, Mar 29 2020, 18:12:06) 
[Clang 11.0.3 (clang-1103.0.32.29)] on darwin
Run Code Online (Sandbox Code Playgroud)

另外值得注意的是,我使用 pip 将 numpy 和 scipy 安装到我的虚拟环境中

pip install numpy
pip install scipy


>>> scipy.__version__
'1.4.1'

>>> numpy.__version__
'1.18.0'

>>> scipy.show_config()
lapack_mkl_info:
    NOT AVAILABLE
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
blas_mkl_info:
    NOT AVAILABLE
blis_info:
    NOT AVAILABLE
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]

>>> numpy.show_config()
lapack_mkl_info:
    NOT AVAILABLE
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
blas_mkl_info:
    NOT AVAILABLE
blis_info:
    NOT AVAILABLE
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
Run Code Online (Sandbox Code Playgroud)

当我做:

$ brew install openblas
Warning: openblas 0.3.9 is already installed and up-to-date
Run Code Online (Sandbox Code Playgroud)

我有 OpenBLAS,我的 scipy/numpy 告诉我它们已链接到它。但是,当我这样做时:

from numpy.distutils.system_info import get_info
info = get_info('blas_opt')
print(info)
Run Code Online (Sandbox Code Playgroud)

然后我得到:

{'extra_compile_args': ['-msse3', '-I/System/Library/Frameworks/vecLib.framework/Headers'], 'extra_link_args': ['-Wl,-framework', '-Wl,Accelerate'], 'define_macros': [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)]}
Run Code Online (Sandbox Code Playgroud)

它仍然尝试使用 Accelerate 库而不是使用 OpenBLAS。

如果我查看 numpy 包中的一些链接:

$ otool -L ~/.virtualenvs/myvenv/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-darwin.so 

/Users/myself/.virtualenvs/myvenv/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-darwin.so:
@loader_path/../.dylibs/libopenblasp-r0.3.7.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)
Run Code Online (Sandbox Code Playgroud)

它确实告诉我它链接到 OpenBLAS。

那么,有人知道这是怎么回事吗?我需要采取什么步骤才能使用 OpenBLAS?