SWIG-python的numpy参数传入C函数
简介
由于python需要调用c语言写的函数,且最好直接传入numpy的矩阵。
经查询,numpy直接提供一个numpy.i(swig配置格式)的文件供swig使用,可以将numpy格式转换成C可用的数组格式。
- numpy获取地址:https://github.com/numpy/numpy
- numpy.i在目录中位置:numpy/tools/swig
- numpy在 ubuntu 上安装: apt-get install python-numpy
我的程序如下:
setup.py:
#!/usr/bin/python
from distutils.core import setup, Extension
convolutionquantized_3x3_test_module =
Extension('_convolutionquantized_3x3_test',
library_dirs=['./'],
libraries=['ncnn'],
sources=['convolutionquantized_3x3_test_wrap.cxx'] )
setup (name = 'convolutionquantized_3x3_test',
version = '0.1',
author = "lb",
description = """for test""",
ext_modules = [convolutionquantized_3x3_test_module],
py_modules = ["convolutionquantized_3x3_test"],)
runme.py: