I'm developing a module for using c inline
in Python code based on swig
.
For that I would like to make numpy
arrays accessible in C
. Until now I used C types like unsigned short
but I would like to use types like uint16_t
from stdint.h
to be save whatever compiler my module encounters.
Unfortunately the c++
-functions do not get wrapped correctly when using stdint.h
types. The Error given is: _setc() takes exactly 2 arguments (1 given)
. That means, the function is not wrapped to accept numpy
arrays. The error does not occur, when I use e.g. unsigned short
.
Do you have any ideas, how I can make swig map numpy
arrays into stdint-types
?
interface.i
NOT working:
/* 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++
function NOT working:
#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
working:
/* 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++
function working:
#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;
}