Debian Codegraph @

tools/swig/test/Array.i

raw
1 // -*- c++ -*-
2
3 %module Array
4
5 %{
6 #define SWIG_FILE_WITH_INIT
7 #include "Array1.h"
8 #include "Array2.h"
9 #include "ArrayZ.h"
10 %}
11
12 // Get the NumPy typemaps
13 %include "../numpy.i"
14
15 // Get the STL typemaps
16 %include "stl.i"
17
18 // Handle standard exceptions
19 %include "exception.i"
20 %exception
21 {
22 try
23 {
24 $action
25 }
26 catch (const std::invalid_argument& e)
27 {
28 SWIG_exception(SWIG_ValueError, e.what());
29 }
30 catch (const std::out_of_range& e)
31 {
32 SWIG_exception(SWIG_IndexError, e.what());
33 }
34 }
35 %init %{
36 import_array();
37 %}
38
39 // Global ignores
40 %ignore *::operator=;
41 %ignore *::operator[];
42
43 // Apply the 1D NumPy typemaps
44 %apply (int DIM1 , long* INPLACE_ARRAY1)
45 {(int length, long* data )};
46 %apply (long** ARGOUTVIEW_ARRAY1, int* DIM1 )
47 {(long** data , int* length)};
48
49 // Apply the 2D NumPy typemaps
50 %apply (int DIM1 , int DIM2 , long* INPLACE_ARRAY2)
51 {(int nrows, int ncols, long* data )};
52 %apply (int* DIM1 , int* DIM2 , long** ARGOUTVIEW_ARRAY2)
53 {(int* nrows, int* ncols, long** data )};
54
55 // Apply the 1D NumPy typemaps
56 %apply (int DIM1 , std::complex<double>* INPLACE_ARRAY1)
57 {(int length, std::complex<double>* data )};
58 %apply (std::complex<double>** ARGOUTVIEW_ARRAY1, int* DIM1 )
59 {(std::complex<double>** data , int* length)};
60
61 // Array1 support
62 %include "Array1.h"
63 %extend Array1
64 {
65 void __setitem__(int i, long v)
66 {
67 self->operator[](i) = v;
68 }
69
70 long __getitem__(int i)
71 {
72 return self->operator[](i);
73 }
74
75 int __len__()
76 {
77 return self->length();
78 }
79
80 std::string __str__()
81 {
82 return self->asString();
83 }
84 }
85
86 // Array2 support
87 %include "Array2.h"
88 %extend Array2
89 {
90 void __setitem__(int i, Array1 & v)
91 {
92 self->operator[](i) = v;
93 }
94
95 Array1 & __getitem__(int i)
96 {
97 return self->operator[](i);
98 }
99
100 int __len__()
101 {
102 return self->nrows() * self->ncols();
103 }
104
105 std::string __str__()
106 {
107 return self->asString();
108 }
109 }
110
111 // ArrayZ support
112 %include "ArrayZ.h"
113 %extend ArrayZ
114 {
115 void __setitem__(int i, std::complex<double> v)
116 {
117 self->operator[](i) = v;
118 }
119
120 std::complex<double> __getitem__(int i)
121 {
122 return self->operator[](i);
123 }
124
125 int __len__()
126 {
127 return self->length();
128 }
129
130 std::string __str__()
131 {
132 return self->asString();
133 }
134 }
135