a sparse matrix by rows, with indices of type I and values of type V, whose rows are appended and removed
More...
#include <ADS/numeric/DynamicCsr.h>
|
| using | Index = I |
| | the type of the indices
|
| using | Value = V |
| | the type of the values
|
|
| | DynamicCsr (void) |
| | the matrix of no rows
|
| std::size_t | rows (void) const |
| | the number of the rows
|
| std::size_t | nonzeros (void) const |
| | the number of the entries
|
| bool | empty (void) const |
| | true if the matrix has no row
|
| void | reserve (std::size_t r, std::size_t z) |
| | room for \( r \) rows and \( z \) entries
|
| void | clear (void) |
| | removes all the rows, keeping the memory
|
| std::size_t | append (std::span< const I > ind, std::span< const V > val) |
| | appends the row of the entries \( ( \mathit{ind}[ k ] , \mathit{val}[ k ] ) \); its index
|
| std::size_t | append (std::size_t r, const I *beg, const I *ind, const V *val) |
| | appends the \( r \) rows of a compressed form: the row \( k \) has the entries \( \mathit{beg}[ k ] - \mathit{beg}[ 0 ] \) to \( \mathit{beg}[ k + 1 ] - \mathit{beg}[ 0 ] \) of ind and val; the index of the first one
|
| template<std::ranges::contiguous_range R> |
| void | remove (const R &E) |
| | removes the rows of \( E \) (a contiguous range of integers, e.g., a std::vector), closing the gaps in one pass
|
| void | remove (std::size_t first, std::size_t last) |
| | removes the rows from \( \mathit{first} \) to \( \mathit{last} \), \( \mathit{last} \) excluded, by one erase of their entries and a shift of the starts after them
|
| std::span< const I > | indices (std::size_t i) const |
| | the minor indices of the row \( i \)
|
| std::span< const V > | values (std::size_t i) const |
| | the values of the row \( i \)
|
| std::span< V > | values (std::size_t i) |
| | the values of the row \( i \), to change in place
|
| const I * | beg (void) const |
| | the \( \mathrm{rows}() + 1 \) starts of the rows, the last one the number of the entries
|
| const I * | ind (void) const |
| | the minor index of each entry
|
| const V * | val (void) const |
| | the value of each entry
|
template<class I = int, class V = double>
class ADS::DynamicCsr< I, V >
a sparse matrix by rows, with indices of type I and values of type V, whose rows are appended and removed
◆ Index
template<class I = int, class V = double>
◆ Value
template<class I = int, class V = double>
◆ DynamicCsr()
template<class I = int, class V = double>
◆ append() [1/2]
template<class I = int, class V = double>
| std::size_t ADS::DynamicCsr< I, V >::append |
( |
std::size_t | r, |
|
|
const I * | beg, |
|
|
const I * | ind, |
|
|
const V * | val ) |
appends the \( r \) rows of a compressed form: the row \( k \) has the entries \( \mathit{beg}[ k ] - \mathit{beg}[ 0 ] \) to \( \mathit{beg}[ k + 1 ] - \mathit{beg}[ 0 ] \) of ind and val; the index of the first one
In pseudocode (beyond the book), the starts shifted by \( \delta = |\mathit{ind}| - \mathit{beg}'[ 0 ] \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{append}( r , \mathit{beg}' ,
\mathit{ind}' , \mathit{val}' ) \cr
2 & \quad \text{append the entries from } \mathit{beg}'[ 0 ] \text{ to }
\mathit{beg}'[ r ] \text{ of } \mathit{ind}' \text{ and }
\mathit{val}' \cr
3 & \quad \textbf{for}\ k \gets 1\ \textbf{to}\ r\ \textbf{do}
\ \text{append } \mathit{beg}'[ k ] + \delta \text{ to } \mathit{beg}
\cr
4 & \quad \textbf{return}\ \text{the index of the first row appended}
\end{array}}
\]
- Precondition
- beg is not decreasing
◆ append() [2/2]
template<class I = int, class V = double>
| std::size_t ADS::DynamicCsr< I, V >::append |
( |
std::span< const I > | ind, |
|
|
std::span< const V > | val ) |
appends the row of the entries \( ( \mathit{ind}[ k ] , \mathit{val}[ k ] ) \); its index
In pseudocode (beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{append}( \mathit{ind}' , \mathit{val}' )
\cr
2 & \quad \text{append } \mathit{ind}' \text{ to } \mathit{ind}
\text{ and } \mathit{val}' \text{ to } \mathit{val} \cr
3 & \quad \text{append } |\mathit{ind}| \text{ to } \mathit{beg} \cr
4 & \quad \textbf{return}\ \mathrm{rows}() - 1
\end{array}}
\]
- Precondition
- ind and val have the same length
◆ beg()
template<class I = int, class V = double>
the \( \mathrm{rows}() + 1 \) starts of the rows, the last one the number of the entries
◆ clear()
template<class I = int, class V = double>
removes all the rows, keeping the memory
◆ empty()
template<class I = int, class V = double>
true if the matrix has no row
◆ ind()
template<class I = int, class V = double>
the minor index of each entry
◆ indices()
template<class I = int, class V = double>
| std::span< const I > ADS::DynamicCsr< I, V >::indices |
( |
std::size_t | i | ) |
const |
|
nodiscard |
the minor indices of the row \( i \)
- Precondition
- \( i < \mathrm{rows}() \)
◆ nonzeros()
template<class I = int, class V = double>
the number of the entries
◆ remove() [1/2]
template<class I = int, class V = double>
template<std::ranges::contiguous_range R>
removes the rows of \( E \) (a contiguous range of integers, e.g., a std::vector), closing the gaps in one pass
In pseudocode (beyond the book), \( o \) the next entry written and \( \mathit{out} \) the next row:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{remove}( E ) \cr
2 & \quad \mathit{out} \gets E[ 0 ];\ o \gets \mathit{beg}[ \mathit{out}
] \cr
3 & \quad \textbf{for}\ i \gets E[ 0 ]\ \textbf{to}\ \mathrm{rows}() -
1\ \textbf{do} \cr
4 & \qquad \textbf{if}\ i \in E\ \textbf{then continue} \cr
5 & \qquad ( s , e ) \gets ( \mathit{beg}[ i ] , \mathit{beg}[ i + 1 ] )
;\ \mathit{beg}[ \mathit{out} ] \gets o;\ \mathit{out} \gets
\mathit{out} + 1 \cr
6 & \qquad \text{move the entries } s .. e - 1 \text{ to } o .. o + e -
s - 1;\ o \gets o + e - s \cr
7 & \quad \mathit{beg}[ \mathit{out} ] \gets o;\ \text{cut the vectors }
\text{after } \mathit{out} \text{ rows and } o \text{ entries}
\end{array}}
\]
- Precondition
- \( E \) is strictly increasing and below rows()
◆ remove() [2/2]
template<class I = int, class V = double>
| void ADS::DynamicCsr< I, V >::remove |
( |
std::size_t | first, |
|
|
std::size_t | last ) |
removes the rows from \( \mathit{first} \) to \( \mathit{last} \), \( \mathit{last} \) excluded, by one erase of their entries and a shift of the starts after them
- Precondition
- \( \mathit{first} \le \mathit{last} \le \mathrm{rows}() \)
◆ reserve()
template<class I = int, class V = double>
room for \( r \) rows and \( z \) entries
◆ rows()
template<class I = int, class V = double>
◆ val()
template<class I = int, class V = double>
◆ values() [1/2]
template<class I = int, class V = double>
the values of the row \( i \), to change in place
- Precondition
- \( i < \mathrm{rows}() \)
◆ values() [2/2]
template<class I = int, class V = double>
| std::span< const V > ADS::DynamicCsr< I, V >::values |
( |
std::size_t | i | ) |
const |
|
nodiscard |
the values of the row \( i \)
- Precondition
- \( i < \mathrm{rows}() \)
The documentation for this class was generated from the following file: