我正在开发一个基于c inline的swig代码中使用swig的模块。为此,我想让numpy数组可以在C中访问。到目前为止,我使用了像unsigned short这样的C类型,但是我希望使用来自stdint.h的uint16_t类型来保存模块遇到的任何编译器。
不幸的是,c++-functions在使用stdint.h类型时没有正确包装。给出的错误是:_setc() takes exactly 2 arguments (1 given)。这意味着,函数不是包装成接受numpy数组的。当我使用例如unsigned short时,错误不会发生。
你有什么想法吗,我怎样才能把numpy数组变成stdint-types
interface.i不工作:
/* interface.i */
extern int __g();
%}
%include "stdint.i"
%include "numpy.i"
%init %{
import_array();
%}
%apply (uint16_t* INPLACE_ARRAY3, int DIM1) {(uint16_t* seq, int n1)};
extern int __g();c++功能不起作用:
#include "Python.h"
#include <stdio.h>
#include <stdint.h>
extern uint16_t* c;
extern int Dc;
extern int Nc[4];
void _setc(uint16_t *seq, int n1, int n2, int n3)
{
c = seq;
Nc[0] = n1;
Nc[1] = n2;
Nc[2] = n3;
}interface.i工作:
/* interface.i */
extern int __g();
%}
%include "stdint.i"
%include "numpy.i"
%init %{
import_array();
%}
%apply (unsigned short* INPLACE_ARRAY3, int DIM1) {(unsigned short* seq, int n1)};
extern int __g();c++函数工作:
#include "Python.h"
#include <stdio.h>
#include <stdint.h>
extern unsigned short* c;
extern int Dc;
extern int Nc[4];
void _setc(unsigned short *seq, int n1, int n2, int n3)
{
c = seq;
Nc[0] = n1;
Nc[1] = n2;
Nc[2] = n3;
}发布于 2015-12-16 15:39:00
哈哈,就在我放弃发表这个问题的几分钟后,我找到了一些“解决办法”。
我编辑了numpy.i以适应我的需要:我在第3044 ff行中用stdint.h类型替换了旧的stdint.h类型:
[..]
/* Concrete instances of the %numpy_typemaps() macro: Each invocation
* below applies all of the typemaps above to the specified data type.
*/
%numpy_typemaps(int8_t , NPY_BYTE , int)
%numpy_typemaps(uint8_t , NPY_UBYTE , int)
%numpy_typemaps(int16_t , NPY_SHORT , int)
%numpy_typemaps(uint16_t , NPY_USHORT , int)
%numpy_typemaps(int32_t , NPY_INT , int)
%numpy_typemaps(uint32_t , NPY_UINT , int)
%numpy_typemaps(long , NPY_LONG , int)
%numpy_typemaps(unsigned long , NPY_ULONG , int)
%numpy_typemaps(int64_t , NPY_LONGLONG , int)
%numpy_typemaps(uint64_t, NPY_ULONGLONG, int)
%numpy_typemaps(float , NPY_FLOAT , int)
%numpy_typemaps(double , NPY_DOUBLE , int)
[..]我想知道是否有比编辑numpy.i更好的主意
欢呼声乔晨
https://stackoverflow.com/questions/34315791
复制相似问题