SWIG: No typemaps are defined

痴心易碎 提交于 2019-12-05 11:02:43

The problem is that the typemap in numpy.i defines a two argument typemap, and you're trying to apply it to a single argument. This would work if you had parameters int len1, and double* vec1 in your function:

%apply (int DIM1, double* IN_ARRAY1) {(int len, double* H_)}

Rather than writing your own typemap, just use carrays.i.

If you WERE to write a typemap, e.g. to take a tuple of doubles as input, it would look something like:

%typemap(in) double TUPLE[ANY]
{
   ...
}

in which case you would apply it to your function the way you expect.

%apply double TUPLE[3] {double H_[3]}

A good place to start when trying to figure out why you can't use a typemap is to run SWIG with the -tmsearch option. It will tell you what it's looking for when trying to match your function parameters.

This works for me:

for

void get_position(double outarray[3])

use

%apply (double ARGOUT_ARRAY1[ANY]) {(double outarray[3])};

(note [ANY] and [3])

result in

a.get_position()
Out[2]: array([0., 0., 0.])
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!