2
我想从使用Cython的BLAS库使用点积,但是当调用编译模块时出现以下跟踪“未定义符号:cblas_ddot”。执行np。 配置 .show()来查看链接库:来自Cython的调用blaotDotot
lapack_info:
libraries = ['lapack', 'lapack']
library_dirs = ['/usr/lib64']
language = f77
lapack_info:
libraries = ['lapack', 'lapack']
library_dirs = ['/usr/lib64']
language = f77
openblas_lapack_info:
NOT AVAILABLE
blas_info:
libraries = ['cblas', 'blas']
library_dirs = ['/usr/lib64']
define_macros = [('HAVE_CBLAS', None)]
language = c
atlas_3_10_blas_threads_info:
NOT AVAILABLE
atlas_threads_info:
NOT AVAILABLE
atlas_3_10_threads_info:
NOT AVAILABLE
atlas_blas_info:
NOT AVAILABLE
atlas_3_10_blas_info:
NOT AVAILABLE
atlas_blas_threads_info:
NOT AVAILABLE
openblas_info:
NOT AVAILABLE
blas_mkl_info:
NOT AVAILABLE
blas_opt_info:
libraries = ['cblas', 'blas']
library_dirs = ['/usr/lib64']
language = c
define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]
blis_info:
NOT AVAILABLE
atlas_info:
NOT AVAILABLE
atlas_3_10_info:
NOT AVAILABLE
lapack_mkl_info:
NOT AVAILABLE
和LDD /usr/lib/python2.7/site-packages/numpy/core/multiarray.so和的readlink -e在/ usr/lib/libblas.so.3显示: /usr/lib/libblas.so.3.7.0
显然,BLAS库已链接,但未找到cblas_ddot。该PYX文件:
import numpy as np
cimport numpy as np
cdef extern from "cblas.h":
double ddot "cblas_ddot"(int N,
double *X, int incX,
double *Y, int incY)
ctypedef np.float64_t dtype_t
def matmul(np.ndarray[dtype_t, ndim=2] A,
np.ndarray[dtype_t, ndim=2] B):
cdef Py_ssize_t i, j
cdef np.ndarray[dtype_t,ndim=2] out = np.zeros((A.shape[0],B.shape[1]))
cdef np.ndarray[dtype_t, ndim=1] A_row, B_col
for i in range(A.shape[0]):
A_row = A[i,:]
for j in range(B.shape[1]):
B_col = B[:, j]
out[i,j] = ddot(
A_row.shape[0],
<dtype_t*>A_row.data,
A_row.strides[0] // sizeof(dtype_t),
<dtype_t*>B_col.data,
B_col.strides[0] // sizeof(dtype_t))
的编译文件看起来像: 进口numpy的
if __name__ == '__main__':
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
# The Cython modules to setup
ext_modules = [
Extension('matmul', ['matmul.pyx'], include_dirs=
[numpy.get_include()])
]
# Run the setup command
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
你能展示你如何编译它吗? – DavidW
是的,先生,帖子是用编译命令更新的 –