-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathswig_test_mod.i
More file actions
141 lines (116 loc) · 3.42 KB
/
Copy pathswig_test_mod.i
File metadata and controls
141 lines (116 loc) · 3.42 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// -*- c++ -*-
/*
* Copyright (c) 2010-2012, Jim Bosch
* All rights reserved.
*
* ndarray is distributed under a simple BSD-like license;
* see the LICENSE file that should be present in the root
* of the source distribution, or alternately available at:
* https://github.com/ndarray/ndarray
*/
%module swig_test_mod
%{
#define PY_ARRAY_UNIQUE_SYMBOL LSST_SWIG_TEST_NUMPY_ARRAY_API
#include "numpy/arrayobject.h"
#include "ndarray/swig.h"
#include "ndarray/converter/eigen.h"
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wuninitialized"
#endif
%}
%init %{
import_array();
%}
%include "ndarray.i"
%declareNumPyConverters(Eigen::MatrixXd);
%declareNumPyConverters(Eigen::Matrix2d);
%declareNumPyConverters(Eigen::Matrix3d);
%declareNumPyConverters(Eigen::Matrix<double,2,2,Eigen::DontAlign>);
%declareNumPyConverters(ndarray::Array<double,1,0>);
%declareNumPyConverters(ndarray::Array<double,1,1>);
%declareNumPyConverters(ndarray::Array<double const,1,1>);
%declareNumPyConverters(ndarray::Array<double,3>);
%declareNumPyConverters(ndarray::Array<double const,3>);
%inline %{
Eigen::MatrixXd returnMatrixXd() {
Eigen::MatrixXd r(5, 3);
for (int n = 0; n < r.size(); ++n) {
r.data()[n] = n;
}
return r;
}
Eigen::Matrix2d returnMatrix2d() {
Eigen::Matrix2d r;
for (int n = 0; n < r.size(); ++n) {
r.data()[n] = n;
}
return r;
}
ndarray::Array<double,1,1> returnArray1() {
ndarray::Array<double,1,1> r(ndarray::allocate(ndarray::makeVector(6)));
for (int n = 0; n < r.getSize<0>(); ++n) {
r[n] = n;
}
return r;
}
ndarray::Array<double const,1,1> returnConstArray1() {
return returnArray1();
}
ndarray::Array<double,3> returnArray3() {
ndarray::Array<double,3,3> r(ndarray::allocate(ndarray::makeVector(4,3,2)));
ndarray::Array<double,1,1> f = ndarray::flatten<1>(r);
for (ndarray::Size n = 0; n < f.getSize<0>(); ++n) {
f[n] = n;
}
return r;
}
ndarray::Array<double const,3> returnConstArray3() {
return returnArray3();
}
bool acceptMatrixXd(Eigen::MatrixXd const & m1) {
Eigen::MatrixXd m2 = returnMatrixXd();
return m1 == m2;
}
bool acceptMatrix2d(Eigen::Matrix2d const & m1) {
Eigen::Matrix2d m2 = returnMatrix2d();
return m1 == m2;
}
bool acceptArray1(ndarray::Array<double,1,1> const & a1) {
ndarray::Array<double,1,1> a2 = returnArray1();
#ifndef GCC_45
return ndarray::all(ndarray::equal(a1, a2));
#else
return std::equal(a1.begin(), a1.end(), a2.begin());
#endif
}
void acceptArray10(ndarray::Array<double,1,0> const & a1) {}
bool acceptArray3(ndarray::Array<double,3> const & a1) {
ndarray::Array<double,3> a2 = returnArray3();
#ifndef GCC_45
return ndarray::all(ndarray::equal(a1, a2));
#else
for (ndarray::Size i = 0; i < a1.getSize<0>(); ++i) {
for (ndarray::Size j = 0; j < a1.getSize<1>(); ++j) {
if (!std::equal(a1[i][j].begin(), a1[i][j].end(), a2[i][j].begin())) return false;
}
}
return true;
#endif
}
int acceptOverload(int n) {
return 0;
}
int acceptOverload(Eigen::Matrix3d const & m) {
return 3;
}
int acceptOverload(Eigen::Matrix2d const & m) {
return 2;
}
struct MatrixOwner {
typedef Eigen::Matrix<double,2,2,Eigen::DontAlign> MemberMatrix;
MemberMatrix member;
MemberMatrix const & getMember() const { return member; }
MemberMatrix & getMember() { return member; }
explicit MatrixOwner() : member(MemberMatrix::Zero()) {}
};
%}