LLT.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020-2021 INRIA
3  */
4 
5 #ifndef __eigenpy_decomposition_llt_hpp__
6 #define __eigenpy_decomposition_llt_hpp__
7 
8 #include <Eigen/Cholesky>
9 #include <Eigen/Core>
10 
11 #include "eigenpy/eigenpy.hpp"
13 
14 namespace eigenpy {
15 
16 template <typename _MatrixType>
18  : public boost::python::def_visitor<LLTSolverVisitor<_MatrixType> > {
19  typedef _MatrixType MatrixType;
20  typedef typename MatrixType::Scalar Scalar;
21  typedef typename MatrixType::RealScalar RealScalar;
22  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, MatrixType::Options>
24  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic,
25  MatrixType::Options>
27  typedef Eigen::LLT<MatrixType> Solver;
28 
29  template <class PyClass>
30  void visit(PyClass &cl) const {
31  cl.def(bp::init<>(bp::arg("self"), "Default constructor"))
32  .def(bp::init<Eigen::DenseIndex>(
33  bp::args("self", "size"),
34  "Default constructor with memory preallocation"))
35  .def(bp::init<MatrixType>(
36  bp::args("self", "matrix"),
37  "Constructs a LLT factorization from a given matrix."))
38 
39  .def("matrixL", &matrixL, bp::arg("self"),
40  "Returns the lower triangular matrix L.")
41  .def("matrixU", &matrixU, bp::arg("self"),
42  "Returns the upper triangular matrix U.")
43  .def("matrixLLT", &Solver::matrixLLT, bp::arg("self"),
44  "Returns the LLT decomposition matrix.",
45  bp::return_internal_reference<>())
46 
47 #if EIGEN_VERSION_AT_LEAST(3, 3, 90)
48  .def("rankUpdate",
49  (Solver & (Solver::*)(const VectorXs &, const RealScalar &)) &
50  Solver::template rankUpdate<VectorXs>,
51  bp::args("self", "vector", "sigma"), bp::return_self<>())
52 #else
53  .def("rankUpdate",
54  (Solver(Solver::*)(const VectorXs &, const RealScalar &)) &
55  Solver::template rankUpdate<VectorXs>,
56  bp::args("self", "vector", "sigma"))
57 #endif
58 
59 #if EIGEN_VERSION_AT_LEAST(3, 3, 0)
60  .def("adjoint", &Solver::adjoint, bp::arg("self"),
61  "Returns the adjoint, that is, a reference to the decomposition "
62  "itself as if the underlying matrix is self-adjoint.",
63  bp::return_self<>())
64 #endif
65 
66  .def(
67  "compute",
68  (Solver & (Solver::*)(const Eigen::EigenBase<MatrixType> &matrix)) &
69  Solver::compute,
70  bp::args("self", "matrix"), "Computes the LLT of given matrix.",
71  bp::return_self<>())
72 
73  .def("info", &Solver::info, bp::arg("self"),
74  "NumericalIssue if the input contains INF or NaN values or "
75  "overflow occured. Returns Success otherwise.")
76 #if EIGEN_VERSION_AT_LEAST(3, 3, 0)
77  .def("rcond", &Solver::rcond, bp::arg("self"),
78  "Returns an estimate of the reciprocal condition number of the "
79  "matrix.")
80 #endif
81  .def("reconstructedMatrix", &Solver::reconstructedMatrix,
82  bp::arg("self"),
83  "Returns the matrix represented by the decomposition, i.e., it "
84  "returns the product: L L^*. This function is provided for debug "
85  "purpose.")
86  .def("solve", &solve<VectorXs>, bp::args("self", "b"),
87  "Returns the solution x of A x = b using the current "
88  "decomposition of A.")
89  .def("solve", &solve<MatrixXs>, bp::args("self", "B"),
90  "Returns the solution X of A X = B using the current "
91  "decomposition of A where B is a right hand side matrix.");
92  }
93 
94  static void expose() {
95  static const std::string classname =
97  expose(classname);
98  }
99 
100  static void expose(const std::string &name) {
101  bp::class_<Solver>(
102  name.c_str(),
103  "Standard Cholesky decomposition (LL^T) of a matrix and associated "
104  "features.\n\n"
105  "This class performs a LL^T Cholesky decomposition of a symmetric, "
106  "positive definite matrix A such that A = LL^* = U^*U, where L is "
107  "lower triangular.\n\n"
108  "While the Cholesky decomposition is particularly useful to solve "
109  "selfadjoint problems like D^*D x = b, for that purpose, we recommend "
110  "the Cholesky decomposition without square root which is more stable "
111  "and even faster. Nevertheless, this standard Cholesky decomposition "
112  "remains useful in many other situations like generalised eigen "
113  "problems with hermitian matrices.",
114  bp::no_init)
115  .def(LLTSolverVisitor());
116  }
117 
118  private:
119  static MatrixType matrixL(const Solver &self) { return self.matrixL(); }
120  static MatrixType matrixU(const Solver &self) { return self.matrixU(); }
121 
122  template <typename MatrixOrVector>
123  static MatrixOrVector solve(const Solver &self, const MatrixOrVector &vec) {
124  return self.solve(vec);
125  }
126 };
127 
128 } // namespace eigenpy
129 
130 #endif // ifndef __eigenpy_decomposition_llt_hpp__
void visit(PyClass &cl) const
Definition: LLT.hpp:30
static void expose(const std::string &name)
Definition: LLT.hpp:100
static MatrixOrVector solve(const Solver &self, const MatrixOrVector &vec)
Definition: LLT.hpp:123
MatrixType::RealScalar RealScalar
Definition: LLT.hpp:21
_MatrixType MatrixType
Definition: LLT.hpp:19
static std::string shortname()
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic, MatrixType::Options > MatrixXs
Definition: LLT.hpp:26
Eigen::LLT< MatrixType > Solver
Definition: LLT.hpp:27
static void expose()
Definition: LLT.hpp:94
static MatrixType matrixL(const Solver &self)
Definition: LLT.hpp:119
static MatrixType matrixU(const Solver &self)
Definition: LLT.hpp:120
Eigen::Matrix< Scalar, Eigen::Dynamic, 1, MatrixType::Options > VectorXs
Definition: LLT.hpp:23
MatrixType::Scalar Scalar
Definition: LLT.hpp:20


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Fri Jun 2 2023 02:10:26