Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Matrix< Trow, Tcol, NumType > Class Template Reference

Sparse matrix with generic row and column domains. More...

#include <al-matrix.H>

Inheritance diagram for Aleph::Matrix< Trow, Tcol, NumType >:
[legend]
Collaboration diagram for Aleph::Matrix< Trow, Tcol, NumType >:
[legend]

Public Types

using RDomain = AlDomain< Trow >
 
using CDomain = AlDomain< Tcol >
 
using RDomainPtr = std::shared_ptr< RDomain >
 
using CDomainPtr = std::shared_ptr< CDomain >
 
using RCPair = std::pair< Trow, Tcol >
 
using Map = Aleph::HashMap< RCPair, NumType, MapODhash >
 
using ColVector = Vector< Trow, NumType >
 
using RowVector = Vector< Tcol, NumType >
 
typedef std::pair< RCPair, NumType > Pair
 Type alias for entries stored in the hash table: ((row,col), value).
 

Public Member Functions

const NumType & get_epsilon () const noexcept
 Return the epsilon value used for zero comparisons.
 
void set_epsilon (const NumType &e)
 Set the epsilon value for zero comparisons.
 
const RDomain & get_row_domain () const noexcept
 Return the row domain.
 
const CDomain & get_col_domain () const noexcept
 Return the column domain.
 
const RDomainPtr & get_row_domain_ptr () const noexcept
 Return the shared pointer to the row domain.
 
const CDomainPtr & get_col_domain_ptr () const noexcept
 Return the shared pointer to the column domain.
 
 Matrix (RDomainPtr rdomain, CDomainPtr cdomain, const NumType &e=default_epsilon)
 Construct an empty sparse matrix over the given domains (shared_ptr version).
 
 Matrix (const RDomain &rdomain, const CDomain &cdomain, const NumType &e=default_epsilon)
 Construct an empty sparse matrix over the given domains (reference version).
 
 Matrix (RDomain &&rdomain, CDomain &&cdomain, const NumType &e=default_epsilon)
 Construct an empty sparse matrix over domains of which one, or both, are temporary: the matrix keeps a copy of each temporary one, which lives as long as the matrix and those that share it.
 
 Matrix (RDomain &&rdomain, const CDomain &cdomain, const NumType &e=default_epsilon)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
 Matrix (const RDomain &rdomain, CDomain &&cdomain, const NumType &e=default_epsilon)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename R , typename C , typename... Rest>
requires (std::is_integral_v<std::remove_cvref_t<R>> or std::is_integral_v<std::remove_cvref_t<C>>)
 Matrix (R &&, C &&, Rest &&...)=delete
 A matrix needs domains: Matrix(IntRange(n), IntRange(m)), not Matrix(n, m), which would turn the numbers into empty domains.
 
 Matrix (RDomainPtr rdomain, CDomainPtr cdomain, std::initializer_list< std::initializer_list< NumType > > l, const NumType &e=default_epsilon) and AlOrderedDomainKey< Tcol >
 Construct a matrix from a 2D initializer list (shared_ptr version).
 
 Matrix (const RDomain &rdomain, const CDomain &cdomain, std::initializer_list< std::initializer_list< NumType > > l, const NumType &e=default_epsilon) and AlOrderedDomainKey< Tcol >
 Construct a matrix from a 2D initializer list (reference version).
 
 Matrix (RDomain &&rdomain, CDomain &&cdomain, std::initializer_list< std::initializer_list< NumType > > l, const NumType &e=default_epsilon) and AlOrderedDomainKey< Tcol >
 Construct a matrix from a 2D initializer list over domains of which one, or both, are temporary: the matrix keeps a copy of each temporary one.
 
 Matrix (RDomain &&rdomain, const CDomain &cdomain, std::initializer_list< std::initializer_list< NumType > > l, const NumType &e=default_epsilon) and AlOrderedDomainKey< Tcol >
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
 Matrix (const RDomain &rdomain, CDomain &&cdomain, std::initializer_list< std::initializer_list< NumType > > l, const NumType &e=default_epsilon) and AlOrderedDomainKey< Tcol >
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
 Matrix (RDomainPtr rdomain, CDomainPtr cdomain, const DynList< DynList< NumType > > &l, const NumType &e=default_epsilon) and AlOrderedDomainKey< Tcol >
 Construct a matrix from a list of lists (shared_ptr version).
 
 Matrix (const RDomain &rdomain, const CDomain &cdomain, const DynList< DynList< NumType > > &l, const NumType &e=default_epsilon) and AlOrderedDomainKey< Tcol >
 Construct a matrix from a list of lists (reference version).
 
 Matrix (RDomain &&rdomain, CDomain &&cdomain, const DynList< DynList< NumType > > &l, const NumType &e=default_epsilon) and AlOrderedDomainKey< Tcol >
 Construct a matrix from a list of lists over domains of which one, or both, are temporary: the matrix keeps a copy of each temporary one.
 
 Matrix (RDomain &&rdomain, const CDomain &cdomain, const DynList< DynList< NumType > > &l, const NumType &e=default_epsilon) and AlOrderedDomainKey< Tcol >
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
 Matrix (const RDomain &rdomain, CDomain &&cdomain, const DynList< DynList< NumType > > &l, const NumType &e=default_epsilon) and AlOrderedDomainKey< Tcol >
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
 Matrix (const Matrix &other)
 Copy constructor.
 
 Matrix (Matrix &&other) noexcept
 Move constructor.
 
