64 template <
typename T >
80 template <
typename T >
94 push_element( j, value );
104 if( nb_elements_ == capacity_ )
108 Element& elt = elements_[nb_elements_++];
113 index_t
find( index_t j )
const 115 for(
auto e :
range( nb_elements_ ) )
117 if( elements_[e].
index == j )
127 for(
auto e :
range( nb_elements_ ) )
129 if( elements_[e].
index == j )
142 return std::make_tuple(
false, T() );
145 return std::make_tuple(
true, value );
151 return elements_[e].value;
157 return elements_[e].index;
163 return elements_[i].value;
174 auto new_elements =
new Element[new_capacity];
176 elements_.get(), elements_.get() + nb_elements_, new_elements );
177 elements_.reset( new_elements );
183 capacity_ = capacity_ * 2;
184 reallocate( capacity_ );
188 std::unique_ptr< Element[] > elements_{};
189 index_t nb_elements_{ 0 };
190 index_t capacity_{ 4 };
199 template <
typename T,
typename RowType >
207 : is_symmetrical_( is_symmetrical )
219 bool exist( index_t i, index_t j )
const 222 return rows_[i].exist( j );
233 return rows_[i].nb_elements();
244 return rows_[i].index( e );
256 index_t i, index_t j )
const 259 index_t
index = rows_[i].find( j );
260 return std::make_tuple( index != NO_ID, index );
287 return is_symmetrical_;
300 rows_.reset(
new Row[ni] );
320 std::unique_ptr< Row[] > rows_{};
321 index_t ni_{ 0 }, nj_{ 0 };
329 template <
typename T,
331 2 *
sizeof( T ) <= 2 *
sizeof( index_t ) +
sizeof( T ) ) >
339 template <
typename T >
357 this->rows_[i].set_element( j, value );
358 if( this->is_symmetrical_ )
360 this->rows_[j].set_element( i, value );
373 this->rows_[i].push_element( j, value );
374 if( this->is_symmetrical_ )
376 this->rows_[j].push_element( i, value );
391 return this->rows_[i].get_element( j );
403 return this->rows_[i][e];
414 template <
typename T >
434 if( this->exist( i, j ) )
436 value_id = get_value_id( i, j );
437 values_[value_id] =
value;
441 values_.push_back( value );
442 value_id = values_.size() - 1;
444 this->rows_[i].set_element( j, value_id );
445 if( this->is_symmetrical_ )
447 this->rows_[j].set_element( i, value_id );
460 bool value_exists{
false };
462 std::tie( value_exists, value_id ) =
463 this->rows_[i].get_element( j );
468 return values_[value_id];
480 index_t value_id = this->rows_[i][e];
481 return values_[value_id];
487 return this->rows_[i].find( j );
491 std::deque< T > values_{};
496 template <
typename T >
501 std::vector< T > result( mat1.
ni(), 0 );
507 i_j_result *= mat2[j];
508 result[i] += i_j_result;
void push_element(index_t i, index_t j, const T &value)
#define ringmesh_disable_copy_and_move(Class)
void reallocate(index_t new_capacity)
std::tuple< bool, T > get_element(index_t j) const
static const index_t NOT_USED
SparseMatrix(bool is_symetrical=false)
void ringmesh_unused(const T &)
index_t index(index_t e) const
MatrixType
enum of MatrixType, This is useful to further specialize the template in the future ...
T get_element_in_line(index_t i, index_t e) const
void set_element(index_t i, index_t j, const T &value)
T get_element_in_line(index_t i, index_t e) const
void set_element(index_t i, index_t j, const T &value)
void set_element(index_t j, const T &value)
SparseMatrixImpl(bool is_symmetrical=false)
bool exist(index_t i, index_t j) const
T get_element(index_t i, index_t j) const
index_t find(const container &in, const T &value)
Returns the position of the first entity matching.
index_t get_column_in_line(index_t i, index_t e) const
gets the j that correspond to the given index within the row
SparseMatrix(bool is_symetrical=false)
T get_element_in_line(index_t i, index_t e) const
Basic "Row" of the matrix, this stores the elements of the matrix in a line-oriented way...
Basic container for the sparse matrix, i.e. the "elements".
std::tuple< bool, index_t > get_index_in_line(index_t i, index_t j) const
gets the rows_ index corresponding to a given i-j couple
void push_element(index_t j, const T &value)
T & operator[](index_t i) const
#define ringmesh_assert(x)
index_t get_value_id(index_t i, index_t j)
index_t get_nb_elements_in_line(index_t i) const
gets number of elements within a row
void build_matrix(index_t ni, index_t nj)
T element(index_t e) const
Classes to build GeoModel from various inputs.
bool is_symmetrical() const
index_t nb_elements() const
std::tuple< bool, T > get_element(index_t i, index_t j) const
This is the parent class for sparse matrices, the main difference between light and heavy type matric...
index_t find(index_t j) const
std::vector< T > product_matrix_by_vector(const SparseMatrix< T, light > &mat1, const std::vector< T > &mat2)
void parallel_for(index_t size, const ACTION &action)
#define ringmesh_assert_not_reached