41#ifndef __ADS_SparseMatrix
42 #define __ADS_SparseMatrix
73class OrthogonalIterator
76 using reference = std::pair< std::size_t , double >;
77 using value_type = reference;
78 using difference_type = std::ptrdiff_t;
79 using iterator_concept = std::forward_iterator_tag;
80 using iterator_category = std::input_iterator_tag;
82 OrthogonalIterator(
void ) =
default;
83 OrthogonalIterator(
const std::vector< Node > * N ,
long q ,
bool byRow )
84 : f_N( N ) , f_q( q ) , f_row( byRow ) { }
87 reference operator*(
void )
const {
88 const Node & x = ( *f_N )[ f_q ];
89 return( reference( f_row ? x.col : x.row , x.val ) );
91 OrthogonalIterator & operator++(
void ) {
92 f_q = f_row ? ( *f_N )[ f_q ].right : ( *f_N )[ f_q ].down;
95 OrthogonalIterator operator++(
int ) {
100 bool operator==(
const OrthogonalIterator & o )
const {
101 return( f_q == o.f_q );
105 const std::vector< Node > * f_N =
nullptr;
128 [[nodiscard]] std::size_t
rows(
void )
const;
130 [[nodiscard]] std::size_t
cols(
void )
const;
138 [[nodiscard]]
double get( std::size_t i , std::size_t j )
const;
163 void set( std::size_t i , std::size_t j ,
double v );
167 [[nodiscard]] std::vector< std::pair< std::size_t , double > >
168 row( std::size_t i )
const;
172 [[nodiscard]] std::vector< std::pair< std::size_t , double > >
173 col( std::size_t j )
const;
204 void pivot( std::size_t r , std::size_t c ,
double eps = 0 );
228 [[nodiscard]] std::ranges::subrange< const_iterator >
233 [[nodiscard]] std::ranges::subrange< const_iterator >
239 [[nodiscard]] std::pair< long , long > findInRow( std::size_t i ,
240 std::size_t j )
const;
242 [[nodiscard]]
long beforeInCol( std::size_t i , std::size_t j )
const;
245 [[nodiscard]]
bool linked(
void )
const;
250 std::vector< Node > f_N;
251 std::vector< long > f_freeNodes;
252 std::size_t f_nnz = 0;
264#include "ADS/numeric/impl/SparseMatrix.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
std::ranges::subrange< const_iterator > rowEntries(std::size_t i) const
the nonzeros of the row as (column, value), by column
void set(std::size_t i, std::size_t j, double v)
sets the entry to , removing its node if is 0
std::vector< std::pair< std::size_t, double > > col(std::size_t j) const
the nonzeros of the column , by row
detail::OrthogonalIterator< Node > const_iterator
Definition SparseMatrix.h:224
std::vector< std::pair< std::size_t, double > > row(std::size_t i) const
the nonzeros of the row , by column
SparseMatrix(std::size_t m, std::size_t n)
the zero matrix of rows and columns, the head nodes alone
std::size_t cols(void) const
the number of columns
std::size_t nonzeros(void) const
the number of nonzero entries
std::size_t rows(void) const
the number of rows
std::ranges::subrange< const_iterator > colEntries(std::size_t j) const
the nonzeros of the column as (row, value), by row
void pivot(std::size_t r, std::size_t c, double eps=0)
the pivot step on the entry ; the entries of absolute value at most vanish
double get(std::size_t i, std::size_t j) const
the entry , 0 if it has no node, by a walk of the row