|
MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
|
COO sparse matrix: stores (row, col, value) triplets. More...
#include <coordinate2D.hpp>
Public Types | |
| using | value_type = Value |
| using | size_type = typename Parameters::size_type |
| using | const_reference = const Value& |
| using | reference = Value& |
| using | triplet_type = std::tuple<size_type, size_type, Value> |
Public Member Functions | |
| coordinate2D () | |
| Default: empty 0x0. | |
| coordinate2D (size_type nrows, size_type ncols) | |
| Empty nrows x ncols matrix. | |
| void | insert (size_type r, size_type c, Value v) |
| Insert a single entry (accumulates with existing entries on compress). | |
| void | reserve (size_type nnz) |
| Reserve space for nnz entries. | |
| value_type | operator() (size_type r, size_type c) const |
| size_type | num_rows () const |
| size_type | num_cols () const |
| size_type | size () const |
| size_type | nnz () const |
| const std::vector< triplet_type > & | ref_entries () const |
| Raw access to the (row, col, value) triplets (unsorted unless sort()ed). | |
| void | sort () |
| Sort entries by (row, col) in-place. | |
| bool | is_sorted () const |
| compressed2D< Value, Parameters > | compress () const |
| Convert to compressed2D, accumulating duplicate entries. | |
| const std::vector< triplet_type > & | entries () const |
COO sparse matrix: stores (row, col, value) triplets.
Supports unordered insertion, sorting, and compression to compressed2D.
| using mtl::mat::coordinate2D< Value, Parameters >::const_reference = const Value& |
| using mtl::mat::coordinate2D< Value, Parameters >::reference = Value& |
| using mtl::mat::coordinate2D< Value, Parameters >::size_type = typename Parameters::size_type |
| using mtl::mat::coordinate2D< Value, Parameters >::triplet_type = std::tuple<size_type, size_type, Value> |
| using mtl::mat::coordinate2D< Value, Parameters >::value_type = Value |
|
inline |
Default: empty 0x0.
|
inline |
Empty nrows x ncols matrix.
|
inline |
Convert to compressed2D, accumulating duplicate entries.
Duplicates are summed in insertion order (#825): the sort is stable, so the result is reproducible for rounding-sensitive and non-commutative values. It used to be std::sort, which put duplicates in an arbitrary order. After sort(), with no insert since, the entries are used as they are, with no copy and no sort.
Throws std::out_of_range (via detail::throw_or_abort) if an entry's row or column is outside the matrix, in every build: an O(nnz) pass, once per matrix (#825). Unchecked, a bad row was a heap write out of bounds below, at starts[r + 1]. A negative index is rejected too, for a signed Parameters::size_type.
|
inline |
|
inline |
Insert a single entry (accumulates with existing entries on compress).
The indices are not checked here: compress() checks every entry, in every build, once per matrix rather than once per insert (#825).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Raw access to the (row, col, value) triplets (unsorted unless sort()ed).
|
inline |
Reserve space for nnz entries.
|
inline |
|
inline |
Sort entries by (row, col) in-place.
Stable: duplicates of one position keep their insertion order, so compress() sums them in that order.