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
|
// -*- c++ -*-
%module Array
%{
#define SWIG_FILE_WITH_INIT
#include "Array1.h"
#include "Array2.h"
#include "ArrayZ.h"
%}
// Get the NumPy typemaps
%include "../numpy.i"
// Get the STL typemaps
%include "stl.i"
// Handle standard exceptions
%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();
%}
// Global ignores
%ignore *::operator=;
%ignore *::operator[];
// Apply the 1D NumPy typemaps
%apply (int DIM1 , long* INPLACE_ARRAY1)
{(int length, long* data )};
%apply (long** ARGOUTVIEW_ARRAY1, int* DIM1 )
{(long** data , int* length)};
// Apply the 2D NumPy typemaps
%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 )};
// Apply the 1D NumPy typemaps
%apply (int DIM1 , std::complex<double>* INPLACE_ARRAY1)
{(int length, std::complex<double>* data )};
%apply (std::complex<double>** ARGOUTVIEW_ARRAY1, int* DIM1 )
{(std::complex<double>** data , int* length)};
// Array1 support
%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();
}
}
// Array2 support
%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();
}
}
// ArrayZ support
%include "ArrayZ.h"
%extend ArrayZ
{
void __setitem__(int i, std::complex<double> v)
{
self->operator[](i) = v;
}
std::complex<double> __getitem__(int i)
{
return self->operator[](i);
}
int __len__()
{
return self->length();
}
std::string __str__()
{
return self->asString();
}
}
|