eigenpy 3.12.0
Bindings between Numpy and Eigen using Boost.Python
Loading...
Searching...
No Matches
GeneralizedEigenSolver.hpp
1/*
2 * Copyright 2025 INRIA
3 */
4
5#ifndef __eigenpy_decompositions_generalized_eigen_solver_hpp__
6#define __eigenpy_decompositions_generalized_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<
20 GeneralizedEigenSolverVisitor<_MatrixType>> {
21 typedef _MatrixType MatrixType;
22 typedef typename MatrixType::Scalar Scalar;
23 typedef Eigen::GeneralizedEigenSolver<MatrixType> Solver;
24
25 template <class PyClass>
26 void visit(PyClass& cl) const {
27 cl.def(bp::init<>("Default constructor"))
28 .def(bp::init<Eigen::DenseIndex>(
29 bp::arg("size"), "Default constructor with memory preallocation. "))
30 .def(bp::init<MatrixType, MatrixType, bp::optional<bool>>(
31 bp::args("A", "B", "computeEigenVectors"),
32 "Computes the generalized eigendecomposition of given matrix "
33 "pair. "))
34
35 .def("eigenvectors", &Solver::eigenvectors, bp::arg("self"),
36 "Returns an expression of the computed generalized eigenvectors. ")
37 .def(
38 "eigenvalues",
39 +[](const Solver& c) { return c.eigenvalues().eval(); },
40 "Returns the computed generalized eigenvalues.")
41
42 .def("alphas", &Solver::alphas, bp::arg("self"),
43 "Returns the vectors containing the alpha values. ")
44 .def("betas", &Solver::betas, bp::arg("self"),
45 "Returns the vectors containing the beta values. ")
46
47 .def("compute",
48 &GeneralizedEigenSolverVisitor::compute_proxy<MatrixType>,
49 bp::args("self", "A", "B"),
50 "Computes generalized eigendecomposition of given matrix. ",
51 bp::return_self<>())
52 .def("compute",
53 (Solver &
54 (Solver::*)(const MatrixType& A, const MatrixType& B, bool)) &
55 Solver::compute,
56 bp::args("self", "A", "B", "computeEigenvectors"),
57 "Computes generalized eigendecomposition of given matrix. .",
58 bp::return_self<>())
59
60 .def("info", &Solver::info, bp::arg("self"),
61 "NumericalIssue if the input contains INF or NaN values or "
62 "overflow occured. Returns Success otherwise.")
63
64 .def("setMaxIterations", &Solver::setMaxIterations,
65 bp::args("self", "max_iter"),
66 "Sets the maximum number of iterations allowed.",
67 bp::return_self<>());
68 }
69
70 static void expose() {
71 static const std::string classname =
72 "GeneralizedEigenSolver" + scalar_name<Scalar>::shortname();
73 expose(classname);
74 }
75
76 static void expose(const std::string& name) {
77 bp::class_<Solver>(name.c_str(), bp::no_init)
79 .def(IdVisitor<Solver>());
80 }
81
82 private:
83 template <typename MatrixType>
84 static Solver& compute_proxy(Solver& self, const MatrixType& A,
85 const MatrixType& B) {
86 return self.compute(A, B);
87 }
88};
89
90} // namespace eigenpy
91
92#endif // ifndef __eigenpy_decompositions_generalized_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