Michele De Stefano's C++ Utilities
vector.i
1 // mds_utils/python/ublas/vector.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 
8 %header %{
9 #include <mds_utils/python/ublas/vector.hpp>
10 
11 namespace ublas_convert = boost::numeric::ublas;
12 %}
13 
14 %define VECTOR_IN_TYPEMAPS_GEN(type)
15 
16 %typemap(in) (ublas_convert::vector< type >) {
17  try {
18  $1 = mds_utils::python::ublas::get< boost::numeric::ublas::vector< type > >($input);
19  } catch (std::exception& e) {
20  PyErr_SetString(PyExc_RuntimeError,e.what());
21  SWIG_fail;
22  }
23 }
24 
25 %typecheck(SWIG_TYPECHECK_POINTER) ublas_convert::vector< type > {
26  $1 = PyArray_Check($input);
27 }
28 
29 
30 %enddef
31 
32 VECTOR_IN_TYPEMAPS_GEN(char)
33 VECTOR_IN_TYPEMAPS_GEN(unsigned char)
34 VECTOR_IN_TYPEMAPS_GEN(short)
35 VECTOR_IN_TYPEMAPS_GEN(unsigned short)
36 VECTOR_IN_TYPEMAPS_GEN(int)
37 VECTOR_IN_TYPEMAPS_GEN(unsigned int)
38 VECTOR_IN_TYPEMAPS_GEN(long)
39 VECTOR_IN_TYPEMAPS_GEN(unsigned long)
40 VECTOR_IN_TYPEMAPS_GEN(long long)
41 VECTOR_IN_TYPEMAPS_GEN(unsigned long long)
42 VECTOR_IN_TYPEMAPS_GEN(size_t)
43 VECTOR_IN_TYPEMAPS_GEN(float)
44 VECTOR_IN_TYPEMAPS_GEN(double)
45 VECTOR_IN_TYPEMAPS_GEN(long double)
46 VECTOR_IN_TYPEMAPS_GEN(std::complex<float>)
47 VECTOR_IN_TYPEMAPS_GEN(std::complex<double>)
48 VECTOR_IN_TYPEMAPS_GEN(std::complex<long double>)
49 
50 %typemap(out) ublas_convert::vector<double> {
51  $result = mds_utils::python::ublas::to_python($1);
52 }
53 
54 
55 
56 %define VECTOR_OUT_TYPEMAPS_GEN(type)
57 
58 %typemap(out) ublas_convert::vector< type > = ublas_convert::vector<double>;
59 
60 %enddef
61 
62 VECTOR_OUT_TYPEMAPS_GEN(char)
63 VECTOR_OUT_TYPEMAPS_GEN(unsigned char)
64 VECTOR_OUT_TYPEMAPS_GEN(short)
65 VECTOR_OUT_TYPEMAPS_GEN(unsigned short)
66 VECTOR_OUT_TYPEMAPS_GEN(int)
67 VECTOR_OUT_TYPEMAPS_GEN(unsigned int)
68 VECTOR_OUT_TYPEMAPS_GEN(long)
69 VECTOR_OUT_TYPEMAPS_GEN(unsigned long)
70 VECTOR_OUT_TYPEMAPS_GEN(long long)
71 VECTOR_OUT_TYPEMAPS_GEN(unsigned long long)
72 VECTOR_OUT_TYPEMAPS_GEN(size_t)
73 VECTOR_OUT_TYPEMAPS_GEN(float)
74 VECTOR_OUT_TYPEMAPS_GEN(long double)
75 VECTOR_OUT_TYPEMAPS_GEN(std::complex<float>)
76 VECTOR_OUT_TYPEMAPS_GEN(std::complex<double>)
77 VECTOR_OUT_TYPEMAPS_GEN(std::complex<long double>)
78