Matrix & operator= (const Matrix &other)
 Copy assignment operator.
 
Matrix & operator= (Matrix &&other) noexcept
 Move assignment operator.
 
NumType get_entry (const Trow &row, const Tcol &col)
 Get an entry value (non-const version with lazy cleanup).
 
NumType get_entry (const Trow &row, const Tcol &col) const noexcept
 Get an entry value (const version, no cleanup).
 
void set_entry (const Trow &row, const Tcol &col, const NumType &val)
 Set an entry value.
 
Matrix< Tcol, Trow, NumType > transpose () const
 Compute the transpose of this matrix.
 
DynList< Trow > row_domain_list () const
 Return a sorted list of row domain keys.
 
DynList< Tcol > col_domain_list () const
 Return a sorted list of column domain keys.
 
DynList< NumType > get_row_as_list (const Trow &row) const
 Get a row as a list of values (in column order).
 
DynList< NumType > get_col_as_list (const Tcol &col) const
 Get a column as a list of values (in row order).
 
DynList< Vector< Tcol, NumType > > to_rowlist () const and AlOrderedDomainKey< Tcol >
 Return a list of vectors corresponding to the rows.
 
DynList< ColVector > to_collist () const and AlOrderedDomainKey< Tcol >
 Return a list of vectors corresponding to the columns.
 
Vector< Tcol, NumType > get_row_vector (const Trow &row) const
 Given a row, build a vector corresponding to the row.
 
Vector< Trow, NumType > get_col_vector (const Tcol &col) const
 Given a column, build a vector corresponding to the column.
 
Vector< Trow, NumType > mult_matrix_vector_linear_comb (const Vector< Tcol, NumType > &vec) const and AlMultiplicativeNumber< NumType >
 return this*vec in terms of linear combinations
 
Vector< Trow, NumType > mult_matrix_vector_sparse (const Vector< Tcol, NumType > &vec) const and AlMultiplicativeNumber< NumType >
 Matrix-vector multiplication using sparse iteration.
 
Vector< Tcol, NumType > mult_vector_matrix_linear_comb (const Vector< Trow, NumType > &vec) const and AlMultiplicativeNumber< NumType >
 return vec*this in terms of linear combinations
 
Vector< Trow, NumType > mult_matrix_vector_dot_product (const Vector< Tcol, NumType > &vec) const and AlMultiplicativeNumber< NumType >
 Matrix-vector multiplication using dot products.
 
Vector< Tcol, NumType > mult_vector_matrix_dot_product (const Vector< Trow, NumType > &vec) const and AlMultiplicativeNumber< NumType >
 Vector-matrix multiplication using dot products.
 
Vector< Trow, NumType > operator* (const Vector< Tcol, NumType > &vec) const and AlMultiplicativeNumber< NumType >
 Matrix-vector multiplication operator (uses linear combination method).
 
Matrix & set_vector_as_row (const Trow &row, const Vector< Tcol, NumType > &vec)
 Set a row from a vector.
 
Matrix & set_vector_as_col (const Tcol &col, const Vector< Trow, NumType > &vec)
 Set a column from a vector.
 
Matrix identity () const
 Create an identity matrix (only for square matrices).
 
Matrix & operator+= (const Matrix &m)
 Add another matrix to this one.
 
Matrix operator+ (const Matrix &m) const
 Matrix addition operator.
 
Matrix & operator-= (const Matrix &m)
 Subtract another matrix from this one.
 
Matrix operator- (const Matrix &m) const
 Matrix subtraction operator.
 
Matrix & mult_by_scalar (const NumType &scalar)
 Multiply all entries by a scalar (in-place).
 
template<typename T2row , typename T2col >
requires AlAdditiveNumber<NumType>
Matrix< Trow, T2col, NumType > vector_matrix_mult (const Matrix< T2row, T2col, NumType > &m) const and AlMultiplicativeNumber< NumType >
 Matrix multiplication using row-vector times matrix approach.
 
template<typename T2row , typename T2col >
requires AlAdditiveNumber<NumType>
Matrix< Trow, T2col, NumType > matrix_vector_mult (const Matrix< T2row, T2col, NumType > &m) const and AlMultiplicativeNumber< NumType >
 Matrix multiplication using matrix times column-vector approach.
 
void print () const and AlStreamable< Tcol > and AlStreamable< NumType >
 Print non-zero entries to stdout.
 
std::string to_str () const and AlOrderedDomainKey< Tcol > and AlStreamable< Trow > and AlStreamable< Tcol > and AlStreamable< NumType >
 Convert matrix to a formatted string representation.
 
bool are_equal (const NumType &n1, const NumType &n2) const
 Check if two values are equal within epsilon tolerance.
 
bool equal_to (const Matrix &m) const
 Check if this matrix equals another (within epsilon).
 
bool operator== (const Matrix &m) const
 Equality operator (uses equal_to).
 
bool operator!= (const Matrix &m) const
 Inequality operator.
 

Static Public Member Functions

static Matrix create_by_rows (const RDomain &rdomain, const DynList< Vector< Tcol, NumType > > &rows, const NumType &e=default_epsilon)
 Create a matrix from a list of row vectors.
 
static Matrix create_by_rows (RDomain &&rdomain, const DynList< Vector< Tcol, NumType > > &rows, const NumType &e=default_epsilon)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The matrix keeps a copy of the temporary row domain.
 
static Matrix create_by_columns (const CDomain &cdomain, const DynList< Vector< Trow, NumType > > &cols, const NumType &e=default_epsilon)
 Create a matrix from a list of column vectors.
 
