首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用stdint和using和numpy.i

使用stdint和using和numpy.i
EN

Stack Overflow用户
提问于 2015-12-16 15:23:19
回答 1查看 1.2K关注 0票数 3

我正在开发一个基于c inlineswig代码中使用swig的模块。为此,我想让numpy数组可以在C中访问。到目前为止,我使用了像unsigned short这样的C类型,但是我希望使用来自stdint.huint16_t类型来保存模块遇到的任何编译器。

不幸的是,c++-functions在使用stdint.h类型时没有正确包装。给出的错误是:_setc() takes exactly 2 arguments (1 given)。这意味着,函数不是包装成接受numpy数组的。当我使用例如unsigned short时,错误不会发生。

你有什么想法吗,我怎样才能把numpy数组变成stdint-types

interface.i不工作:

代码语言:javascript
复制
/* 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++功能不起作用:

代码语言:javascript
复制
#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工作:

代码语言:javascript
复制
/* 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++函数工作:

代码语言:javascript
复制
#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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-16 15:39:00

哈哈,就在我放弃发表这个问题的几分钟后,我找到了一些“解决办法”。

我编辑了numpy.i以适应我的需要:我在第3044 ff行中用stdint.h类型替换了旧的stdint.h类型:

代码语言:javascript
复制
[..]
/* 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更好的主意

欢呼声乔晨

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34315791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档