MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::mat::coordinate2D< Value, Parameters > Class Template Reference

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

Detailed Description

template<typename Value, typename Parameters = parameters<>>
class mtl::mat::coordinate2D< Value, Parameters >

COO sparse matrix: stores (row, col, value) triplets.

Supports unordered insertion, sorting, and compression to compressed2D.

Member Typedef Documentation

◆ const_reference

template<typename Value, typename Parameters = parameters<>>
using mtl::mat::coordinate2D< Value, Parameters >::const_reference = const Value&

◆ reference

template<typename Value, typename Parameters = parameters<>>
using mtl::mat::coordinate2D< Value, Parameters >::reference = Value&

◆ size_type

template<typename Value, typename Parameters = parameters<>>
using mtl::mat::coordinate2D< Value, Parameters >::size_type = typename Parameters::size_type

◆ triplet_type

template<typename Value, typename Parameters = parameters<>>
using mtl::mat::coordinate2D< Value, Parameters >::triplet_type = std::tuple<size_type, size_type, Value>

◆ value_type

template<typename Value, typename Parameters = parameters<>>
using mtl::mat::coordinate2D< Value, Parameters >::value_type = Value

Constructor & Destructor Documentation

◆ coordinate2D() [1/2]

template<typename Value, typename Parameters = parameters<>>
mtl::mat::coordinate2D< Value, Parameters >::coordinate2D ( )
inline

Default: empty 0x0.

◆ coordinate2D() [2/2]

template<typename Value, typename Parameters = parameters<>>
mtl::mat::coordinate2D< Value, Parameters >::coordinate2D ( size_type nrows,
size_type ncols )
inline

Empty nrows x ncols matrix.

Member Function Documentation

◆ compress()

template<typename Value, typename Parameters = parameters<>>
compressed2D< Value, Parameters > mtl::mat::coordinate2D< Value, Parameters >::compress ( ) const
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.

◆ entries()

template<typename Value, typename Parameters = parameters<>>
const std::vector< triplet_type > & mtl::mat::coordinate2D< Value, Parameters >::entries ( ) const
inline

◆ insert()

template<typename Value, typename Parameters = parameters<>>
void mtl::mat::coordinate2D< Value, Parameters >::insert ( size_type r,
size_type c,
Value v )
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).

◆ is_sorted()

template<typename Value, typename Parameters = parameters<>>
bool mtl::mat::coordinate2D< Value, Parameters >::is_sorted ( ) const
inline

◆ nnz()

template<typename Value, typename Parameters = parameters<>>
size_type mtl::mat::coordinate2D< Value, Parameters >::nnz ( ) const
inline

◆ num_cols()

template<typename Value, typename Parameters = parameters<>>
size_type mtl::mat::coordinate2D< Value, Parameters >::num_cols ( ) const
inline

◆ num_rows()

template<typename Value, typename Parameters = parameters<>>
size_type mtl::mat::coordinate2D< Value, Parameters >::num_rows ( ) const
inline

◆ operator()()

template<typename Value, typename Parameters = parameters<>>
value_type mtl::mat::coordinate2D< Value, Parameters >::operator() ( size_type r,
size_type c ) const
inline

◆ ref_entries()

template<typename Value, typename Parameters = parameters<>>
const std::vector< triplet_type > & mtl::mat::coordinate2D< Value, Parameters >::ref_entries ( ) const
inline

Raw access to the (row, col, value) triplets (unsorted unless sort()ed).

◆ reserve()

template<typename Value, typename Parameters = parameters<>>
void mtl::mat::coordinate2D< Value, Parameters >::reserve ( size_type nnz)
inline

Reserve space for nnz entries.

◆ size()

template<typename Value, typename Parameters = parameters<>>
size_type mtl::mat::coordinate2D< Value, Parameters >::size ( ) const
inline

◆ sort()

template<typename Value, typename Parameters = parameters<>>
void mtl::mat::coordinate2D< Value, Parameters >::sort ( )
inline

Sort entries by (row, col) in-place.

Stable: duplicates of one position keep their insertion order, so compress() sums them in that order.


The documentation for this class was generated from the following file: