Aleph-w 3.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, NumTypePair
 Type alias for entries stored in the hash table: ((row,col), value).
 

Public Member Functions

const NumTypeget_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 RDomainget_row_domain () const noexcept
 Return the row domain.
 
const CDomainget_col_domain () const noexcept
 Return the column domain.
 
const RDomainPtrget_row_domain_ptr () const noexcept
 Return the shared pointer to the row domain.
 
const CDomainPtrget_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 (RDomainPtr rdomain, CDomainPtr cdomain, std::initializer_list< std::initializer_list< NumType > > l, const NumType &e=default_epsilon)
 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)
 Construct a matrix from a 2D initializer list (reference version).
 
 Matrix (RDomainPtr rdomain, CDomainPtr cdomain, const DynList< DynList< NumType > > &l, const NumType &e=default_epsilon)
 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)
 Construct a matrix from a list of lists (reference version).
 
 Matrix (const Matrix &other)
 Copy constructor.
 
 Matrix (Matrix &&other) noexcept
 Move constructor.
 
Matrixoperator= (const Matrix &other)
 Copy assignment operator.
 
Matrixoperator= (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 transpose () const
 Compute the transpose of this matrix.
 
DynList< Trowrow_domain_list () const
 Return a sorted list of row domain keys.
 
DynList< Tcolcol_domain_list () const
 Return a sorted list of column domain keys.
 
DynList< NumTypeget_row_as_list (const Trow &row) const
 Get a row as a list of values (in column order).
 
DynList< NumTypeget_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
 Return a list of vectors corresponding to the rows.
 
DynList< ColVectorto_collist () const
 Return a list of vectors corresponding to the columns.
 
Vector< Tcol, NumTypeget_row_vector (const Trow &row) const
 Given a row, build a vector corresponding to the row.
 
Vector< Trow, NumTypeget_col_vector (const Tcol &col) const
 Given a column, build a vector corresponding to the column.
 
Vector< Trow, NumTypemult_matrix_vector_linear_comb (const Vector< Tcol, NumType > &vec) const
 return this*vec in terms of linear combinations
 
Vector< Trow, NumTypemult_matrix_vector_sparse (const Vector< Tcol, NumType > &vec) const
 Matrix-vector multiplication using sparse iteration.
 
Vector< Tcol, NumTypemult_vector_matrix_linear_comb (const Vector< Trow, NumType > &vec) const
 return vec*this in terms of linear combinations
 
Vector< Trow, NumTypemult_matrix_vector_dot_product (const Vector< Tcol, NumType > &vec) const
 Matrix-vector multiplication using dot products.
 
Vector< Tcol, NumTypemult_vector_matrix_dot_product (const Vector< Trow, NumType > &vec) const
 Vector-matrix multiplication using dot products.
 
Vector< Trow, NumTypeoperator* (const Vector< Tcol, NumType > &vec) const
 Matrix-vector multiplication operator (uses linear combination method).
 
Matrixset_vector_as_row (const Trow &row, const Vector< Tcol, NumType > &vec)
 Set a row from a vector.
 
Matrixset_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).
 
Matrixoperator+= (const Matrix &m)
 Add another matrix to this one.
 
Matrix operator+ (const Matrix &m) const
 Matrix addition operator.
 
Matrixoperator-= (const Matrix &m)
 Subtract another matrix from this one.
 
Matrix operator- (const Matrix &m) const
 Matrix subtraction operator.
 
Matrixmult_by_scalar (const NumType &scalar)
 Multiply all entries by a scalar (in-place).
 
template<typename T2row , typename T2col >
Matrix< Trow, T2colvector_matrix_mult (const Matrix< T2row, T2col, NumType > &m) const
 Matrix multiplication using row-vector times matrix approach.
 
template<typename T2row , typename T2col >
Matrix< Trow, T2colmatrix_vector_mult (const Matrix< T2row, T2col, NumType > &m) const
 Matrix multiplication using matrix times column-vector approach.
 
void print () const
 Print non-zero entries to stdout.
 
std::string to_str () const
 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_columns (const CDomain &cdomain, const DynList< Vector< Trow, NumType > > &cols, const NumType &e=default_epsilon)
 Create a matrix from a list of column vectors.
 

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.
 

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>
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 65 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 69 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 71 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 77 of file al-matrix.H.

◆ Map

Definition at line 75 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 111 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 73 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 68 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 70 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 79 of file al-matrix.H.

Constructor & Destructor Documentation

◆ Matrix() [1/8]

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 130 of file al-matrix.H.

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

◆ Matrix() [2/8]

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 146 of file al-matrix.H.

◆ Matrix() [3/8]

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 163 of file al-matrix.H.

