SuiteSparseライブラリ ( SuiteSparse )の一部であるC Cholmodライブラリへの Python インターフェイスを作成しようとしています。
私は Swig を初めて使用するので、これが困難な作業であるかどうかはわかりません。Swig で行われたこのインターフェースへの参照は見つかりませんでした。
コンパイルは問題なく行われます。
これは、swig で生成された「_cholmod.py」ファイルをインポートしようとすると発生するエラーです。
Python 2.7.5+ (default, Feb 27 2014, 19:37:08)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _cholmod
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_cholmod.py", line 99, in <module>
class SuiteSparse_config_struct(_object):
File "_cholmod.py", line 106, in SuiteSparse_config_struct
__swig_setmethods__["malloc_func"] =
__cholmod.SuiteSparse_config_struct_malloc_func_set
NameError: name '_SuiteSparse_config_struct__cholmod' is not defined
この名前はどこで定義されていますか? 拡張機能をインポートしようとする前に、簡単な grep では何も返されません が、インポートしようとすると次のようになります。
grep -R -n _SuiteSparse_config_struct__cholmod *
Binary file _cholmod.pyc matches
私は使用しています:
- SWIG バージョン 3.0.5 g++ でコンパイル [x86_64-unknown-linux-gnu] 設定オプション: +pcre
- SuiteSparse 4.4.3 の cholmod ライブラリ
最小限の例を次に示します。
ファイル setup.py:
from distutils.core import setup, Extension
module1 = Extension('__cholmod',
sources=['cholmod.i'],
libraries=['cholmod', 'suitesparseconfig', 'blas', 'amd'],
library_dirs=['/home/nikolaj/Documents/WORK/Dominique/suitesparse
4.4.1-1_ArchLinux/suitesparse-4.4.1-1-x86_64.pkg/usr/lib/'],
include_dirs=['/home/nikolaj/Documents/WORK/Dominique/suitesparse
4.4.1-1_ArchLinux/suitesparse-4.4.1-1-x86_64.pkg/usr/include/'],
swig_opts=['-I/home/nikolaj/Documents/WORK/Dominique/suitesparse
4.4.1-1_ArchLinux/suitesparse-4.4.1-1-x86_64.pkg/usr/include/'])
setup(name='_cholmod', version='0.1', ext_modules=[module1])
そして、私はそれを次のように呼び出します:
python setup.py build_ext --inplace
ファイル cholmod.i:
/* -*- C -*- */
#ifdef SWIGPYTHON
%module _cholmod
%{
#define SWIG_FILE_WITH_INIT
#include "SuiteSparse_config.h"
#include "cholmod_config.h"
#include "cholmod_core.h"
#include "numpy/arrayobject.h"
%}
%feature("autodoc", "1");
%init %{
import_array();
%}
%include "SuiteSparse_config.h
%include "cholmod_config.h"
%include "cholmod_core.h"
#endif
typedef と C 構造体に問題があると思いますが、チュートリアル、公式ドキュメント、プレゼンテーションを何度も読んだ後、何が欠けているのか本当にわかりません。
ここで誰か助けてくれませんか?どうもありがとう!