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
|
%define %Matrix_typemaps(DATA_TYPE,DATA_TYPECODE)
%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY,
fragment="NumPy_Macros")
const Matrix< DATA_TYPE >&
{
$1 = is_array($input) || PySequence_Check($input);
}
%typemap(in,
fragment="NumPy_Fragments")
const Matrix<DATA_TYPE>&
(PyArrayObject* array=NULL, int is_new_object=0,Matrix<DATA_TYPE>* new_mat=0 )
{
npy_intp size[2] = { -1, -1 };
array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 2) ||
!require_size(array, size, 2)) SWIG_fail;
new_mat = new Matrix<DATA_TYPE>((size_t) array_size(array,0),(size_t) array_size(array,1), (DATA_TYPE*) array_data(array));
$1 = new_mat;
}
%typemap(freearg) const Matrix< DATA_TYPE >& {
if (new_mat$argnum) delete new_mat$argnum;
}
%enddef // %Matrix_typemaps()
// Concrete instanciations of the macro %Matrix_typemaps()
%Matrix_typemaps(signed char , NPY_BYTE )
%Matrix_typemaps(unsigned char , NPY_UBYTE )
%Matrix_typemaps(short , NPY_SHORT )
%Matrix_typemaps(unsigned short , NPY_USHORT )
%Matrix_typemaps(int , NPY_INT )
%Matrix_typemaps(unsigned int , NPY_UINT )
%Matrix_typemaps(long , NPY_LONG )
%Matrix_typemaps(unsigned long , NPY_ULONG )
%Matrix_typemaps(long long , NPY_LONGLONG )
%Matrix_typemaps(unsigned long long, NPY_ULONGLONG)
%Matrix_typemaps(float , NPY_FLOAT )
%Matrix_typemaps(double , NPY_DOUBLE ) |
Partager