eigenpy 3.12.0
Bindings between Numpy and Eigen using Boost.Python
Loading...
Searching...
No Matches
EigenSolver.hpp
1/*
2 * Copyright 2020 INRIA
3 */
4
5#ifndef __eigenpy_decompositions_eigen_solver_hpp__
6#define __eigenpy_decompositions_eigen_solver_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
15namespace eigenpy {
16
17template <typename _MatrixType>
19 : public boost::python::def_visitor<EigenSolverVisitor<_MatrixType>> {
20 typedef _MatrixType MatrixType;
21 typedef typename MatrixType::Scalar Scalar;
22 typedef Eigen::EigenSolver<MatrixType> Solver;
23
24 template <class PyClass>
25 void visit(PyClass& cl) const {
26 cl.def(bp::init<>("Default constructor"))
27 .def(bp::init<Eigen::DenseIndex>(
28 bp::arg("size"), "Default constructor with memory preallocation"))
29 .def(bp::init<MatrixType, bp::optional<bool>>(
30 bp::args("matrix", "compute_eigen_vectors"),
31 "Computes eigendecomposition of given matrix"))
32
33 .def("eigenvalues", &Solver::eigenvalues, bp::arg("self"),
34 "Returns the eigenvalues of given matrix.",
35 bp::return_internal_reference<>())
36 .def("eigenvectors", &Solver::eigenvectors, bp::arg("self"),
37 "Returns the eigenvectors of given matrix.")
38
39 .def("compute", &EigenSolverVisitor::compute_proxy<MatrixType>,
40 bp::args("self", "matrix"),
41 "Computes the eigendecomposition of given matrix.",
42 bp::return_self<>())
43 .def("compute",
44 (Solver &
45 (Solver::*)(const Eigen::EigenBase<MatrixType>& matrix, bool)) &
46 Solver::compute,
47 bp::args("self", "matrix", "compute_eigen_vectors"),
48 "Computes the eigendecomposition of given matrix.",
49 bp::return_self<>())
50
51 .def("getMaxIterations", &Solver::getMaxIterations, bp::arg("self"),
52 "Returns the maximum number of iterations.")
53 .def("setMaxIterations", &Solver::setMaxIterations,
54 bp::args("self", "max_iter"),
55 "Sets the maximum number of iterations allowed.",
56 bp::return_self<>())
57
58 .def("pseudoEigenvalueMatrix", &Solver::pseudoEigenvalueMatrix,
59 bp::arg("self"),
60 "Returns the block-diagonal matrix in the "
61 "pseudo-eigendecomposition.")
62 .def("pseudoEigenvectors", &Solver::pseudoEigenvectors, bp::arg("self"),
63 "Returns the pseudo-eigenvectors of given matrix.",
64 bp::return_internal_reference<>())
65
66 .def("info", &Solver::info, bp::arg("self"),
67 "NumericalIssue if the input contains INF or NaN values or "
68 "overflow occured. Returns Success otherwise.");
69 }
70
71 static void expose() {
72 static const std::string classname =
73 "EigenSolver" + 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)
80 .def(IdVisitor<Solver>());
81 }
82
83 private:
84 template <typename MatrixType>
85 static Solver& compute_proxy(Solver& self,
86 const Eigen::EigenBase<MatrixType>& matrix) {
87 return self.compute(matrix);
88 }
89};
90
91} // namespace eigenpy
92
93#endif // ifndef __eigenpy_decompositions_eigen_solver_hpp__
void expose()
Call the expose function of a given type T.
Definition expose.hpp:23
Add the Python method id to retrieving a unique id for a given object exposed with Boost....
Definition id.hpp:18