1 // mds_utils/python/ublas/matrix.i
3 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
5 // Distributed under the MIT License (See accompanying file LICENSE)
7 %include "mds_utils/python/common.i"
8 %include "mds_utils/python/obj.i"
9 %include "std_complex.i"
13 #include <mds_utils/python/ublas/matrix.hpp>
15 namespace ublas_convert = boost::numeric::ublas;
19 %define MATRIX_IN_TYPEMAPS_GEN(type)
21 %typemap(in) (ublas_convert::matrix< type >) {
23 $1 = mds_utils::python::ublas::get< boost::numeric::ublas::matrix< type > >($input);
24 } catch (std::exception& e) {
25 PyErr_SetString(PyExc_RuntimeError,e.what());
30 %typecheck(SWIG_TYPECHECK_POINTER) ublas_convert::matrix< type > {
31 $1 = PyArray_Check($input);
35 %typemap(in) (ublas_convert::matrix< type ,boost::numeric::ublas::row_major>) {
37 $1 = mds_utils::python::ublas::get< boost::numeric::ublas::matrix< type ,boost::numeric::ublas::row_major> >($input);
38 } catch (std::exception& e) {
39 PyErr_SetString(PyExc_RuntimeError,e.what());
44 %typecheck(SWIG_TYPECHECK_POINTER) ublas_convert::matrix< type ,boost::numeric::ublas::row_major> {
45 $1 = PyArray_Check($input);
49 %typemap(in) (ublas_convert::matrix< type ,boost::numeric::ublas::column_major>) {
51 $1 = mds_utils::python::ublas::get< boost::numeric::ublas::matrix< type ,boost::numeric::ublas::column_major> >($input);
52 } catch (std::exception& e) {
53 PyErr_SetString(PyExc_RuntimeError,e.what());
58 %typecheck(SWIG_TYPECHECK_POINTER) ublas_convert::matrix< type ,boost::numeric::ublas::column_major> {
59 $1 = PyArray_Check($input);
64 MATRIX_IN_TYPEMAPS_GEN(char)
65 MATRIX_IN_TYPEMAPS_GEN(unsigned char)
66 MATRIX_IN_TYPEMAPS_GEN(short)
67 MATRIX_IN_TYPEMAPS_GEN(unsigned short)
68 MATRIX_IN_TYPEMAPS_GEN(int)
69 MATRIX_IN_TYPEMAPS_GEN(unsigned int)
70 MATRIX_IN_TYPEMAPS_GEN(long)
71 MATRIX_IN_TYPEMAPS_GEN(unsigned long)
72 MATRIX_IN_TYPEMAPS_GEN(long long)
73 MATRIX_IN_TYPEMAPS_GEN(unsigned long long)
74 MATRIX_IN_TYPEMAPS_GEN(size_t)
75 MATRIX_IN_TYPEMAPS_GEN(float)
76 MATRIX_IN_TYPEMAPS_GEN(double)
77 MATRIX_IN_TYPEMAPS_GEN(long double)
78 MATRIX_IN_TYPEMAPS_GEN(std::complex<float>)
79 MATRIX_IN_TYPEMAPS_GEN(std::complex<double>)
80 MATRIX_IN_TYPEMAPS_GEN(std::complex<long double>)
82 %typemap(out) ublas_convert::matrix<double> {
83 $result = mds_utils::python::ublas::to_python($1);
86 %typemap(out) ublas_convert::matrix<double,boost::numeric::ublas::row_major> = ublas_convert::matrix<double>;
87 %typemap(out) ublas_convert::matrix<double,boost::numeric::ublas::column_major> = ublas_convert::matrix<double>;
90 %define MATRIX_OUT_TYPEMAPS_GEN(type)
92 %typemap(out) ublas_convert::matrix< type > = ublas_convert::matrix<double>;
93 %typemap(out) ublas_convert::matrix< type,boost::numeric::ublas::row_major> = ublas_convert::matrix<double>;
94 %typemap(out) ublas_convert::matrix< type,boost::numeric::ublas::column_major> = ublas_convert::matrix<double>;
98 MATRIX_OUT_TYPEMAPS_GEN(char)
99 MATRIX_OUT_TYPEMAPS_GEN(unsigned char)
100 MATRIX_OUT_TYPEMAPS_GEN(short)
101 MATRIX_OUT_TYPEMAPS_GEN(unsigned short)
102 MATRIX_OUT_TYPEMAPS_GEN(int)
103 MATRIX_OUT_TYPEMAPS_GEN(unsigned int)
104 MATRIX_OUT_TYPEMAPS_GEN(long)
105 MATRIX_OUT_TYPEMAPS_GEN(unsigned long)
106 MATRIX_OUT_TYPEMAPS_GEN(long long)
107 MATRIX_OUT_TYPEMAPS_GEN(unsigned long long)
108 MATRIX_OUT_TYPEMAPS_GEN(size_t)
109 MATRIX_OUT_TYPEMAPS_GEN(float)
110 MATRIX_OUT_TYPEMAPS_GEN(long double)
111 MATRIX_OUT_TYPEMAPS_GEN(std::complex<float>)
112 MATRIX_OUT_TYPEMAPS_GEN(std::complex<double>)
113 MATRIX_OUT_TYPEMAPS_GEN(std::complex<long double>)