I'm wanting to wrap some c++ code in python using swig, and I need to be able to use numpy.i to convert numpy arrays to vectors.
This has been quite the frustrating process, as I haven't been able to find any useful info online as to where I actually get numpy.i from.
This is what I currently have running:
numpy 1.17.3
swig 2.0.12
python 3.7.3
Debian 4.9.2
From reading https://docs.scipy.org/doc/numpy/reference/swig.interface-file.html I'm told that numpy.i should be located in tools/swig/numpy.i, though the only place on my machine that I can find numpy.i is in a python 2.7 folder which I've upgraded from. My working version of python (3.7.3) holds no such file.
$ locate numpy.i
/usr/lib/python2.7/dist-packages/instant/swig/numpy.i
What I've tried:
copying the numpy.i (as described above) into my working folder. This is at least recognized by my test.i file when I call %include "numpy.i", but it doesn't seem to allow usage of numpy.i calls.
Copying this code https://github.com/numpy/numpy/blob/master/tools/swig/numpy.i into a new file called numpy.i and putting that in my folder, but I get lots of errors when I try to run it.
Is there a standard way to get the proper numpy.i version? Where would I download it from, and where should I put it?
I've included some code below as reference:
test.i:
%module test
%{
#define SWIG_FILE_WITH_INIT
#include "test.h"
%}
%include "numpy.i" //this doesn't seem to do anything
%init %{
import_array();
%}
%apply (int DIM1) {(char x)}; //this doesn't seem to do anything
%include "test.h"
test.h:
#include <iostream>
void char_print(char x);
test.cpp:
#include "test.h"
void char_print(char x) {
std::cout << x << std::endl;
return;
}
tester.py:
import test
test.char_print(5) #nothing is printed, since this isn't converted properly to a char.
This is just a simple example, but I've tried using numpy.i in many different ways (including copying and pasting other people's code that works for them) but it consistently doesn't change anything whether I have it in my test.i file or not.
Where/how do I get numpy.i?