我正在开发一个模块来使用c inline
在Python代码中基于swig
。
为此我想做numpy
数组可访问于C
。到目前为止我使用的 C 类型如下unsigned short
但我想使用类似的类型uint16_t
from stdint.h
保存我的模块遇到的任何编译器。
不幸的是c++
- 使用时函数无法正确包装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;
}