77#ifndef __ADS_CsrMatrix
78 #define __ADS_CsrMatrix
120 std::conditional_t< std::is_same_v< I , std::uint32_t > , std::size_t , I >;
126template<
class T = double , std::integral I = std::uint32_t ,
127 std::integral P = detail::CsrOffset< I > >
136 using Triplet = std::tuple< std::size_t , std::size_t , T >;
171 [[nodiscard]] std::size_t
rows(
void )
const {
return( f_m ); }
173 [[nodiscard]] std::size_t
cols(
void )
const {
return( f_n ); }
175 [[nodiscard]] std::size_t
nonzeros(
void )
const {
return( f_val.size() ); }
179 [[nodiscard]] T
get( std::size_t i , std::size_t j )
const;
183 [[nodiscard]] std::vector< T >
multiply(
const std::vector< T > & x )
const;
228 [[nodiscard]]
const P *
rowStart(
void )
const {
return( f_row.data() ); }
230 [[nodiscard]]
const I *
columns(
void )
const {
return( f_col.data() ); }
232 [[nodiscard]]
const T *
values(
void )
const {
return( f_val.data() ); }
243 [[nodiscard]]
static constexpr std::uint64_t
persistTag(
void ) {
244 return( detail::persistMix( {
sizeof( T ) , std::is_floating_point_v< T > ,
245 sizeof( I ) , std::is_signed_v< I > ,
246 sizeof( P ) , std::is_signed_v< P > } ) );
256 [[nodiscard]]
bool sorted(
void )
const;
259 using Vector = std::vector< U , MappableAllocator< U , false > >;
264 static constexpr bool fits( std::size_t x ) {
265 return( ( x == 0 ) ||
266 ( x - 1 <= std::size_t( std::numeric_limits< U >::max() ) ) );
287#include "ADS/numeric/impl/CsrMatrix.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The dense matrices by rows, beyond the book: DenseMatrix keeps the entries by rows in one contiguous...
A file mapped in memory, shared by the structures that are read from it in place [see Persistence....
A sparse matrix on orthogonal lists, beyond the book (section 2.2.6 of Knuth): each nonzero entry is ...
a sparse matrix of values T in compressed sparse rows, the columns of the type I and the offsets of ...
Definition CsrMatrix.h:129
std::vector< T > multiply(const std::vector< T > &x) const
the product , a new vector
const I * columns(void) const
the column of each nonzero, row by row
Definition CsrMatrix.h:230
std::size_t nonzeros(void) const
the number of the entries kept
Definition CsrMatrix.h:175
std::size_t rows(void) const
the number of rows
Definition CsrMatrix.h:171
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
void multiply(const T *x, T *y) const
the product into , which must have entries
T Value
the type of the values
Definition CsrMatrix.h:131
BasicCsrMatrix(const SparseMatrix &S)
the matrix of the orthogonal lists of the book, row by row
static constexpr std::uint64_t persistTag(void)
the types of the values, of the columns and of the offsets, in a file
Definition CsrMatrix.h:243
BasicCsrMatrix(std::size_t m, std::size_t n, std::vector< Triplet > E)
the matrix of the triplets , the values of equal places summed
P Offset
the type of the offsets of the rows
Definition CsrMatrix.h:133
const P * rowStart(void) const
the offsets of the rows
Definition CsrMatrix.h:228
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition CsrMatrix.h:240
T get(std::size_t i, std::size_t j) const
the entry , by a binary search in the row
const T * values(void) const
the value of each nonzero, row by row
Definition CsrMatrix.h:232
I Index
the type of the columns
Definition CsrMatrix.h:132
std::tuple< std::size_t, std::size_t, T > Triplet
an entry
Definition CsrMatrix.h:136
bool operator==(const BasicCsrMatrix &) const =default
true if the two matrices have the same sizes and the same entries kept
BasicCsrMatrix transpose(void) const
the transpose,
BasicCsrMatrix(std::size_t m=0, std::size_t n=0)
the zero matrix
std::size_t cols(void) const
the number of columns
Definition CsrMatrix.h:173
a sparse matrix on orthogonal circular lists
Definition SparseMatrix.h:119
BasicCsrMatrix<> CsrMatrix
the matrix of doubles of 32-bit columns and std::size_t offsets
Definition CsrMatrix.h:277