|
|
|
|
|
%module Array |
|
|
|
%{ |
|
#define SWIG_FILE_WITH_INIT |
|
#include "Array1.h" |
|
#include "Array2.h" |
|
%} |
|
|
|
|
|
%include "../numpy.i" |
|
|
|
|
|
%include "stl.i" |
|
|
|
|
|
%include "exception.i" |
|
%exception |
|
{ |
|
try |
|
{ |
|
$action |
|
} |
|
catch (const std::invalid_argument& e) |
|
{ |
|
SWIG_exception(SWIG_ValueError, e.what()); |
|
} |
|
catch (const std::out_of_range& e) |
|
{ |
|
SWIG_exception(SWIG_IndexError, e.what()); |
|
} |
|
} |
|
%init %{ |
|
import_array(); |
|
%} |
|
|
|
|
|
%ignore *::operator=; |
|
%ignore *::operator[]; |
|
|
|
|
|
%apply (int DIM1 , long* INPLACE_ARRAY1) |
|
{(int length, long* data )}; |
|
%apply (long** ARGOUTVIEW_ARRAY1, int* DIM1 ) |
|
{(long** data , int* length)}; |
|
|
|
|
|
%apply (int DIM1 , int DIM2 , long* INPLACE_ARRAY2) |
|
{(int nrows, int ncols, long* data )}; |
|
%apply (int* DIM1 , int* DIM2 , long** ARGOUTVIEW_ARRAY2) |
|
{(int* nrows, int* ncols, long** data )}; |
|
|
|
|
|
%include "Array1.h" |
|
%extend Array1 |
|
{ |
|
void __setitem__(int i, long v) |
|
{ |
|
self->operator[](i) = v; |
|
} |
|
|
|
long __getitem__(int i) |
|
{ |
|
return self->operator[](i); |
|
} |
|
|
|
int __len__() |
|
{ |
|
return self->length(); |
|
} |
|
|
|
std::string __str__() |
|
{ |
|
return self->asString(); |
|
} |
|
} |
|
|
|
|
|
%include "Array2.h" |
|
%extend Array2 |
|
{ |
|
void __setitem__(int i, Array1 & v) |
|
{ |
|
self->operator[](i) = v; |
|
} |
|
|
|
Array1 & __getitem__(int i) |
|
{ |
|
return self->operator[](i); |
|
} |
|
|
|
int __len__() |
|
{ |
|
return self->nrows() * self->ncols(); |
|
} |
|
|
|
std::string __str__() |
|
{ |
|
return self->asString(); |
|
} |
|
} |
|
|