|
| 1 | +/* |
| 2 | + * Copyright 2020 INRIA |
| 3 | + */ |
| 4 | + |
| 5 | +#ifndef __eigenpy_decompositions_complex_schur_hpp__ |
| 6 | +#define __eigenpy_decompositions_complex_schur_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 ComplexSchurVisitor |
| 19 | + : public boost::python::def_visitor<ComplexSchurVisitor<_MatrixType>> { |
| 20 | + typedef _MatrixType MatrixType; |
| 21 | + typedef typename MatrixType::Scalar Scalar; |
| 22 | + typedef Eigen::ComplexSchur<MatrixType> Solver; |
| 23 | + |
| 24 | + template <class PyClass> |
| 25 | + void visit(PyClass& cl) const { |
| 26 | + cl.def(bp::init<Eigen::DenseIndex>(bp::arg("size"), "Default constructor")) |
| 27 | + .def(bp::init<MatrixType, bp::optional<bool>>( |
| 28 | + bp::args("matrix", "computeU"), "Computes Schur of given matrix")) |
| 29 | + |
| 30 | + .def("compute", &ComplexSchurVisitor::compute_proxy<MatrixType>, |
| 31 | + bp::args("self", "matrix"), "Computes the Schur of given matrix.", |
| 32 | + bp::return_self<>()) |
| 33 | + .def("compute", |
| 34 | + (Solver & |
| 35 | + (Solver::*)(const Eigen::EigenBase<MatrixType>& matrix, bool)) & |
| 36 | + Solver::compute, |
| 37 | + bp::args("self", "matrix", "computeU"), |
| 38 | + "Computes the Schur of given matrix.", bp::return_self<>()) |
| 39 | + |
| 40 | + .def("computeFromHessenberg", |
| 41 | + (Solver & (Solver::*)(const Eigen::EigenBase<MatrixType>& matrixH, |
| 42 | + const Eigen::EigenBase<MatrixType>& matrixQ, |
| 43 | + bool)) & |
| 44 | + Solver::computeFromHessenberg, |
| 45 | + bp::args("self", "matrix", "computeU"), |
| 46 | + "Compute Schur decomposition from a given Hessenberg matrix. ", |
| 47 | + bp::return_self<>()) |
| 48 | + |
| 49 | + .def("matrixT", &Solver::matrixT, bp::arg("self"), |
| 50 | + "Returns the triangular matrix in the Schur decomposition. ", |
| 51 | + bp::return_value_policy<bp::copy_const_reference>()) |
| 52 | + .def("matrixU", &Solver::matrixU, bp::arg("self"), |
| 53 | + "Returns the unitary matrix in the Schur decomposition. ", |
| 54 | + bp::return_value_policy<bp::copy_const_reference>()) |
| 55 | + |
| 56 | + .def("info", &Solver::info, bp::arg("self"), |
| 57 | + "NumericalIssue if the input contains INF or NaN values or " |
| 58 | + "overflow occured. Returns Success otherwise.") |
| 59 | + |
| 60 | + .def("getMaxIterations", &Solver::getMaxIterations, bp::arg("self"), |
| 61 | + "Returns the maximum number of iterations.") |
| 62 | + .def("setMaxIterations", &Solver::setMaxIterations, |
| 63 | + bp::args("self", "max_iter"), |
| 64 | + "Sets the maximum number of iterations allowed.", |
| 65 | + bp::return_self<>()); |
| 66 | + } |
| 67 | + |
| 68 | + static void expose() { |
| 69 | + static const std::string classname = |
| 70 | + "ComplexSchur" + scalar_name<Scalar>::shortname(); |
| 71 | + expose(classname); |
| 72 | + } |
| 73 | + |
| 74 | + static void expose(const std::string& name) { |
| 75 | + bp::class_<Solver>(name.c_str(), bp::no_init) |
| 76 | + .def(ComplexSchurVisitor()) |
| 77 | + .def(IdVisitor<Solver>()); |
| 78 | + } |
| 79 | + |
| 80 | + private: |
| 81 | + template <typename MatrixType> |
| 82 | + static Solver& compute_proxy(Solver& self, |
| 83 | + const Eigen::EigenBase<MatrixType>& matrix) { |
| 84 | + return self.compute(matrix); |
| 85 | + } |
| 86 | +}; |
| 87 | + |
| 88 | +} // namespace eigenpy |
| 89 | + |
| 90 | +#endif // ifndef __eigenpy_decompositions_complex_schur_hpp__ |
0 commit comments