Michele De Stefano's C++ Utilities
numpy_array.i
1 // mds_utils/python/ublas/numpy_array.i
2 //
3 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
4 //
5 // Distributed under the MIT License (See accompanying file LICENSE)
6 
7 %include "mds_utils/python/common.i"
8 %include "mds_utils/python/obj.i"
9 %include "std_complex.i"
10 
11 %header %{
12 #include <complex>
13 #include <mds_utils/python/ublas/numpy_array.hpp>
14 
15 namespace ublas_convert = boost::numeric::ublas;
16 %}
17 
18 %define NUMPY_ARRAY_IN_TYPEMAPS_GEN(type)
19 
20 %typemap(in) ublas_convert::NumPy1DArray< type > = mds_utils::python::Obj;
21 %typemap(in) ublas_convert::NumPy1DArray< type >& (ublas_convert::NumPy1DArray< type > tmp) {
22  try {
23  tmp = $input;
24  $1 = &tmp;
25  } catch (std::exception& e) {
26  PyErr_SetString(PyExc_RuntimeError,e.what());
27  SWIG_fail;
28  }
29 }
30 %typemap(in) ublas_convert::NumPy1DArray< type >* = ublas_convert::NumPy1DArray< type >&;
31 
32 %typecheck(SWIG_TYPECHECK_POINTER) ublas_convert::NumPy1DArray< type > {
33  $1 = PyArray_Check($input);
34 }
35 
36 
37 %enddef
38 
39 NUMPY_ARRAY_IN_TYPEMAPS_GEN(char)
40 NUMPY_ARRAY_IN_TYPEMAPS_GEN(unsigned char)
41 NUMPY_ARRAY_IN_TYPEMAPS_GEN(short)
42 NUMPY_ARRAY_IN_TYPEMAPS_GEN(unsigned short)
43 NUMPY_ARRAY_IN_TYPEMAPS_GEN(int)
44 NUMPY_ARRAY_IN_TYPEMAPS_GEN(unsigned int)
45 NUMPY_ARRAY_IN_TYPEMAPS_GEN(long)
46 NUMPY_ARRAY_IN_TYPEMAPS_GEN(unsigned long)
47 NUMPY_ARRAY_IN_TYPEMAPS_GEN(long long)
48 NUMPY_ARRAY_IN_TYPEMAPS_GEN(unsigned long long)
49 NUMPY_ARRAY_IN_TYPEMAPS_GEN(size_t)
50 NUMPY_ARRAY_IN_TYPEMAPS_GEN(float)
51 NUMPY_ARRAY_IN_TYPEMAPS_GEN(double)
52 NUMPY_ARRAY_IN_TYPEMAPS_GEN(long double)
53 NUMPY_ARRAY_IN_TYPEMAPS_GEN(std::complex<float>)
54 NUMPY_ARRAY_IN_TYPEMAPS_GEN(std::complex<double>)
55 NUMPY_ARRAY_IN_TYPEMAPS_GEN(std::complex<long double>)
56 
57 
58 %define NUMPY_ARRAY_OUT_TYPEMAPS_GEN(type)
59 
60 %typemap(out) ublas_convert::NumPy1DArray< type > = mds_utils::python::Obj;
61 
62 %enddef
63 
64 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(char)
65 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(unsigned char)
66 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(short)
67 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(unsigned short)
68 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(int)
69 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(unsigned int)
70 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(long)
71 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(unsigned long)
72 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(long long)
73 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(unsigned long long)
74 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(size_t)
75 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(float)
76 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(double)
77 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(long double)
78 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(std::complex<float>)
79 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(std::complex<double>)
80 NUMPY_ARRAY_OUT_TYPEMAPS_GEN(std::complex<long double>)
81