proxsuite-nlp  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
Loading...
Searching...
No Matches
expose-ldlt.cpp
Go to the documentation of this file.
2
4
5namespace proxsuite {
6namespace nlp {
7namespace python {
8
9template <class LDLTtype>
10struct LDLTVisitor : bp::def_visitor<LDLTVisitor<LDLTtype>> {
11 using Scalar = typename LDLTtype::Scalar;
12 using VectorXs = Eigen::Matrix<Scalar, -1, 1, Eigen::ColMajor>;
13 using MatrixXs = Eigen::Matrix<Scalar, -1, -1, Eigen::ColMajor>;
14
15 static LDLTtype &compute_proxy(LDLTtype &fac,
16 const context::ConstMatrixRef &mat) {
17 return fac.compute(mat);
18 }
19
20 static bool solveInPlace_proxy(const LDLTtype &fac,
21 context::MatrixRef rhsAndX) {
22 return fac.solveInPlace(rhsAndX);
23 }
24
25 template <typename RhsType>
26 static auto solve(const LDLTtype &fac, RhsType &rhs) {
27 return fac.solve(rhs);
28 }
29
30 template <typename... Args> void visit(bp::class_<Args...> &cl) const {
31 cl.def("compute", compute_proxy, bp::return_internal_reference<>(),
32 ("self"_a, "mat"))
33 .def("solveInPlace", solveInPlace_proxy, ("self"_a, "rhsAndX"))
34 .def("solve", solve<Eigen::Ref<const VectorXs>>, ("self"_a, "rhs"))
35 .def("solve", solve<Eigen::Ref<const MatrixXs>>, ("self"_a, "rhs"))
36 .def("matrixLDLT", &LDLTtype::matrixLDLT,
37 bp::return_value_policy<bp::return_by_value>(), "self"_a,
38 "Get the current value of the decomposition matrix. This makes a "
39 "copy.");
40 }
41};
42
44 using context::Scalar;
45 using context::VectorXs;
46
47 using DenseLDLT = linalg::DenseLDLT<Scalar>;
48 bp::class_<DenseLDLT>("DenseLDLT", bp::no_init).def(LDLTVisitor<DenseLDLT>());
49
51 bp::class_<BunchKaufman_t>("BunchKaufman", bp::no_init)
52 .def(bp::init<>("self"_a))
54 .def("pivots", &BunchKaufman_t::pivots, bp::return_internal_reference<>())
55 .def(
56 "subdiag",
57 +[](const BunchKaufman_t &bk) -> VectorXs { return bk.subdiag(); });
58
59 using BlockLDLT = linalg::BlockLDLT<Scalar>;
60 bp::class_<BlockLDLT>("BlockLDLT", bp::no_init)
62 .def("print_sparsity", &BlockLDLT::print_sparsity, "self"_a,
63 "Print the sparsity pattern of the matrix to factorize.");
64#ifdef PROXSUITE_NLP_USE_PROXSUITE_LDLT
65 using ProxSuiteLDLT = linalg::ProxSuiteLDLTWrapper<Scalar>;
66 bp::class_<ProxSuiteLDLT>(
67 "ProxSuiteLDLT", "Wrapper around ProxSuite's custom LDLT.", bp::no_init)
69#endif
70}
71
72} // namespace python
73} // namespace nlp
74} // namespace proxsuite
Utility function to allocate an LDLT solver for the Newton iterations.
Main package namespace.
Definition bcl-params.hpp:5
Block sparsity-aware LDLT factorization algorithm.
A fast, recursive divide-and-conquer LDLT algorithm.
Definition dense.hpp:164
static bool solveInPlace_proxy(const LDLTtype &fac, context::MatrixRef rhsAndX)
Eigen::Matrix< Scalar, -1, 1, Eigen::ColMajor > VectorXs
typename LDLTtype::Scalar Scalar
static auto solve(const LDLTtype &fac, RhsType &rhs)
Eigen::Matrix< Scalar, -1, -1, Eigen::ColMajor > MatrixXs
static LDLTtype & compute_proxy(LDLTtype &fac, const context::ConstMatrixRef &mat)
void visit(bp::class_< Args... > &cl) const