proxsuite-nlp  0.11.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
 
Loading...
Searching...
No Matches
block-ldlt.hxx
Go to the documentation of this file.
1
5#pragma once
6
7#include "./block-ldlt.hpp"
8
9namespace proxsuite {
10namespace nlp {
11namespace linalg {
12
13template <typename Scalar>
14void BlockLDLT<Scalar>::setBlockPermutation(isize const *new_perm) {
15 SymbolicBlockMatrix in(m_structure.copy());
16 const isize n = m_structure.nsegments();
17 if (new_perm != nullptr)
18 std::copy_n(new_perm, n, m_perm.data());
19 m_structure.performed_llt = false;
20 symbolic_deep_copy(in, m_structure, m_perm.data());
21 analyzePattern(); // call manually
22 updateBlockPermutationMatrix(in);
23}
24
25template <typename Scalar>
27 SymbolicBlockMatrix in(m_structure.copy());
28 m_structure.brute_force_best_permutation(in, m_perm.data(), m_iwork.data());
29 symbolic_deep_copy(in, m_structure, m_perm.data());
31 updateBlockPermutationMatrix(in);
32 return *this;
33}
34
35template <typename Scalar> bool BlockLDLT<Scalar>::analyzePattern() {
36 if (m_structure.performed_llt)
37 return true;
38 bool flag = m_structure.llt_in_place();
39 m_struct_tr = m_structure.transpose();
40 return flag;
41}
42
43template <typename Scalar>
44BlockLDLT<Scalar> &BlockLDLT<Scalar>::updateBlockPermutationMatrix(
45 const SymbolicBlockMatrix &init) {
46 PermIdxType &indices = m_permutation.indices();
47 computeStartIndices(init);
48
49 isize idx = 0;
50 for (isize i = 0; i < (isize)nblocks(); ++i) {
51 auto j = (usize)m_perm[(usize)i];
52 isize len = init.segment_lens[j];
53 isize i0 = m_start_idx[j];
54 indices.segment(idx, len).setLinSpaced(i0, i0 + len - 1);
55 idx += len;
56 }
57 return *this;
58}
59
60template <typename Scalar>
61typename BlockLDLT<Scalar>::MatrixXs
62BlockLDLT<Scalar>::reconstructedMatrix() const {
63 MatrixXs res(m_matrix.rows(), m_matrix.cols());
64 res.setIdentity();
65 MatrixXs mat = m_matrix.template selfadjointView<Eigen::Lower>();
66 backend::dense_ldlt_reconstruct<Scalar>(mat, res);
67 res.noalias() = permutationP() * res;
68 res.noalias() = res * permutationP().transpose();
69 return res;
70}
71
72template <typename Scalar>
73template <typename Derived>
74bool BlockLDLT<Scalar>::solveInPlace(Eigen::MatrixBase<Derived> &b) const {
75
76 b.noalias() = permutationP().transpose() * b;
78 BlockTriL mat_blk_L(m_matrix, m_structure);
79 bool flag = mat_blk_L.solveInPlace(b);
80
81 using std::abs;
82 auto vecD(m_matrix.diagonal());
83 const Scalar tol = std::numeric_limits<Scalar>::min();
84 for (isize i = 0; i < vecD.size(); ++i) {
85 if (abs(vecD(i)) > tol)
86 b.row(i) /= vecD(i);
87 else
88 b.row(i).setZero();
89 }
90
92 BlockTriU mat_blk_U(m_matrix.transpose(), m_struct_tr);
93 flag |= mat_blk_U.solveInPlace(b);
94
96 b.noalias() = permutationP() * b;
97 return flag;
98}
99
100} // namespace linalg
101} // namespace nlp
102} // namespace proxsuite
Routines for block-sparse matrix LDLT factorisation.
#define PROXSUITE_NLP_NOMALLOC_END
Exiting performance-critical code.
Definition macros.hpp:23
#define PROXSUITE_NLP_NOMALLOC_BEGIN
Entering performance-critical code.
Definition macros.hpp:20
Specific linear algebra routines.
PROXSUITE_NLP_DLLAPI void symbolic_deep_copy(const SymbolicBlockMatrix &in, SymbolicBlockMatrix &out, isize const *perm=nullptr) noexcept
Deep copy of a SymbolicBlockMatrix, possibily with a permutation.
Main package namespace.
Definition bcl-params.hpp:5
Block sparsity-aware LDLT factorization algorithm.
BlockLDLT(isize size, SymbolicBlockMatrix const &structure)
The constructor copies the input matrix.
bool solveInPlace(Eigen::MatrixBase< Derived > &b) const
Solve for the right-hand side in-place.
void setBlockPermutation(isize const *new_perm=nullptr)
Calls updateBlockPermutationMatrix.
bool analyzePattern()
Analyze and factorize the block structure, if not done already.
BlockLDLT & findSparsifyingPermutation()
Find a sparsity-maximizing permutation of the blocks. This will also compute the symbolic factorizati...
Symbolic representation of the sparsity structure of a (square) block matrix.
bool solveInPlace(Eigen::MatrixBase< Derived > &bAndX) const
Block-sparse variant of the TriangularViewType::solveInPlace() method on standard dense matrices.