|
| 1 | +/* |
| 2 | + * Copyright 2020 INRIA |
| 3 | + */ |
| 4 | + |
| 5 | +#ifndef __eigenpy_decompositions_tridiagonalization_hpp__ |
| 6 | +#define __eigenpy_decompositions_tridiagonalization_hpp__ |
| 7 | + |
| 8 | +#include <Eigen/Core> |
| 9 | +#include <Eigen/Eigenvalues> |
| 10 | + |
| 11 | +#include "eigenpy/eigen-to-python.hpp" |
| 12 | +#include "eigenpy/eigenpy.hpp" |
| 13 | +#include "eigenpy/utils/scalar-name.hpp" |
| 14 | + |
| 15 | +namespace eigenpy { |
| 16 | + |
| 17 | +template <typename _MatrixType> |
| 18 | +struct TridiagonalizationVisitor |
| 19 | + : public boost::python::def_visitor<TridiagonalizationVisitor<_MatrixType>> { |
| 20 | + typedef _MatrixType MatrixType; |
| 21 | + typedef typename MatrixType::Scalar Scalar; |
| 22 | + typedef Eigen::Tridiagonalization<MatrixType> Solver; |
| 23 | + |
| 24 | + template <class PyClass> |
| 25 | + void visit(PyClass& cl) const { |
| 26 | + cl.def( |
| 27 | + bp::init<Eigen::DenseIndex>(bp::arg("size"), "Default constructor. ")) |
| 28 | + .def(bp::init<MatrixType>( |
| 29 | + bp::arg("matrix"), |
| 30 | + "Constructor; computes tridiagonal decomposition of given matrix. ")) |
| 31 | + |
| 32 | + .def("compute", &TridiagonalizationVisitor::compute_proxy<MatrixType>, |
| 33 | + bp::args("self", "matrix"), |
| 34 | + "Computes tridiagonal decomposition of given matrix. ", |
| 35 | + bp::return_self<>()) |
| 36 | + .def("compute", |
| 37 | + (Solver & |
| 38 | + (Solver::*)(const Eigen::EigenBase<MatrixType>& matrix)) & |
| 39 | + Solver::compute, |
| 40 | + bp::args("self", "matrix"), |
| 41 | + "Computes tridiagonal decomposition of given matrix. ", bp::return_self<>()) |
| 42 | + |
| 43 | + .def("diagonal", &Solver::diagonal, bp::arg("self"), |
| 44 | + "Returns the diagonal of the tridiagonal matrix T in the decomposition. ") |
| 45 | + |
| 46 | + .def("householderCoefficients", &Solver::householderCoefficients, |
| 47 | + bp::arg("self"), "Returns the Householder coefficients. ") |
| 48 | + |
| 49 | + .def("matrixQ", &Solver::matrixQ, |
| 50 | + bp::arg("self"), "Returns the unitary matrix Q in the decomposition. ") |
| 51 | + .def("matrixT", &Solver::matrixT, |
| 52 | + bp::arg("self"), "Returns the unitary matrix T in the decomposition. ") |
| 53 | + |
| 54 | + .def("packedMatrix", &Solver::packedMatrix, bp::arg("self"), |
| 55 | + "Returns the internal representation of the decomposition. ", |
| 56 | + bp::return_value_policy<bp::copy_const_reference>()) |
| 57 | + |
| 58 | + .def("subDiagonal", &Solver::subDiagonal, bp::arg("self"), |
| 59 | + "Returns the subdiagonal of the tridiagonal matrix T in the decomposition."); |
| 60 | + } |
| 61 | + |
| 62 | + static void expose() { |
| 63 | + static const std::string classname = |
| 64 | + "TridiagonalizationVisitor" + scalar_name<Scalar>::shortname(); |
| 65 | + expose(classname); |
| 66 | + } |
| 67 | + |
| 68 | + static void expose(const std::string& name) { |
| 69 | + bp::class_<Solver>(name.c_str(), bp::no_init) |
| 70 | + .def(TridiagonalizationVisitor()) |
| 71 | + .def(IdVisitor<Solver>()); |
| 72 | + } |
| 73 | + |
| 74 | + private: |
| 75 | + template <typename MatrixType> |
| 76 | + static Solver& compute_proxy(Solver& self, const Eigen::EigenBase<MatrixType>& matrix) { |
| 77 | + return self.compute(matrix); |
| 78 | + } |
| 79 | +}; |
| 80 | + |
| 81 | +} // namespace eigenpy |
| 82 | + |
| 83 | +#endif // ifndef __eigenpy_decompositions_tridiagonalization_hpp__ |
0 commit comments