proxsuite-nlp  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear programming on manifolds.
Loading...
Searching...
No Matches
block-kind.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include "proxsuite-nlp/config.hpp"
9
10#include <Eigen/Core>
11#include <numeric>
12#include <vector>
13
14namespace proxsuite {
15namespace nlp {
16namespace linalg {
17
18using isize = Eigen::Index;
19using usize = std::make_unsigned<isize>::type;
20
34
36PROXSUITE_NLP_DLLAPI BlockKind trans(BlockKind a) noexcept;
37
39PROXSUITE_NLP_DLLAPI BlockKind add(BlockKind a, BlockKind b) noexcept;
40
42PROXSUITE_NLP_DLLAPI BlockKind mul(BlockKind a, BlockKind b) noexcept;
43
48struct PROXSUITE_NLP_DLLAPI SymbolicBlockMatrix {
55 bool performed_llt = false;
56
57private:
58 void alloc() {
59 m_data = new BlockKind[usize(size())];
60 segment_lens = new isize[usize(nsegments())];
61 }
62
63public:
67 : segments_count(nc), outer_stride(os) {
68 alloc();
69 }
72 : m_data(data), segment_lens(lens), segments_count(nc), outer_stride(os) {
73 }
77 SymbolicBlockMatrix(const std::vector<isize> &lens)
78 : segments_count(static_cast<isize>(lens.size())) {
79 outer_stride = segments_count;
80
81 alloc();
82
83 std::fill_n(m_data, size(), BlockKind::Dense);
84 std::copy_n(lens.begin(), nsegments(), segment_lens);
85 }
86
89
90 isize nsegments() const noexcept { return segments_count; }
91 isize size() const noexcept { return segments_count * outer_stride; }
92 BlockKind *ptr(isize i, isize j) noexcept {
93 return m_data + (i + j * outer_stride);
94 }
95 BlockKind const *ptr(isize i, isize j) const noexcept {
96 return m_data + (i + j * outer_stride);
97 }
98
103 BlockKind &operator()(isize i, isize j) noexcept { return *ptr(i, j); }
105 const BlockKind &operator()(isize i, isize j) const noexcept {
106 return *ptr(i, j);
107 }
108
114 Eigen::ComputationInfo
116 isize *iwork);
117 bool check_if_symmetric() const noexcept;
118 isize count_nnz() const noexcept;
122 bool llt_in_place() noexcept;
123
124 SymbolicBlockMatrix transpose() const {
125 const auto &self = *this;
126 SymbolicBlockMatrix out(self.copy());
127 for (isize i = 0; i < nsegments(); ++i) {
128 for (isize j = 0; j < nsegments(); ++j) {
129 out(i, j) = trans(self(j, i));
130 }
131 }
132 return out;
133 }
134};
135
136PROXSUITE_NLP_DLLAPI void
138
140PROXSUITE_NLP_DLLAPI void
142 isize const *perm = nullptr) noexcept;
143
144} // namespace linalg
145} // namespace nlp
146} // namespace proxsuite
PROXSUITE_NLP_DLLAPI BlockKind trans(BlockKind a) noexcept
BlockKind of the transpose of a matrix.
std::make_unsigned< isize >::type usize
PROXSUITE_NLP_DLLAPI void print_sparsity_pattern(const SymbolicBlockMatrix &smat) noexcept
PROXSUITE_NLP_DLLAPI BlockKind add(BlockKind a, BlockKind b) noexcept
BlockKind of the addition of two matrices - given by their BlockKind.
PROXSUITE_NLP_DLLAPI BlockKind mul(BlockKind a, BlockKind b) noexcept
BlockKind of the product of two matrices.
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.
BlockKind
Kind of matrix block: zeros, diagonal, lower/upper triangular or dense.
@ Dense
There is no known prior structure; assume a dense block.
@ Diag
The block is diagonal.
@ Zero
All entries in the block are zero.
@ TriL
The block is lower-triangular.
@ TriU
The block is upper-triangular.
Main package namespace.
Definition bcl-params.hpp:5
Symbolic representation of the sparsity structure of a (square) block matrix.
const BlockKind & operator()(isize i, isize j) const noexcept
SymbolicBlockMatrix(const std::vector< isize > &lens)
SymbolicBlockMatrix(SymbolicBlockMatrix const &other)=default
Shallow copy constructor.
SymbolicBlockMatrix(isize nc, isize os)
Allocating constructor.
SymbolicBlockMatrix(BlockKind *data, isize *lens, isize nc, isize os)
Constructor from external data.
SymbolicBlockMatrix submatrix(isize i, isize n) noexcept
BlockKind const * ptr(isize i, isize j) const noexcept
BlockKind & operator()(isize i, isize j) noexcept
Get a reference to the block in position (i, j).
Eigen::ComputationInfo brute_force_best_permutation(SymbolicBlockMatrix const &in, isize *best_perm, isize *iwork)
BlockKind * ptr(isize i, isize j) noexcept
SymbolicBlockMatrix & operator=(SymbolicBlockMatrix const &other)=default
SymbolicBlockMatrix copy() const
Deep copy.