a sparse \( m \times n \) matrix of values T in compressed sparse rows, the columns of the type I and the offsets of the rows of the type P
More...
#include <ADS/numeric/CsrMatrix.h>
|
| using | Value = T |
| | the type of the values
|
| using | Index = I |
| | the type of the columns
|
| using | Offset = P |
| | the type of the offsets of the rows
|
| using | Triplet = std::tuple< std::size_t , std::size_t , T > |
| | an entry \( ( i , j , v ) \)
|
|
| | BasicCsrMatrix (std::size_t m=0, std::size_t n=0) |
| | the \( m \times n \) zero matrix
|
| | BasicCsrMatrix (std::size_t m, std::size_t n, std::vector< Triplet > E) |
| | the \( m \times n \) matrix of the triplets \( ( i , j , v ) \), the values of equal places summed
|
| | BasicCsrMatrix (const SparseMatrix &S) |
| | the matrix of the orthogonal lists of the book, row by row
|
| std::size_t | rows (void) const |
| | the number \( m \) of rows
|
| std::size_t | cols (void) const |
| | the number \( n \) of columns
|
| std::size_t | nonzeros (void) const |
| | the number \( \mathit{nnz} \) of the entries kept
|
| T | get (std::size_t i, std::size_t j) const |
| | the entry \( ( i , j ) \), by a binary search in the row
|
| std::vector< T > | multiply (const std::vector< T > &x) const |
| | the product \( y = A x \), a new vector
|
| void | multiply (const T *x, T *y) const |
| | the product \( y = A x \) into \( y \), which must have \( m \) entries
|
| BasicCsrMatrix | transpose (void) const |
| | the transpose, \( n \times m \)
|
| const P * | rowStart (void) const |
| | the \( m + 1 \) offsets of the rows
|
| const I * | columns (void) const |
| | the column of each nonzero, row by row
|
| const T * | values (void) const |
| | the value of each nonzero, row by row
|
| bool | operator== (const BasicCsrMatrix &) const =default |
| | true if the two matrices have the same sizes and the same entries kept
|
| template<class A> |
| void | persist (A &a) |
| | the members written to, or read from, the archive \( a \) [see Persistence.h]
|
|
| static constexpr std::uint64_t | persistTag (void) |
| | the types of the values, of the columns and of the offsets, in a file
|
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
class ADS::BasicCsrMatrix< T, I, P >
a sparse \( m \times n \) matrix of values T in compressed sparse rows, the columns of the type I and the offsets of the rows of the type P
◆ Index
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
◆ Offset
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the type of the offsets of the rows
◆ Triplet
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
an entry \( ( i , j , v ) \)
◆ Value
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
◆ BasicCsrMatrix() [1/3]
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the \( m \times n \) zero matrix
◆ BasicCsrMatrix() [2/3]
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the \( m \times n \) matrix of the triplets \( ( i , j , v ) \), the values of equal places summed
In pseudocode (Saad, section 3.4, beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{CsrMatrix}( m , n , T ) \cr
2 & \quad \mathit{row}[ i + 1 ] \gets \text{the number of the triplets}
\text{ of the row } i \text{, for each } i \cr
3 & \quad \mathit{row} \gets \text{its prefix sums}\quad \triangleright
\ \text{the counting sort} \cr
4 & \quad E \gets \text{the pairs } ( j , v ) \text{ of } T \text{ put }
\text{by row at the offsets} \cr
5 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ m - 1\ \textbf{do} \cr
6 & \qquad \text{sort the pairs of the row } i \text{ by column};
\ \mathit{row}[ i ] \gets | \mathit{col} | \cr
7 & \qquad \text{append them to } \mathit{col} \text{ and }
\mathit{val} \text{, a repeated column added to the last} \cr
8 & \quad \mathit{row}[ m ] \gets | \mathit{col} |
\end{array}}
\]
- Precondition
- \( i < m \) and \( j < n \) for each triplet, the columns fit I and the number of the triplets fits P
◆ BasicCsrMatrix() [3/3]
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the matrix of the orthogonal lists of the book, row by row
- Precondition
- the columns fit I and the nonzeros P
◆ cols()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the number \( n \) of columns
◆ columns()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the column of each nonzero, row by row
◆ get()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the entry \( ( i , j ) \), by a binary search in the row
- Precondition
- \( i < m \) and \( j < n \)
◆ multiply() [1/2]
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the product \( y = A x \), a new vector
- Precondition
- \( x \) has \( n \) entries
◆ multiply() [2/2]
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the product \( y = A x \) into \( y \), which must have \( m \) entries
In pseudocode (Saad, section 3.4, beyond the book), one pass on the nonzeros:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{multiply}( x , y ) \cr
2 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ m - 1\ \textbf{do} \cr
3 & \qquad y_i \gets \sum_{p = \mathit{row}[ i ]}^{\mathit{row}[ i + 1 ]
- 1} \mathit{val}[ p ] \, x_{\mathit{col}[ p ]}
\end{array}}
\]
- Precondition
- \( x \) has \( n \) entries and \( y \) \( m \) entries, apart from \( x \)
◆ nonzeros()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the number \( \mathit{nnz} \) of the entries kept
◆ operator==()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
true if the two matrices have the same sizes and the same entries kept
◆ persist()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
template<class A>
the members written to, or read from, the archive \( a \) [see Persistence.h]
◆ persistTag()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
|
|
inlinestaticnodiscardconstexpr |
the types of the values, of the columns and of the offsets, in a file
◆ rows()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the number \( m \) of rows
◆ rowStart()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the \( m + 1 \) offsets of the rows
◆ transpose()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the transpose, \( n \times m \)
In pseudocode (beyond the book), by a counting sort on the columns, stable on the rows:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{transpose}() \cr
2 & \quad \mathit{trow} \gets \text{the prefix sums of the counts of }
\text{the columns} \cr
3 & \quad \mathit{at} \gets \mathit{trow} \cr
4 & \quad \textbf{if}\ \text{the rows span columns far apart}
\ \textbf{then} \cr
5 & \qquad \text{scatter the entries, in the order of the rows, into }
\text{256 buckets of columns} \cr
6 & \quad \textbf{foreach}\ \text{entry } ( i , j , v ) \text{ by row, }
\text{or by bucket}\ \textbf{do} \cr
7 & \qquad q \gets \mathit{at}[ j ];\ \mathit{at}[ j ] \gets q + 1;
\ \mathit{tcol}[ q ] \gets i;\ \mathit{tval}[ q ] \gets v \cr
8 & \quad \textbf{return}\ ( \mathit{trow} , \mathit{tcol} ,
\mathit{tval} )
\end{array}}
\]
- Precondition
- the rows fit I
◆ values()
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
the value of each nonzero, row by row
◆ persistName
template<class T = double, std::integral I = std::uint32_t, std::integral P = detail::CsrOffset< I >>
The documentation for this class was generated from the following file: