【发布时间】:2015-12-16 15:23:19
【问题描述】:
我正在开发一个基于swig 在Python 代码中使用c inline 的模块。
为此,我想让numpy 数组可以在C 中访问。到目前为止,我使用像 unsigned short 这样的 C 类型,但我想使用像 stdint.h 中的 uint16_t 这样的类型来保存我的模块遇到的任何编译器。
不幸的是,c++-函数在使用 stdint.htypes 时没有正确包装。给出的错误是:_setc() takes exactly 2 arguments (1 given)。这意味着,该函数未包装以接受 numpy 数组。当我使用例如错误不会发生unsigned short.
您有什么想法,我如何将 swig 映射 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;
}
【问题讨论】:
标签: python c++ numpy swig stdint