static Matrix create_by_columns (CDomain &&cdomain, const DynList< Vector< Trow, NumType > > &cols, const NumType &e=default_epsilon)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The matrix keeps a copy of the temporary column domain.
 

Private Member Functions

bool is_zero (const NumType &val) const noexcept
 
template<typename T2row , typename T2col >
void validate_domains_for_mult (const Matrix< T2row, T2col, NumType > &m) const
 Validate domain compatibility for matrix multiplication.
 

Static Private Member Functions

template<class D >
static std::shared_ptr< D > borrow (const D &d)
 
template<class D >
static std::shared_ptr< D > own (D &&d)
 
template<class Vec , class D >
static void check_vectors (const D &domain, const DynList< Vec > &vectors, const char *name)
 
static Matrix create_by_rows_impl (RDomainPtr rdomain, const DynList< Vector< Tcol, NumType > > &rows, const NumType &e)
 
static Matrix create_by_columns_impl (CDomainPtr cdomain, const DynList< Vector< Trow, NumType > > &cols, const NumType &e)
 

Private Attributes

RDomainPtr rdomain_ptr = nullptr
 
CDomainPtr cdomain_ptr = nullptr
 
Map entries
 
NumType epsilon
 

Static Private Attributes

static const NumType default_epsilon = 1e-7
 

Detailed Description

template<typename Trow = int, typename Tcol = int, typename NumType = double>
requires AlDomainKey<Trow>
class Aleph::Matrix< Trow, Tcol, NumType >

Sparse matrix with generic row and column domains.

This class implements a sparse matrix where row and column indices are elements of arbitrary domains (AlDomain). Internally, only non-zero entries are stored in a hash table keyed by (row, col) pairs.

  • Absence of an entry in the hash table means the value is zero.
  • Setting an entry to zero removes it from the hash table.
Template Parameters
TrowType of row domain elements (default: int)
TcolType of column domain elements (default: int)
NumTypeNumeric type for matrix entries (default: double)

Definition at line 69 of file al-matrix.H.

Member Typedef Documentation

◆ CDomain

template<typename Trow = int, typename Tcol = int, typename NumType = double>
using Aleph::Matrix< Trow, Tcol, NumType >::CDomain = AlDomain<Tcol>

Definition at line 73 of file al-matrix.H.

◆ CDomainPtr

template<typename Trow = int, typename Tcol = int, typename NumType = double>
using Aleph::Matrix< Trow, Tcol, NumType >::CDomainPtr = std::shared_ptr<CDomain>

Definition at line 75 of file al-matrix.H.

◆ ColVector

template<typename Trow = int, typename Tcol = int, typename NumType = double>
using Aleph::Matrix< Trow, Tcol, NumType >::ColVector = Vector<Trow, NumType>

Definition at line 81 of file al-matrix.H.

◆ Map

template<typename Trow = int, typename Tcol = int, typename NumType = double>
using Aleph::Matrix< Trow, Tcol, NumType >::Map = Aleph::HashMap<RCPair, NumType, MapODhash>

Definition at line 79 of file al-matrix.H.

◆ Pair

template<typename Trow = int, typename Tcol = int, typename NumType = double>
typedef std::pair<RCPair, NumType> Aleph::Matrix< Trow, Tcol, NumType >::Pair

Type alias for entries stored in the hash table: ((row,col), value).

Definition at line 130 of file al-matrix.H.

◆ RCPair

template<typename Trow = int, typename Tcol = int, typename NumType = double>
using Aleph::Matrix< Trow, Tcol, NumType >::RCPair = std::pair<Trow, Tcol>

Definition at line 77 of file al-matrix.H.

◆ RDomain

template<typename Trow = int, typename Tcol = int, typename NumType = double>
using Aleph::Matrix< Trow, Tcol, NumType >::RDomain = AlDomain<Trow>

Definition at line 72 of file al-matrix.H.

◆ RDomainPtr

template<typename Trow = int, typename Tcol = int, typename NumType = double>
using Aleph::Matrix< Trow, Tcol, NumType >::RDomainPtr = std::shared_ptr<RDomain>

Definition at line 74 of file al-matrix.H.

◆ RowVector

template<typename Trow = int, typename Tcol = int, typename NumType = double>
using Aleph::Matrix< Trow, Tcol, NumType >::RowVector = Vector<Tcol, NumType>

Definition at line 83 of file al-matrix.H.

Constructor & Destructor Documentation

