-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpyisc.i
More file actions
232 lines (172 loc) · 5.58 KB
/
pyisc.i
File metadata and controls
232 lines (172 loc) · 5.58 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
%module pyisc
%{
#define SWIG_FILE_WITH_INIT
/* Includes the header in the wrapper code */
#include "dataformat/format.hh"
#include "dataformat/formatbinary.hh"
#include "dataformat/formatcont.hh"
#include "dataformat/formatdiscr.hh"
#include "dataformat/formatsymbol.hh"
#include "dataformat/dynindvector.hh"
#include "dataformat/data.hh"
#include "isc2/isc_exportimport.hh"
#include "isc2/isc_micromodel.hh"
#include "isc2/hmatrix.hh"
#include "isc2/isc_micromodel_gaussian.hh"
#include "isc2/isc_component.hh"
#include "isc2/isc_mixture.hh"
#include "isc2/gamma.hh"
#include "isc2/isc_micromodel_multigaussian.hh"
#include "isc2/hgf.hh"
#include "isc2/isc_micromodel_poissongamma.hh"
#include "isc2/isc_micromodel_markovgaussian.hh"
//#include "isc2/isc_micromodel_multidirichlet.hh"
#include "isc2/anomalydetector.hh"
#include "src/_Format.hh"
#include "src/_DataObject.hh"
#include "src/_AnomalyDetector.hh"
#include "src/_JSonExporter.hh"
#include "src/_JSonImporter.hh"
%}
%include <typemaps.i>
%include "numpy.i"
%include <std_vector.i>
%include <std_string.i>
%init %{
import_array();
%}
%inline %{
/* Create any sort of [size] array */
int *_int_array(int size) {
return (int *) new int[size];
}
int **_int_pointer_array(int size) {
return (int **) new int*[size];
}
void _free_array_int_pointer(int** array, int length) {
delete [] array;
}
void _set_int_array(int** array2D, int index, int*array1D) {
array2D[index] = array1D;
}
void _set_array_value(int *array1, int index, int val) {
array1[index] = val;
}
int _get_array_value(int *array1, int index) {
return array1[index];
}
double* _double_array(int size) {
return (double*) new double[size];
}
int _get_int_value(int *array1, int index) {
return array1[index];
}
intfloat* _intfloat_array(int size) {
return (intfloat*) new intfloat[size];
}
void _free_array_intfloat(intfloat* array) {
delete [] array;
}
float _get_intfloat_value(intfloat *array1, int index) {
return (float) array1[index];
}
double _get_double_value(double* array1, int index) {
return array1[index];
}
double _set_double_value(double* array1, int index, double value) {
array1[index] = value;
}
double* _to_cpp_array(double* IN_ARRAY1, int DIM1) {
double* out_array = new double[DIM1];
for(int i=0; i < DIM1; i++) {
out_array[i] = IN_ARRAY1[i];
}
return out_array;
}
void _free_array_double(double* array) {
delete [] array;
}
int* _to_cpp_array_int(int* IN_ARRAY1, int DIM1) {
int* out_array = new int[DIM1];
for(int i=0; i < DIM1; i++) {
out_array[i] = IN_ARRAY1[i];
}
return out_array;
}
void _free_array_int(int* array) {
delete [] array;
}
void _to_numpy_array_double(double* inarray, double* ARGOUT_ARRAY1, int DIM1) {
for(int i=0; i < DIM1; i++) {
ARGOUT_ARRAY1[i] = inarray[i];
}
}
void _to_numpy_array_int(int* inarray, int* ARGOUT_ARRAY1, int DIM1) {
for(int i=0; i < DIM1; i++) {
ARGOUT_ARRAY1[i] = inarray[i];
}
}
char* _get_string_value(char** strings, int i) {
return strings[i];
}
IscMarkovGaussMicroModel** _to_pointer(std::vector<IscMarkovGaussMicroModel*> vec) {
IscMarkovGaussMicroModel** new_vec = new IscMarkovGaussMicroModel*[vec.size()];
for(int i=0; i < vec.size(); i++) {
new_vec[i] = vec[i];
}
return new_vec;
}
void _free_pointer(IscMarkovGaussMicroModel** new_vec) {
delete [] new_vec;
}
%}
%apply (double* IN_ARRAY1, int DIM1) {(double* in_array1D, int num_of_columns)}
%apply (double* IN_ARRAY2, int DIM1, int DIM2) {(double* in_array2D, int num_of_rows, int num_of_columns)}
%apply (double* ARGOUT_ARRAY1, int DIM1) {(double* deviations, int deviations_length)}
%apply (int* ARGOUT_ARRAY1, int DIM1) {(int* class_ids, int class_ids_length)}
%apply (int* ARGOUT_ARRAY1, int DIM1) {(int* cluster_ids, int cluster_ids_length)}
%apply (double* ARGOUT_ARRAY1, int DIM1) {(double* out_1DArray, int num_of_elements)}
%apply (double* ARGOUT_ARRAY1, int DIM1) {(double* logp, int size)}
/* Parse the header file to generate wrappers */
enum IscCombinationRule {IscMin, IscMax, IscPlus};
%ignore IscCombinationRule;
%ignore IscMin;
%ignore IscMax;
%ignore IscPlus;
%rename ("_%s", regexmatch$name="^Isc") "";
%include "isc2/isc_exportimport.hh"
%include "src/_Format.hh"
%include "src/_DataObject.hh"
%include "src/_AnomalyDetector.hh"
%include "src/_JSonExporter.hh"
%include "src/_JSonImporter.hh"
%include "isc2/isc_component.hh"
%include "isc2/isc_micromodel.hh"
%include "isc2/isc_micromodel_multigaussian.hh"
%include "isc2/isc_micromodel_poissongamma.hh"
%include "isc2/isc_micromodel_markovgaussian.hh"
#%include "isc2/isc_micromodel_multidirichlet.hh"
%template(_IscMicroModelVector) std::vector<IscMicroModel*>;
%template(_IscMarkovGaussMicroModelVector) std::vector<IscMarkovGaussMicroModel*>;
%pythoncode %{
from _pyisc_modules.BaseISC import *
from _pyisc_modules.AnomalyDetector import *
from _pyisc_modules.DataObject import *
from _pyisc_modules.SklearnClassifier import *
from _pyisc_modules.SklearnOutlierDetector import *
from _pyisc_modules.AnomalyClustering import *
from _pyisc_modules.OutlierClustering import *
from numpy import array, dtype, double
def _to_numpy_array(inarray, n, type=double):
if type == double:
return _to_numpy_array_double(inarray,n);
elif type == int:
return _to_numpy_array_int(inarray,n);
print ("Unknown type ", type)
%}
%extend pyisc::_DataObject {
intfloat* _DataObject::__getitem__(int i) {
return _get_intfloat(i);
}
}