forked from ge25duq/gofmm_swig_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.i
executable file
·46 lines (35 loc) · 1.54 KB
/
tools.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// "tools.i"
%module tools
// Must include these two lib files before .cpp so that .cpp can see
// the types
%include "stdint.i" // Included to use uint64_t
%include <std_string.i> // Included to use std::string
/* Initialize the swig and c++ interface: can only be done once */
%{
#define SWIG_FILE_WITH_INIT
#include "../example/test_gofmm.cpp"
%}
/* Use numpy array: this section must be placed before .cpp include */
%include "numpy.i"
%init %{
import_array();
%}
// Typemap: the order and names of the parameteres must match exactly
// the function args in the cpp file. `\` is the line separator
%apply (float* IN_ARRAY2, int DIM1, int DIM2 ) \ // IN_ARRAY2: Input 2D
{(float* numpy_matrix, int num_of_rows, int num_of_cols)}
// load_matrix_from_console
%apply (float* IN_ARRAY2, int DIM1, int DIM2 ) \ // IN_ARRAY2: Input 2D
{(float* numpy_matrix, int num_of_rows, int num_of_cols)}
// mul_numpy is actually a 2D array flattened row-wise into a 1D array
// Why not use 2D? bc typemap (double* ARGOUT_ARRAY2, int DIM1, int DIM2)
// is not available in numpy.i
%apply (double* ARGOUT_ARRAY1, int DIM1) \ // ARGOUT: output array
{(double* product_matrix, int len_mul_numpy)}
// inv_numpy is actually a 2D array flattened row-wise into a 1D array
// Why not use 2D? bc typemap (double* ARGOUT_ARRAY2, int DIM1, int DIM2)
// is not available in numpy.i
%apply (double* ARGOUT_ARRAY1, int DIM1) \ // ARGOUT: output array
{(double* inverse_matrix, int len_inv_numpy)}
/* Typically in the end */
%include "../example/test_gofmm.h"