我没办法让斯威格明白,(int len,double*ivec)实际上应该是(int,数字阵列),而不是一个numpy数组?,尽管我使用了numpy.i打印地图。我尝试了以下方法:
/* test3.cpp */
#include <cstring>
#include <iostream>
#include <cmath>
void abel(int len1, double* ivec, int len2, double* ovec)
{
std::cout << "Hello" << std::endl;
return;
}
以及
^{pr2}$ <> >我将C++类型<强>(int大小,双*IVEC)< /St> > NoMy.I类型映射>强>(int DIM1,双* INPATION ARARY1)> Suthe,如ScPy DOC/*test3.i*/
%module Amod
%{
#define SWIG_FILE_WITH_INIT
#include "test3.h"
%}
%include "numpy.i"
%init %{
import_array();
%}
%apply (int DIM1, double* INPLACE_ARRAY1) {(int len1, double* ivec), (int len2, double* ovec)};
%include "test3.h"
我在文档中编译解释:
swig -c++ -python test3.i
g++ -fPIC -c test3.cpp
g++ -fPIC -c test3_wrap.cxx -I/usr/include/python2.7
g++ -shared test3.o test3_wrap.o -o _Amod.so
我可以在python中导入Amod,但是:
>>>import Amod as ab
>>>import numpy as np
>>>a = np.array([1.0,2.0,3.0])
>>>ab.abel()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: abel() takes exactly 2 arguments (0 given)
>>>ab.abel(a,a)
Hello
>>>ab.abel(3,a,3,a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: abel() takes exactly 2 arguments (4 given)
怎么了?为什么整数arg消失了?我觉得我错过了一些重要的事情。在
非常感谢,对于这个问题,我尽量减少代码。我是新来的,请告诉我如何激活颜色代码,使其更具可读性。在
目前没有回答
相关问题 更多 >
编程相关推荐