19 :
public boost::python::def_visitor<LDLTSolverVisitor<_MatrixType>> {
20 typedef _MatrixType MatrixType;
21 typedef typename MatrixType::Scalar Scalar;
22 typedef typename MatrixType::RealScalar RealScalar;
23 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, MatrixType::Options>
25 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic,
28 typedef Eigen::LDLT<MatrixType> Solver;
30 template <
class PyClass>
31 void visit(PyClass &cl)
const {
32 cl.def(bp::init<>(bp::arg(
"self"),
"Default constructor"))
33 .def(bp::init<Eigen::DenseIndex>(
34 bp::args(
"self",
"size"),
35 "Default constructor with memory preallocation"))
36 .def(bp::init<MatrixType>(
37 bp::args(
"self",
"matrix"),
38 "Constructs a LDLT factorization from a given matrix."))
42 .def(
"isNegative", &Solver::isNegative, bp::arg(
"self"),
43 "Returns true if the matrix is negative (semidefinite).")
44 .def(
"isPositive", &Solver::isPositive, bp::arg(
"self"),
45 "Returns true if the matrix is positive (semidefinite).")
47 .def(
"matrixL", &matrixL, bp::arg(
"self"),
48 "Returns the lower triangular matrix L.")
49 .def(
"matrixU", &matrixU, bp::arg(
"self"),
50 "Returns the upper triangular matrix U.")
51 .def(
"vectorD", &vectorD, bp::arg(
"self"),
52 "Returns the coefficients of the diagonal matrix D.")
53 .def(
"transpositionsP", &transpositionsP, bp::arg(
"self"),
54 "Returns the permutation matrix P.")
56 .def(
"matrixLDLT", &Solver::matrixLDLT, bp::arg(
"self"),
57 "Returns the LDLT decomposition matrix.",
58 bp::return_internal_reference<>())
61 (Solver & (Solver::*)(
const Eigen::MatrixBase<VectorXs> &,
62 const RealScalar &)) &
63 Solver::template rankUpdate<VectorXs>,
64 bp::args(
"self",
"vector",
"sigma"), bp::return_self<>())
66#if EIGEN_VERSION_AT_LEAST(3, 3, 0) 67 .def(
"adjoint", &Solver::adjoint, bp::arg(
"self"),
68 "Returns the adjoint, that is, a reference to the decomposition " 69 "itself as if the underlying matrix is self-adjoint.",
75 (Solver & (Solver::*)(
const Eigen::EigenBase<MatrixType> &matrix)) &
77 bp::args(
"self",
"matrix"),
"Computes the LDLT of given matrix.",
80 .def(
"info", &Solver::info, bp::arg(
"self"),
81 "NumericalIssue if the input contains INF or NaN values or " 82 "overflow occured. Returns Success otherwise.")
83#if EIGEN_VERSION_AT_LEAST(3, 3, 0) 84 .def(
"rcond", &Solver::rcond, bp::arg(
"self"),
85 "Returns an estimate of the reciprocal condition number of the " 88 .def(
"reconstructedMatrix", &Solver::reconstructedMatrix,
90 "Returns the matrix represented by the decomposition, i.e., it " 91 "returns the product: L L^*. This function is provided for debug " 93 .def(
"solve", &solve<VectorXs>, bp::args(
"self",
"b"),
94 "Returns the solution x of A x = b using the current " 95 "decomposition of A.")
96 .def(
"solve", &solve<MatrixXs>, bp::args(
"self",
"B"),
97 "Returns the solution X of A X = B using the current " 98 "decomposition of A where B is a right hand side matrix.")
100 .def(
"setZero", &Solver::setZero, bp::arg(
"self"),
101 "Clear any existing decomposition.");
105 static const std::string classname =
106 "LDLT" + scalar_name<Scalar>::shortname();
110 static void expose(
const std::string &name) {
113 "Robust Cholesky decomposition of a matrix with pivoting.\n\n" 114 "Perform a robust Cholesky decomposition of a positive semidefinite or " 115 "negative semidefinite matrix $ A $ such that $ A = P^TLDL^*P $, where " 116 "P is a permutation matrix, L is lower triangular with a unit diagonal " 117 "and D is a diagonal matrix.\n\n" 118 "The decomposition uses pivoting to ensure stability, so that L will " 119 "have zeros in the bottom right rank(A) - n submatrix. Avoiding the " 120 "square root on D also stabilizes the computation.",
127 static MatrixType matrixL(
const Solver &self) {
return self.matrixL(); }
128 static MatrixType matrixU(
const Solver &self) {
return self.matrixU(); }
129 static VectorXs vectorD(
const Solver &self) {
return self.vectorD(); }
131 static MatrixType transpositionsP(
const Solver &self) {
132 return self.transpositionsP() *
133 MatrixType::Identity(self.matrixL().rows(), self.matrixL().rows());
136 template <
typename MatrixOrVector>
137 static MatrixOrVector solve(
const Solver &self,
const MatrixOrVector &vec) {
138 return self.solve(vec);