◆ Matrix() [1/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( RDomainPtr  rdomain,
CDomainPtr  cdomain,
const NumType &  e = default_epsilon 
)
inline

Construct an empty sparse matrix over the given domains (shared_ptr version).

Parameters
rdomainShared pointer to row domain
cdomainShared pointer to column domain
eEpsilon for zero comparisons (default: 1e-7)

Definition at line 149 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::set_epsilon().

◆ Matrix() [2/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( const RDomain &  rdomain,
const CDomain &  cdomain,
const NumType &  e = default_epsilon 
)
inline

Construct an empty sparse matrix over the given domains (reference version).

Parameters
rdomainRow domain (will be wrapped in non-owning shared_ptr)
cdomainColumn domain (will be wrapped in non-owning shared_ptr)
eEpsilon for zero comparisons (default: 1e-7)
Note
Creates non-owning shared_ptrs; caller must ensure domains outlive matrix

Definition at line 165 of file al-matrix.H.

◆ Matrix() [3/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( RDomain &&  rdomain,
CDomain &&  cdomain,
const NumType &  e = default_epsilon 
)
inline

Construct an empty sparse matrix over domains of which one, or both, are temporary: the matrix keeps a copy of each temporary one, which lives as long as the matrix and those that share it.

Parameters
rdomainRow domain
cdomainColumn domain
eEpsilon for zero comparisons (default: 1e-7)

Definition at line 180 of file al-matrix.H.

◆ Matrix() [4/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( RDomain &&  rdomain,
const CDomain &  cdomain,
const NumType &  e = default_epsilon 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 188 of file al-matrix.H.

◆ Matrix() [5/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( const RDomain &  rdomain,
CDomain &&  cdomain,
const NumType &  e = default_epsilon 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 196 of file al-matrix.H.

◆ Matrix() [6/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
template<typename R , typename C , typename... Rest>
requires (std::is_integral_v<std::remove_cvref_t<R>> or std::is_integral_v<std::remove_cvref_t<C>>)
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( R &&  ,
C &&  ,
Rest &&  ... 
)
delete

A matrix needs domains: Matrix(IntRange(n), IntRange(m)), not Matrix(n, m), which would turn the numbers into empty domains.

◆ Matrix() [7/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( RDomainPtr  rdomain,
CDomainPtr  cdomain,
std::initializer_list< std::initializer_list< NumType > >  l,
const NumType &  e = default_epsilon 
)
inline

Construct a matrix from a 2D initializer list (shared_ptr version).

Parameters
rdomainShared pointer to row domain
cdomainShared pointer to column domain
lInitializer list of rows (each row is a list of values)
eEpsilon for zero comparisons
Exceptions
ah_range_errorif dimensions don't match domain sizes

Definition at line 218 of file al-matrix.H.

References ah_range_error_if, StlAlephIterator< SetName >::begin(), Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, col, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::for_each(), FunctionalMethods< Container, T >::for_each(), Aleph::Matrix< Trow, Tcol, NumType >::is_zero(), GenericItems< Container, T >::keys(), l, Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, row, and Aleph::DynList< T >::size().

◆ Matrix() [8/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( const RDomain &  rdomain,
const CDomain &  cdomain,
std::initializer_list< std::initializer_list< NumType > >  l,
const NumType &  e = default_epsilon 
)
inline

Construct a matrix from a 2D initializer list (reference version).

Parameters
rdomainRow domain (will be wrapped in non-owning shared_ptr)
cdomainColumn domain (will be wrapped in non-owning shared_ptr)
lInitializer list of rows
eEpsilon for zero comparisons
Note
Creates non-owning shared_ptrs; caller must ensure domains outlive matrix

Definition at line 253 of file al-matrix.H.

◆ Matrix() [9/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( RDomain &&  rdomain,
CDomain &&  cdomain,
std::initializer_list< std::initializer_list< NumType > >  l,
const NumType &  e = default_epsilon 
)
inline

Construct a matrix from a 2D initializer list over domains of which one, or both, are temporary: the matrix keeps a copy of each temporary one.

Parameters
rdomainRow domain
cdomainColumn domain
lInitializer list of rows
eEpsilon for zero comparisons
Exceptions
ah_range_errorif dimensions don't match domain sizes

Definition at line 269 of file al-matrix.H.

◆ Matrix() [10/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( RDomain &&  rdomain,
const CDomain &  cdomain,
std::initializer_list< std::initializer_list< NumType > >  l,
const NumType &  e = default_epsilon 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 277 of file al-matrix.H.

◆ Matrix() [11/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( const RDomain &  rdomain,
CDomain &&  cdomain,
std::initializer_list< std::initializer_list< NumType > >  l,
const NumType &  e = default_epsilon 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 285 of file al-matrix.H.

◆ Matrix() [12/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( RDomainPtr  rdomain,
CDomainPtr  cdomain,
const DynList< DynList< NumType > > &  l,
const NumType &  e = default_epsilon 
)
inline

Construct a matrix from a list of lists (shared_ptr version).

Parameters
rdomainShared pointer to row domain
cdomainShared pointer to column domain
lList of rows (each row is a DynList of values)
eEpsilon for zero comparisons
Exceptions
ah_range_errorif dimensions don't match domain sizes

Definition at line 299 of file al-matrix.H.

References ah_range_error_if, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::is_zero(), l, Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, row, Aleph::DynList< T >::size(), and Aleph::zip_it().

◆ Matrix() [13/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( const RDomain &  rdomain,
const CDomain &  cdomain,
const DynList< DynList< NumType > > &  l,
const NumType &  e = default_epsilon 
)
inline

Construct a matrix from a list of lists (reference version).

Parameters
rdomainRow domain (will be wrapped in non-owning shared_ptr)
cdomainColumn domain (will be wrapped in non-owning shared_ptr)
lList of rows
eEpsilon for zero comparisons
Note
Creates non-owning shared_ptrs; caller must ensure domains outlive matrix

Definition at line 333 of file al-matrix.H.

◆ Matrix() [14/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( RDomain &&  rdomain,
CDomain &&  cdomain,
const DynList< DynList< NumType > > &  l,
const NumType &  e = default_epsilon 
)
inline

Construct a matrix from a list of lists over domains of which one, or both, are temporary: the matrix keeps a copy of each temporary one.

Parameters
rdomainRow domain
cdomainColumn domain
lList of rows
eEpsilon for zero comparisons
Exceptions
ah_range_errorif dimensions don't match domain sizes

Definition at line 349 of file al-matrix.H.

◆ Matrix() [15/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( RDomain &&  rdomain,
const CDomain &  cdomain,
const DynList< DynList< NumType > > &  l,
const NumType &  e = default_epsilon 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 357 of file al-matrix.H.

◆ Matrix() [16/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( const RDomain &  rdomain,
CDomain &&  cdomain,
const DynList< DynList< NumType > > &  l,
const NumType &  e = default_epsilon 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 365 of file al-matrix.H.

◆ Matrix() [17/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( const Matrix< Trow, Tcol, NumType > &  other)
inline

Copy constructor.

Definition at line 373 of file al-matrix.H.

◆ Matrix() [18/18]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Aleph::Matrix< Trow, Tcol, NumType >::Matrix ( Matrix< Trow, Tcol, NumType > &&  other)
inlinenoexcept

Move constructor.

Definition at line 383 of file al-matrix.H.

Member Function Documentation

◆ are_equal()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
bool Aleph::Matrix< Trow, Tcol, NumType >::are_equal ( const NumType &  n1,
const NumType &  n2 
) const
inline

Check if two values are equal within epsilon tolerance.

Definition at line 1179 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::is_zero().

Referenced by Aleph::Matrix< Trow, Tcol, NumType >::equal_to().

◆ borrow()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
template<class D >
static std::shared_ptr< D > Aleph::Matrix< Trow, Tcol, NumType >::borrow ( const D &  d)
inlinestaticprivate

◆ check_vectors()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
template<class Vec , class D >
static void Aleph::Matrix< Trow, Tcol, NumType >::check_vectors ( const D &  domain,
const DynList< Vec > &  vectors,
const char *  name 
)
inlinestaticprivate

◆ col_domain_list()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
DynList< Tcol > Aleph::Matrix< Trow, Tcol, NumType >::col_domain_list ( ) const
inline

◆ create_by_columns() [1/2]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
static Matrix Aleph::Matrix< Trow, Tcol, NumType >::create_by_columns ( CDomain &&  cdomain,
const DynList< Vector< Trow, NumType > > &  cols,
const NumType &  e = default_epsilon 
)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The matrix keeps a copy of the temporary column domain.

Definition at line 545 of file al-matrix.H.

References cols, Aleph::Matrix< Trow, Tcol, NumType >::create_by_columns_impl(), and Aleph::Matrix< Trow, Tcol, NumType >::own().

◆ create_by_columns() [2/2]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
static Matrix Aleph::Matrix< Trow, Tcol, NumType >::create_by_columns ( const CDomain &  cdomain,
const DynList< Vector< Trow, NumType > > &  cols,
const NumType &  e = default_epsilon 
)
inlinestatic

Create a matrix from a list of column vectors.

The matrix shares the row domain of the vectors, which must be the same for all of them.

Parameters
cdomainColumn domain
colsList of vectors, one per column, in the order of the sorted keys of cdomain
eEpsilon for zero comparisons
Returns
New matrix constructed from the column vectors
Exceptions
ah_range_errorif there is not one vector per column
ah_domain_errorif the vectors have different domains

Definition at line 535 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::borrow(), cols, and Aleph::Matrix< Trow, Tcol, NumType >::create_by_columns_impl().

◆ create_by_columns_impl()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
static Matrix Aleph::Matrix< Trow, Tcol, NumType >::create_by_columns_impl ( CDomainPtr  cdomain,
const DynList< Vector< Trow, NumType > > &  cols,
const NumType &  e 
)
inlinestaticprivate

◆ create_by_rows() [1/2]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
static Matrix Aleph::Matrix< Trow, Tcol, NumType >::create_by_rows ( const RDomain &  rdomain,
const DynList< Vector< Tcol, NumType > > &  rows,
const NumType &  e = default_epsilon 
)
inlinestatic

Create a matrix from a list of row vectors.

The matrix shares the column domain of the vectors, which must be the same for all of them.

Parameters
rdomainRow domain
rowsList of vectors, one per row, in the order of the sorted keys of rdomain
eEpsilon for zero comparisons
Returns
New matrix constructed from the row vectors
Exceptions
ah_range_errorif there is not one vector per row
ah_domain_errorif the vectors have different domains

Definition at line 504 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::borrow(), Aleph::Matrix< Trow, Tcol, NumType >::create_by_rows_impl(), and rows.

◆ create_by_rows() [2/2]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
static Matrix Aleph::Matrix< Trow, Tcol, NumType >::create_by_rows ( RDomain &&  rdomain,
const DynList< Vector< Tcol, NumType > > &  rows,
const NumType &  e = default_epsilon 
)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The matrix keeps a copy of the temporary row domain.

Definition at line 514 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::create_by_rows_impl(), Aleph::Matrix< Trow, Tcol, NumType >::own(), and rows.

◆ create_by_rows_impl()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
static Matrix Aleph::Matrix< Trow, Tcol, NumType >::create_by_rows_impl ( RDomainPtr  rdomain,
const DynList< Vector< Tcol, NumType > > &  rows,
const NumType &  e 
)
inlinestaticprivate

◆ equal_to()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
bool Aleph::Matrix< Trow, Tcol, NumType >::equal_to ( const Matrix< Trow, Tcol, NumType > &  m) const
inline

Check if this matrix equals another (within epsilon).

Parameters
mMatrix to compare with
Returns
true if all entries are equal within epsilon
Exceptions
ah_domain_errorif domains don't match

Definition at line 1190 of file al-matrix.H.

References ah_domain_error_if, FunctionalMethods< Container, T >::all(), Aleph::and, Aleph::Matrix< Trow, Tcol, NumType >::are_equal(), Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, col, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::get_entry(), m, Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and row.

◆ get_col_as_list()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
DynList< NumType > Aleph::Matrix< Trow, Tcol, NumType >::get_col_as_list ( const Tcol &  col) const
inline

Get a column as a list of values (in row order).

Parameters
colColumn index
Returns
List of values in that column
Exceptions
ah_domain_errorif col not in domain

Definition at line 666 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, col, Aleph::Matrix< Trow, Tcol, NumType >::get_entry(), row, and Aleph::Matrix< Trow, Tcol, NumType >::row_domain_list().

◆ get_col_domain()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
const CDomain & Aleph::Matrix< Trow, Tcol, NumType >::get_col_domain ( ) const
inlinenoexcept

◆ get_col_domain_ptr()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
const CDomainPtr & Aleph::Matrix< Trow, Tcol, NumType >::get_col_domain_ptr ( ) const
inlinenoexcept

Return the shared pointer to the column domain.

Definition at line 142 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr.

Referenced by TEST().

◆ get_col_vector()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Vector< Trow, NumType > Aleph::Matrix< Trow, Tcol, NumType >::get_col_vector ( const Tcol &  col) const
inline

◆ get_entry() [1/2]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
NumType Aleph::Matrix< Trow, Tcol, NumType >::get_entry ( const Trow &  row,
const Tcol &  col 
)
inline

Get an entry value (non-const version with lazy cleanup).

If the stored value is within epsilon of zero, the entry is removed from the hash table (lazy cleanup) and zero is returned.

Parameters
rowRow index
colColumn index
Returns
Entry value, or 0 if not present

Definition at line 562 of file al-matrix.H.

References Aleph::and, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, col, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::is_zero(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and row.

Referenced by demo_adjacency_matrix(), demo_named_matrix(), demo_sparse_matrix(), demo_transpose(), Aleph::Matrix< Trow, Tcol, NumType >::equal_to(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_as_list(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_as_list(), and TEST().

◆ get_entry() [2/2]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
NumType Aleph::Matrix< Trow, Tcol, NumType >::get_entry ( const Trow &  row,
const Tcol &  col 
) const
inlinenoexcept

Get an entry value (const version, no cleanup).

Parameters
rowRow index
colColumn index
Returns
Entry value, or 0 if not present

Definition at line 581 of file al-matrix.H.

References Aleph::and, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, col, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and row.

◆ get_epsilon()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
const NumType & Aleph::Matrix< Trow, Tcol, NumType >::get_epsilon ( ) const
inlinenoexcept

Return the epsilon value used for zero comparisons.

Definition at line 116 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::epsilon.

◆ get_row_as_list()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
DynList< NumType > Aleph::Matrix< Trow, Tcol, NumType >::get_row_as_list ( const Trow &  row) const
inline

Get a row as a list of values (in column order).

Parameters
rowRow index
Returns
List of values in that row
Exceptions
ah_domain_errorif row not in domain

Definition at line 650 of file al-matrix.H.

References ah_domain_error_if, col, Aleph::Matrix< Trow, Tcol, NumType >::col_domain_list(), Aleph::Matrix< Trow, Tcol, NumType >::get_entry(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and row.

Referenced by Aleph::Matrix< Trow, Tcol, NumType >::to_str().

◆ get_row_domain()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
const RDomain & Aleph::Matrix< Trow, Tcol, NumType >::get_row_domain ( ) const
inlinenoexcept

◆ get_row_domain_ptr()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
const RDomainPtr & Aleph::Matrix< Trow, Tcol, NumType >::get_row_domain_ptr ( ) const
inlinenoexcept

Return the shared pointer to the row domain.

Definition at line 139 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr.

Referenced by TEST().

◆ get_row_vector()

◆ identity()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix Aleph::Matrix< Trow, Tcol, NumType >::identity ( ) const
inline

Create an identity matrix (only for square matrices).

Requires that Trow == Tcol (enforced by static_assert).

Returns
Identity matrix over the row domain

Definition at line 940 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, row, and Aleph::Matrix< Trow, Tcol, NumType >::set_entry().

◆ is_zero()

◆ matrix_vector_mult()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
template<typename T2row , typename T2col >
requires AlAdditiveNumber<NumType>
Matrix< Trow, T2col, NumType > Aleph::Matrix< Trow, Tcol, NumType >::matrix_vector_mult ( const Matrix< T2row, T2col, NumType > &  m) const
inline

Matrix multiplication using matrix times column-vector approach.

Template Parameters
T2rowRow type of second matrix
T2colColumn type of second matrix
Parameters
mMatrix to multiply with
Returns
Result matrix
Exceptions
ah_domain_errorif column domain size != row domain size of m

Definition at line 1065 of file al-matrix.H.

References col, Aleph::for_each(), m, Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_col(), and Aleph::Matrix< Trow, Tcol, NumType >::validate_domains_for_mult().

◆ mult_by_scalar()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix & Aleph::Matrix< Trow, Tcol, NumType >::mult_by_scalar ( const NumType &  scalar)
inline

Multiply all entries by a scalar (in-place).

Parameters
scalarValue to multiply by
Returns
Reference to this matrix

Definition at line 1023 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::entries.

Referenced by demo_matrix_arithmetic(), and Aleph::operator*().

◆ mult_matrix_vector_dot_product()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Vector< Trow, NumType > Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_dot_product ( const Vector< Tcol, NumType > &  vec) const
inline

Matrix-vector multiplication using dot products.

Computes each result entry as dot product of row vector and input.

Parameters
vecColumn vector to multiply
Returns
Result vector
Exceptions
ah_domain_errorif domain mismatch

Definition at line 833 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::get_col_domain(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_vector(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, row, and Aleph::Vector< T, NumType >::set_entry().

Referenced by demo_matrix_vector_mult().

◆ mult_matrix_vector_linear_comb()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Vector< Trow, NumType > Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_linear_comb ( const Vector< Tcol, NumType > &  vec) const
inline

return this*vec in terms of linear combinations

| a b c

A | 1 2 3 a b c A B C B | 4 5 6 * ---— = v[a]*m[a] + v[b]*m[b] + v[c]*m[c] = -----— C | 7 8 9 1 0 2 7 16 25

Definition at line 756 of file al-matrix.H.

References ah_domain_error_if, col, Aleph::Matrix< Trow, Tcol, NumType >::get_col_domain(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_vector(), and Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr.

Referenced by Aleph::Matrix< Trow, Tcol, NumType >::operator*().

◆ mult_matrix_vector_sparse()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Vector< Trow, NumType > Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_sparse ( const Vector< Tcol, NumType > &  vec) const
inline

Matrix-vector multiplication using sparse iteration.

Iterates only over non-zero matrix entries for efficiency.

Parameters
vecColumn vector to multiply
Returns
Result vector
Exceptions
ah_domain_errorif domain mismatch

Definition at line 780 of file al-matrix.H.

References ah_domain_error_if, col, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::get_col_domain(), Aleph::Vector< T, NumType >::get_entry(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, row, and Aleph::Vector< T, NumType >::set_entry().

◆ mult_vector_matrix_dot_product()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Vector< Tcol, NumType > Aleph::Matrix< Trow, Tcol, NumType >::mult_vector_matrix_dot_product ( const Vector< Trow, NumType > &  vec) const
inline

Vector-matrix multiplication using dot products.

Computes each result entry as dot product of input and column vector.

Parameters
vecRow vector to multiply
Returns
Result vector
Exceptions
ah_domain_errorif domain mismatch

Definition at line 855 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, col, Aleph::Matrix< Trow, Tcol, NumType >::get_col_vector(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_domain(), and Aleph::Vector< T, NumType >::set_entry().

◆ mult_vector_matrix_linear_comb()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Vector< Tcol, NumType > Aleph::Matrix< Trow, Tcol, NumType >::mult_vector_matrix_linear_comb ( const Vector< Trow, NumType > &  vec) const
inline

return vec*this in terms of linear combinations

| a b c

A B C A | 1 2 3 a b c -----— * B | 4 5 6 = v[A]*M[A] = ----------— 1.5 0 3 C | 7 8 9 22.5 27 31.5

Definition at line 809 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::get_row_domain(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_vector(), and row.

◆ operator!=()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
bool Aleph::Matrix< Trow, Tcol, NumType >::operator!= ( const Matrix< Trow, Tcol, NumType > &  m) const
inline

Inequality operator.

Definition at line 1217 of file al-matrix.H.

References m.

◆ operator*()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Vector< Trow, NumType > Aleph::Matrix< Trow, Tcol, NumType >::operator* ( const Vector< Tcol, NumType > &  vec) const
inline

Matrix-vector multiplication operator (uses linear combination method).

Definition at line 870 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_linear_comb().

◆ operator+()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix Aleph::Matrix< Trow, Tcol, NumType >::operator+ ( const Matrix< Trow, Tcol, NumType > &  m) const
inline

Matrix addition operator.

Definition at line 978 of file al-matrix.H.

References m.

◆ operator+=()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix & Aleph::Matrix< Trow, Tcol, NumType >::operator+= ( const Matrix< Trow, Tcol, NumType > &  m)
inline

Add another matrix to this one.

Parameters
mMatrix to add (must share same domains)
Returns
Reference to this matrix
Exceptions
ah_domain_errorif domains don't match

Definition at line 958 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, col, Aleph::Matrix< Trow, Tcol, NumType >::entries, FunctionalMethods< Container, T >::for_each(), m, Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and row.

◆ operator-()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix Aleph::Matrix< Trow, Tcol, NumType >::operator- ( const Matrix< Trow, Tcol, NumType > &  m) const
inline

Matrix subtraction operator.

Definition at line 1011 of file al-matrix.H.

References m.

◆ operator-=()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix & Aleph::Matrix< Trow, Tcol, NumType >::operator-= ( const Matrix< Trow, Tcol, NumType > &  m)
inline

Subtract another matrix from this one.

Parameters
mMatrix to subtract (must share same domains)
Returns
Reference to this matrix
Exceptions
ah_domain_errorif domains don't match

Definition at line 991 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, col, Aleph::Matrix< Trow, Tcol, NumType >::entries, FunctionalMethods< Container, T >::for_each(), m, Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and row.

◆ operator=() [1/2]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix & Aleph::Matrix< Trow, Tcol, NumType >::operator= ( const Matrix< Trow, Tcol, NumType > &  other)
inline

◆ operator=() [2/2]

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix & Aleph::Matrix< Trow, Tcol, NumType >::operator= ( Matrix< Trow, Tcol, NumType > &&  other)
inlinenoexcept

◆ operator==()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
bool Aleph::Matrix< Trow, Tcol, NumType >::operator== ( const Matrix< Trow, Tcol, NumType > &  m) const
inline

Equality operator (uses equal_to).

Definition at line 1210 of file al-matrix.H.

References m.

◆ own()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
template<class D >
static std::shared_ptr< D > Aleph::Matrix< Trow, Tcol, NumType >::own ( D &&  d)
inlinestaticprivate

◆ print()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
void Aleph::Matrix< Trow, Tcol, NumType >::print ( ) const
inline

Print non-zero entries to stdout.

Definition at line 1080 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::entries, and Aleph::to_str().

◆ row_domain_list()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
DynList< Trow > Aleph::Matrix< Trow, Tcol, NumType >::row_domain_list ( ) const
inline

◆ set_entry()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
void Aleph::Matrix< Trow, Tcol, NumType >::set_entry ( const Trow &  row,
const Tcol &  col,
const NumType &  val 
)
inline

◆ set_epsilon()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
void Aleph::Matrix< Trow, Tcol, NumType >::set_epsilon ( const NumType &  e)
inline

Set the epsilon value for zero comparisons.

Parameters
eNew epsilon value (must be >= 0)
Exceptions
ah_domain_errorif e < 0

Definition at line 122 of file al-matrix.H.

References ah_domain_error_if, and Aleph::Matrix< Trow, Tcol, NumType >::epsilon.

Referenced by Aleph::Matrix< Trow, Tcol, NumType >::Matrix().

◆ set_vector_as_col()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix & Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_col ( const Tcol &  col,
const Vector< Trow, NumType > &  vec 
)
inline

Set a column from a vector.

Parameters
colColumn index
vecVector with row domain
Returns
Reference to this matrix
Exceptions
ah_domain_errorif vector domain doesn't match row domain

Definition at line 921 of file al-matrix.H.

References ah_domain_error_if, col, Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::Vector< T, NumType >::get_domain(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, row, and Aleph::Matrix< Trow, Tcol, NumType >::set_entry().

Referenced by Aleph::Matrix< Trow, Tcol, NumType >::matrix_vector_mult().

◆ set_vector_as_row()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix & Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_row ( const Trow &  row,
const Vector< Tcol, NumType > &  vec 
)
inline

Set a row from a vector.

Parameters
rowRow index
vecVector with column domain
Returns
Reference to this matrix
Exceptions
ah_domain_errorif vector domain doesn't match column domain

Definition at line 902 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, col, Aleph::FunctionalMixin< Derived, Type >::for_each(), Aleph::Vector< T, NumType >::get_domain(), row, and Aleph::Matrix< Trow, Tcol, NumType >::set_entry().

Referenced by demo_row_col_operations(), and Aleph::Matrix< Trow, Tcol, NumType >::vector_matrix_mult().

◆ to_collist()

◆ to_rowlist()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
DynList< Vector< Tcol, NumType > > Aleph::Matrix< Trow, Tcol, NumType >::to_rowlist ( ) const
inline

◆ to_str()

◆ transpose()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
Matrix< Tcol, Trow, NumType > Aleph::Matrix< Trow, Tcol, NumType >::transpose ( ) const
inline

Compute the transpose of this matrix.

Returns
New matrix with rows and columns swapped, which shares the domains of this one

Definition at line 619 of file al-matrix.H.

References Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and Aleph::Matrix< Trow, Tcol, NumType >::set_entry().

Referenced by demo_transpose().

◆ validate_domains_for_mult()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
template<typename T2row , typename T2col >
void Aleph::Matrix< Trow, Tcol, NumType >::validate_domains_for_mult ( const Matrix< T2row, T2col, NumType > &  m) const
inlineprivate

Validate domain compatibility for matrix multiplication.

For A×B to be valid, the column domain of A must be identical to the row domain of B (same shared_ptr).

Parameters
mMatrix to multiply with
Exceptions
ah_domain_errorif domains are not identical

Definition at line 886 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, and m.

Referenced by Aleph::Matrix< Trow, Tcol, NumType >::matrix_vector_mult(), and Aleph::Matrix< Trow, Tcol, NumType >::vector_matrix_mult().

◆ vector_matrix_mult()

template<typename Trow = int, typename Tcol = int, typename NumType = double>
template<typename T2row , typename T2col >
requires AlAdditiveNumber<NumType>
Matrix< Trow, T2col, NumType > Aleph::Matrix< Trow, Tcol, NumType >::vector_matrix_mult ( const Matrix< T2row, T2col, NumType > &  m) const
inline

Matrix multiplication using row-vector times matrix approach.

Template Parameters
T2rowRow type of second matrix
T2colColumn type of second matrix
Parameters
mMatrix to multiply with
Returns
Result matrix
Exceptions
ah_domain_errorif column domain size != row domain size of m

Definition at line 1043 of file al-matrix.H.

References Aleph::for_each(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_vector(), m, Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, row, Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_row(), and Aleph::Matrix< Trow, Tcol, NumType >::validate_domains_for_mult().

Member Data Documentation

◆ cdomain_ptr

◆ default_epsilon

template<typename Trow , typename Tcol , typename NumType >
requires AlDomainKey<Trow>
and AlDomainKey< Tcol > and AlNumber< NumType > const NumType Aleph::Matrix< Trow, Tcol, NumType >::default_epsilon = 1e-7
staticprivate

Definition at line 86 of file al-matrix.H.

◆ entries

◆ epsilon

◆ rdomain_ptr

template<typename Trow = int, typename Tcol = int, typename NumType = double>
RDomainPtr Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr = nullptr
private

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