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