LAPACK
Cython拡張機能と使用法(および)を含むPythonモジュールを作成していますBLAS
。clapack
必要に応じて、または、またはlapacke
何らかのソリューションを使用することもできます。重要なのは、Python呼び出しのオーバーヘッドなしに、タイトなループでCythonからルーチンを呼び出すことができるということです。f2c
f2py
lapack
blas
ここで1つの例を見つけました。ただし、その例はSAGEに依存します。私のユーザーは他の目的でSAGEを必要としない可能性が高いため、SAGEをインストールせずにモジュールをインストールできるようにしたいと思います。私のユーザーは、numpy、scipy、pandas、scikit learnなどのパッケージをインストールしている可能性が高いため、これらは妥当な依存関係になります。使用するインターフェースの最適な組み合わせは何ですか?また、コンパイルに必要な情報(numpy、scipyなどから)をフェッチできる最小のsetup.pyファイルはどのようになりますか?
編集: これが私がやったことです。それは私のMacBookで動作しますが、それがどれほどポータブルかはわかりません。確かにもっと良い方法があります。
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy
from Cython.Build import cythonize
from numpy.distutils.system_info import get_info
# TODO: This cannot be the right way
blas_include = get_info('blas_opt')['extra_compile_args'][1][2:]
includes = [blas_include,numpy.get_include()]
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = cythonize([Extension("cylapack", ["cylapack.pyx"],
include_dirs = includes,
libraries=['blas','lapack'])
])
)
私のMacBookでは、clapack.h
ヘッダーファイルがと同じディレクトリにあるため、これは機能しますcblas.h
。次に、pyxファイルでこれを行うことができます。
ctypedef np.int32_t integer
cdef extern from "cblas.h":
double cblas_dnrm2(int N,double *X, int incX)
cdef extern from "clapack.h":
integer dgelsy_(integer *m, integer *n, integer *nrhs,
double *a, integer *lda, double *b, integer *ldb, integer *
jpvt, double *rcond, integer *rank, double *work, integer *
lwork, integer *info)