1#ifndef ADOLC_SPARSE_MATRIX_H
2#define ADOLC_SPARSE_MATRIX_H
53 : coords_{coords}, value_(
value) {}
70 double value() const noexcept {
return value_; }
101 : entries_(std::move(
entries)) {}
113 const std::array<CoordinateFormatTripled, N> &
entries) noexcept
137 size_t size()
const {
return entries_.size(); }
139 bool empty()
const {
return entries_.empty(); }
162 unsigned int rowIndex(
size_t idx)
const {
return entries_[idx].rowIndex(); }
168 unsigned int colIndex(
size_t idx)
const {
return entries_[idx].colIndex(); }
174 double value(
size_t idx)
const {
return entries_[idx].value(); }
198 const bool isDependentRow =
199 coords.
rowIndex_ <
static_cast<unsigned int>(depen);
200 const bool isIndependentCol =
201 coords.
colIndex_ <
static_cast<unsigned int>(indep);
203 if (isDependentRow && isIndependentCol)
205 else if (isDependentRow)
207 else if (isIndependentCol)
262 std::vector<double>
cz;
264 std::vector<double>
cy;
266 std::vector<double>
y;
268 std::vector<double>
z;
302 for (
size_t i = 0; i <
J.
size(); ++i) {
310 for (
size_t i = 0; i <
L.
size(); ++i) {
Owning sparse matrix container in coordinate-format.
Definition sparsematrix.h:81
const value_type & operator[](size_t idx) const
Read-only indexed access to one sparse entry.
Definition sparsematrix.h:187
void resize(size_t size)
Resize the number of stored entries.
Definition sparsematrix.h:146
size_t size() const
Get the number of stored nonzeros.
Definition sparsematrix.h:137
unsigned int colIndex(size_t idx) const
Get the column index of one stored entry.
Definition sparsematrix.h:168
SparseMatrix(const std::array< CoordinateFormatTripled, N > &entries) noexcept
Construct from an already prepared array of coordinate-format entries.
Definition sparsematrix.h:112
SparseMatrix & operator=(const SparseMatrix &other)=default
std::vector< value_type > storage_type
Definition sparsematrix.h:84
void push_back(CoordinateFormatTripled value)
Append one entry at the end of the sparse matrix.
Definition sparsematrix.h:155
const storage_type & entries() const
Get read-only access to the underlying entry storage.
Definition sparsematrix.h:134
SparseMatrix(const SparseMatrix &other)=default
bool empty() const
Check whether no entries are stored.
Definition sparsematrix.h:139
storage_type & entries()
Get mutable access to the underlying entry storage.
Definition sparsematrix.h:132
SparseMatrix(SparseMatrix &&other) noexcept=default
SparseMatrix(size_t size)
Construct a sparse matrix with storage for size entries.
Definition sparsematrix.h:123
void clear()
Remove all entries while keeping vector ownership.
Definition sparsematrix.h:148
SparseMatrix()=default
Construct an empty sparse matrix.
unsigned int rowIndex(size_t idx) const
Get the row index of one stored entry.
Definition sparsematrix.h:162
double value(size_t idx) const
Get the numerical value of one stored entry.
Definition sparsematrix.h:174
SparseMatrix(storage_type &&entries) noexcept
Construct from already prepared coordinate-format entries.
Definition sparsematrix.h:100
SparseMatrix & operator=(SparseMatrix &&other) noexcept=default
value_type & operator[](size_t idx)
Mutable indexed access to one sparse entry.
Definition sparsematrix.h:181
SparseANFBlock
Represents the different ANF blocks.
Definition sparsematrix.h:193
SparseANFBlock classifySparseANFBlock(CoordinateFormatTripled::Coordinates coords, int depen, int indep)
Definition sparsematrix.h:196
Definition adtl_indo.h:46
Base tag for abs-normal form shapes.
Definition absnormalformconcept.h:10
Stores the abs-normal form in sparse format.
Definition sparsematrix.h:247
Shape shape
Definition sparsematrix.h:250
void clear()
Clear all sparse blocks and dense vectors.
Definition sparsematrix.h:287
SparseMatrix L
Switching-equation block L = dz / d|z|.
Definition sparsematrix.h:259
std::vector< double > z
Switching-variable values at the evaluation point.
Definition sparsematrix.h:268
SparseMatrix Z
Switching-equation Jacobian block Z = dz / dx.
Definition sparsematrix.h:257
bool empty() const
Check whether all sparse blocks and dense vectors are empty.
Definition sparsematrix.h:282
SparseANF(SparseANF &&)=default
SparseMatrix J
Output block J = dy / d|z|.
Definition sparsematrix.h:255
void updateCz()
Compute cz = z - L|z| from the current data.
Definition sparsematrix.h:308
Shape dims() const
Definition sparsematrix.h:297
SparseMatrix Y
Output Jacobian block Y = dy / dx.
Definition sparsematrix.h:253
std::vector< double > y
Dependent values at the evaluation point.
Definition sparsematrix.h:266
std::vector< double > cy
Constant term of the dependent equations.
Definition sparsematrix.h:264
std::vector< double > cz
Constant term of the switching equations.
Definition sparsematrix.h:262
void updateCy()
Compute cy = y - J|z| from the current data.
Definition sparsematrix.h:300
SparseANF(Shape dims)
Definition sparsematrix.h:273
SparseANF & operator=(const SparseANF &)=default
SparseANF(const SparseANF &)=default
SparseANF & operator=(SparseANF &&)=default
void resize(Shape dims)
Resize sparse blocks according to the given block counts.
Definition sparsematrix.h:320
Nonzero counts for the four blocks of a sparse abs-normal form.
Definition sparsematrix.h:220
size_t z
Definition sparsematrix.h:223
size_t l
Definition sparsematrix.h:224
size_t y
Definition sparsematrix.h:221
size_t j
Definition sparsematrix.h:222
SparseShape(size_t y, size_t j, size_t z, size_t l)
Definition sparsematrix.h:227