References ah_range_error_if, StlAlephIterator< SetName >::begin(), Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::for_each(), FunctionalMethods< Container, T >::for_each(), Aleph::Matrix< Trow, Tcol, NumType >::is_zero(), l, Aleph::maps(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, Aleph::HTList::size(), and Aleph::sort().

◆ Matrix() [4/8]

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 197 of file al-matrix.H.

◆ Matrix() [5/8]

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 211 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::maps(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, Aleph::HTList::size(), and Aleph::zip_it().

◆ Matrix() [6/8]

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 242 of file al-matrix.H.

◆ Matrix() [7/8]

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 250 of file al-matrix.H.

◆ Matrix() [8/8]

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 260 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 957 of file al-matrix.H.

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

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

◆ col_domain_list()

◆ create_by_columns()

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.

Parameters
cdomainColumn domain
colsList of vectors, one per column
eEpsilon for zero comparisons
Returns
New matrix constructed from the column vectors

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

References Aleph::Vector< T, NumType >::get_it(), Aleph::DynList< T >::insert(), GenericItems< Container, T >::keys(), Aleph::maps(), and Aleph::zip_it().

◆ create_by_rows()

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.

Parameters
rdomainRow domain
rowsList of vectors, one per row
eEpsilon for zero comparisons
Returns
New matrix constructed from the row vectors

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

References Aleph::DynList< T >::get_first(), LocateFunctions< Container, Type >::get_it(), Aleph::DynList< T >::insert(), GenericItems< Container, T >::keys(), Aleph::maps(), and Aleph::zip_it().

◆ 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 967 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::are_equal(), Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::get_entry(), Aleph::maps(), and Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr.

◆ 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 466 of file al-matrix.H.

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

◆ get_col_domain()

◆ 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 123 of file al-matrix.H.

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

◆ get_col_vector()

◆ 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 366 of file al-matrix.H.

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

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

◆ 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 385 of file al-matrix.H.

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

◆ 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 97 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 451 of file al-matrix.H.

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

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

◆ get_row_domain()

◆ 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 120 of file al-matrix.H.

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

◆ 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 729 of file al-matrix.H.

References Aleph::maps(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, 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 >
Matrix< Trow, T2col > 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 848 of file al-matrix.H.

References Aleph::for_each(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_domain(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_vector(), Aleph::maps(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, 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 808 of file al-matrix.H.

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

Referenced by demo_matrix_arithmetic().

◆ 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 627 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::maps(), and Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr.

◆ 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 553 of file al-matrix.H.

References ah_domain_error_if, FunctionalMethods< Container, T >::for_each(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_domain(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_vector(), Aleph::maps(), 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 576 of file al-matrix.H.

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

◆ 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 648 of file al-matrix.H.

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

◆ 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 604 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, FunctionalMethods< Container, T >::for_each(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_domain(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_vector(), and Aleph::maps().

Referenced by Aleph::operator*().

◆ 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 989 of file al-matrix.H.

References Aleph::maps().

◆ 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 662 of file al-matrix.H.

References Aleph::maps(), and 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 766 of file al-matrix.H.

References Aleph::maps().

◆ 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 747 of file al-matrix.H.

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

◆ 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 797 of file al-matrix.H.

References Aleph::maps().

◆ 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 778 of file al-matrix.H.

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

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ 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 986 of file al-matrix.H.

◆ 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 862 of file al-matrix.H.

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

◆ row_domain_list()

◆ set_entry()

◆ 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 103 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 710 of file al-matrix.H.

References ah_domain_error_if, FunctionalMethods< Container, T >::for_each(), Aleph::DynList< T >::get(), Aleph::maps(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and Aleph::Matrix< Trow, Tcol, NumType >::set_entry().

◆ 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 691 of file al-matrix.H.

References ah_domain_error_if, Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, FunctionalMethods< Container, T >::for_each(), Aleph::DynList< T >::get(), Aleph::maps(), and Aleph::Matrix< Trow, Tcol, NumType >::set_entry().

Referenced by demo_row_col_operations().

◆ to_collist()

◆ to_rowlist()

◆ to_str()

◆ transpose()

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

Compute the transpose of this matrix.

Returns
New matrix with rows and columns swapped

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

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

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 677 of file al-matrix.H.

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

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 >
Matrix< Trow, T2col > 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 827 of file al-matrix.H.

References Aleph::for_each(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_domain(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_vector(), Aleph::maps(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and Aleph::Matrix< Trow, Tcol, NumType >::validate_domains_for_mult().

Member Data Documentation

◆ cdomain_ptr

◆ default_epsilon

const NumType Aleph::Matrix< Trow, Tcol, NumType >::default_epsilon = 1e-7
staticprivate

Definition at line 82 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

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

Referenced by Aleph::Matrix< Trow, Tcol, NumType >::Matrix(), Aleph::Matrix< Trow, Tcol, NumType >::Matrix(), Aleph::Matrix< Trow, Tcol, NumType >::equal_to(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_vector(), Aleph::Matrix< Trow, Tcol, NumType >::get_entry(), Aleph::Matrix< Trow, Tcol, NumType >::get_entry(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_as_list(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_domain(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_domain_ptr(), Aleph::Matrix< Trow, Tcol, NumType >::get_row_vector(), Aleph::Matrix< Trow, Tcol, NumType >::identity(), Aleph::Matrix< Trow, Tcol, NumType >::matrix_vector_mult(), Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_dot_product(), Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_linear_comb(), Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_sparse(), Aleph::Matrix< Trow, Tcol, NumType >::operator+=(), Aleph::Matrix< Trow, Tcol, NumType >::operator-=(), Aleph::Matrix< Trow, Tcol, NumType >::operator=(), Aleph::Matrix< Trow, Tcol, NumType >::operator=(), Aleph::Matrix< Trow, Tcol, NumType >::row_domain_list(), Aleph::Matrix< Trow, Tcol, NumType >::set_entry(), Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_col(), Aleph::Matrix< Trow, Tcol, NumType >::to_collist(), Aleph::Matrix< Trow, Tcol, NumType >::to_str(), Aleph::Matrix< Trow, Tcol, NumType >::transpose(), Aleph::Matrix< Trow, Tcol, NumType >::validate_domains_for_mult(), and Aleph::Matrix< Trow, Tcol, NumType >::vector_matrix_mult().


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