Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Several numpy arrays with SWIG

I am using SWIG to pass numpy arrays from Python to C++ code:

%include "numpy.i"
%init %{
import_array();
%}

%apply (float* INPLACE_ARRAY1, int DIM1) {(float* data, int n)};

class Class 
{
  public: 
  void test(float* data, int n)
  {
    //...
  }
};

and in Python:

c = Class()
a = zeros(5)
c.test(a)

This works, but how can I pass multiple numpy arrays to the same function?

like image 331
Petter Avatar asked Jan 23 '23 05:01

Petter


1 Answers

I found out the answer from a collegue of mine:

%apply (float* INPLACE_ARRAY1, int DIM1) {(float* data1, int n1), (float* data2, int n2)};

class Class 
{
  public: 
  void test(float* data1, int n1, float* data2, int n2)
  {
    //...
  }
};

Now two numpy arrays are passed to Class::test.

like image 95
Petter Avatar answered Jan 31 '23 05:01

Petter