|
| 1 | +/* |
| 2 | + * Copyright 2020 INRIA |
| 3 | + */ |
| 4 | + |
| 5 | +#include "eigenpy/eigenpy.hpp" |
| 6 | + |
| 7 | +namespace Eigen |
| 8 | +{ |
| 9 | + #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \ |
| 10 | + /** \ingroup matrixtypedefs */ \ |
| 11 | + typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \ |
| 12 | + /** \ingroup matrixtypedefs */ \ |
| 13 | + typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \ |
| 14 | + /** \ingroup matrixtypedefs */ \ |
| 15 | + typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix; |
| 16 | + |
| 17 | + #define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \ |
| 18 | + /** \ingroup matrixtypedefs */ \ |
| 19 | + typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \ |
| 20 | + /** \ingroup matrixtypedefs */ \ |
| 21 | + typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix; |
| 22 | + |
| 23 | + #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \ |
| 24 | + EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \ |
| 25 | + EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \ |
| 26 | + EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \ |
| 27 | + EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \ |
| 28 | + EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \ |
| 29 | + EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \ |
| 30 | + EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4) |
| 31 | + |
| 32 | + EIGEN_MAKE_TYPEDEFS_ALL_SIZES(long double, ld) |
| 33 | + EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<long double>, cld) |
| 34 | + |
| 35 | + #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES |
| 36 | + #undef EIGEN_MAKE_TYPEDEFS |
| 37 | + #undef EIGEN_MAKE_FIXED_TYPEDEFS |
| 38 | +} |
| 39 | + |
| 40 | +template<typename ComplexMatrix> |
| 41 | +typename Eigen::Matrix<typename ComplexMatrix::RealScalar,ComplexMatrix::RowsAtCompileTime,ComplexMatrix::ColsAtCompileTime,ComplexMatrix::Options> |
| 42 | +real(const Eigen::MatrixBase<ComplexMatrix> & complex_mat) |
| 43 | +{ |
| 44 | + return complex_mat.real(); |
| 45 | +} |
| 46 | + |
| 47 | +template<typename ComplexMatrix> |
| 48 | +typename Eigen::Matrix<typename ComplexMatrix::RealScalar,ComplexMatrix::RowsAtCompileTime,ComplexMatrix::ColsAtCompileTime,ComplexMatrix::Options> |
| 49 | +imag(const Eigen::MatrixBase<ComplexMatrix> & complex_mat) |
| 50 | +{ |
| 51 | + return complex_mat.imag(); |
| 52 | +} |
| 53 | + |
| 54 | +template<typename Scalar, int Rows, int Cols, int Options> |
| 55 | +Eigen::Matrix<std::complex<Scalar>,Rows,Cols,Options> |
| 56 | +ascomplex(const Eigen::Matrix<Scalar,Rows,Cols,Options> & mat) |
| 57 | +{ |
| 58 | + typedef Eigen::Matrix<std::complex<Scalar>,Rows,Cols,Options> ReturnType; |
| 59 | + return ReturnType(mat); |
| 60 | +} |
| 61 | + |
| 62 | +BOOST_PYTHON_MODULE(complex) |
| 63 | +{ |
| 64 | + using namespace Eigen; |
| 65 | + namespace bp = boost::python; |
| 66 | + eigenpy::enableEigenPy(); |
| 67 | + |
| 68 | + bp::def("ascomplex", ascomplex<float,Eigen::Dynamic,Eigen::Dynamic,0>); |
| 69 | + bp::def("ascomplex", ascomplex<double,Eigen::Dynamic,Eigen::Dynamic,0>); |
| 70 | + bp::def("ascomplex", ascomplex<long double,Eigen::Dynamic,Eigen::Dynamic,0>); |
| 71 | + |
| 72 | + bp::def("real", (MatrixXf (*)(const Eigen::MatrixBase<MatrixXcf> &))&real<MatrixXcf>); |
| 73 | + bp::def("real", (MatrixXd (*)(const Eigen::MatrixBase<MatrixXcd> &))&real<MatrixXcd>); |
| 74 | + bp::def("real", (MatrixXld (*)(const Eigen::MatrixBase<MatrixXcld> &))&real<MatrixXcld>); |
| 75 | + |
| 76 | + bp::def("imag", (MatrixXf (*)(const Eigen::MatrixBase<MatrixXcf> &))&imag<MatrixXcf>); |
| 77 | + bp::def("imag", (MatrixXd (*)(const Eigen::MatrixBase<MatrixXcd> &))&imag<MatrixXcd>); |
| 78 | + bp::def("imag", (MatrixXld (*)(const Eigen::MatrixBase<MatrixXcld> &))&imag<MatrixXcld>); |
| 79 | +} |
0 commit comments