|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Sparse matrix with generic row and column domains. More...
#include <al-matrix.H>
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 (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. | |
| 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 | 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 |
| Return a list of vectors corresponding to the rows. | |
| DynList< ColVector > | to_collist () const |
| 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 |
| return this*vec in terms of linear combinations | |
| Vector< Trow, NumType > | mult_matrix_vector_sparse (const Vector< Tcol, NumType > &vec) const |
| Matrix-vector multiplication using sparse iteration. | |
| Vector< Tcol, NumType > | mult_vector_matrix_linear_comb (const Vector< Trow, NumType > &vec) const |
| return vec*this in terms of linear combinations | |
| Vector< Trow, NumType > | mult_matrix_vector_dot_product (const Vector< Tcol, NumType > &vec) const |
| Matrix-vector multiplication using dot products. | |
| Vector< Tcol, NumType > | mult_vector_matrix_dot_product (const Vector< Trow, NumType > &vec) const |
| Vector-matrix multiplication using dot products. | |
| Vector< Trow, NumType > | operator* (const Vector< Tcol, NumType > &vec) const |
| 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 > | |
| Matrix< Trow, T2col > | vector_matrix_mult (const Matrix< T2row, T2col, NumType > &m) const |
| Matrix multiplication using row-vector times matrix approach. | |
| template<typename T2row , typename T2col > | |
| Matrix< Trow, T2col > | matrix_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 |
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.
| Trow | Type of row domain elements (default: int) |
| Tcol | Type of column domain elements (default: int) |
| NumType | Numeric type for matrix entries (default: double) |
Definition at line 65 of file al-matrix.H.
Definition at line 69 of file al-matrix.H.
Definition at line 71 of file al-matrix.H.
Definition at line 77 of file al-matrix.H.
| using Aleph::Matrix< Trow, Tcol, NumType >::Map = Aleph::HashMap<RCPair, NumType, MapODhash> |
Definition at line 75 of file al-matrix.H.
Type alias for entries stored in the hash table: ((row,col), value).
Definition at line 111 of file al-matrix.H.
Definition at line 73 of file al-matrix.H.
Definition at line 68 of file al-matrix.H.
Definition at line 70 of file al-matrix.H.
Definition at line 79 of file al-matrix.H.
|
inline |
Construct an empty sparse matrix over the given domains (shared_ptr version).
| rdomain | Shared pointer to row domain |
| cdomain | Shared pointer to column domain |
| e | Epsilon for zero comparisons (default: 1e-7) |
Definition at line 130 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::set_epsilon().
|
inline |
Construct an empty sparse matrix over the given domains (reference version).
| rdomain | Row domain (will be wrapped in non-owning shared_ptr) |
| cdomain | Column domain (will be wrapped in non-owning shared_ptr) |
| e | Epsilon for zero comparisons (default: 1e-7) |
Definition at line 146 of file al-matrix.H.
|
inline |
Construct a matrix from a 2D initializer list (shared_ptr version).
| rdomain | Shared pointer to row domain |
| cdomain | Shared pointer to column domain |
| l | Initializer list of rows (each row is a list of values) |
| e | Epsilon for zero comparisons |
| ah_range_error | if 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().
|
inline |
Construct a matrix from a 2D initializer list (reference version).
| rdomain | Row domain (will be wrapped in non-owning shared_ptr) |
| cdomain | Column domain (will be wrapped in non-owning shared_ptr) |
| l | Initializer list of rows |
| e | Epsilon for zero comparisons |
Definition at line 197 of file al-matrix.H.
|
inline |
Construct a matrix from a list of lists (shared_ptr version).
| rdomain | Shared pointer to row domain |
| cdomain | Shared pointer to column domain |
| l | List of rows (each row is a DynList of values) |
| e | Epsilon for zero comparisons |
| ah_range_error | if 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().
|
inline |
Construct a matrix from a list of lists (reference version).
| rdomain | Row domain (will be wrapped in non-owning shared_ptr) |
| cdomain | Column domain (will be wrapped in non-owning shared_ptr) |
| l | List of rows |
| e | Epsilon for zero comparisons |
Definition at line 242 of file al-matrix.H.
Copy constructor.
Definition at line 250 of file al-matrix.H.
|
inlinenoexcept |
Move constructor.
Definition at line 260 of file al-matrix.H.
|
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().
Return a sorted list of column domain keys.
Definition at line 441 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, and Aleph::sort().
Referenced by Aleph::Matrix< Trow, Tcol, NumType >::get_row_as_list(), Aleph::Matrix< Trow, Tcol, NumType >::to_collist(), and Aleph::Matrix< Trow, Tcol, NumType >::to_rowlist().
|
inlinestatic |
Create a matrix from a list of column vectors.
| cdomain | Column domain |
| cols | List of vectors, one per column |
| e | Epsilon for zero comparisons |
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().
|
inlinestatic |
Create a matrix from a list of row vectors.
| rdomain | Row domain |
| rows | List of vectors, one per row |
| e | Epsilon for zero comparisons |
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().
|
inline |
Check if this matrix equals another (within epsilon).
| m | Matrix to compare with |
| ah_domain_error | if 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.
|
inline |
Get a column as a list of values (in row order).
| col | Column index |
| ah_domain_error | if 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().
Return the column domain.
Definition at line 117 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr.
Referenced by 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(), and Aleph::Matrix< Trow, Tcol, NumType >::vector_matrix_mult().
|
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.
|
inline |
Given a column, build a vector corresponding to the column.
Definition at line 530 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.
Referenced by demo_row_col_operations(), Aleph::Matrix< Trow, Tcol, NumType >::matrix_vector_mult(), Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_linear_comb(), Aleph::Matrix< Trow, Tcol, NumType >::mult_vector_matrix_dot_product(), and TEST_F().
|
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.
| row | Row index |
| col | Column index |
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().
|
inlinenoexcept |
Get an entry value (const version, no cleanup).
| row | Row index |
| col | Column index |
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.
Return the epsilon value used for zero comparisons.
Definition at line 97 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::epsilon.
|
inline |
Get a row as a list of values (in column order).
| row | Row index |
| ah_domain_error | if 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().
Return the row domain.
Definition at line 114 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr.
Referenced by Aleph::Matrix< Trow, Tcol, NumType >::mult_vector_matrix_dot_product(), and Aleph::Matrix< Trow, Tcol, NumType >::mult_vector_matrix_linear_comb().
|
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.
|
inline |
Given a row, build a vector corresponding to the row.
Definition at line 515 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.
Referenced by demo_adjacency_matrix(), demo_row_col_operations(), Aleph::Matrix< Trow, Tcol, NumType >::mult_matrix_vector_dot_product(), Aleph::Matrix< Trow, Tcol, NumType >::mult_vector_matrix_linear_comb(), TEST_F(), and Aleph::Matrix< Trow, Tcol, NumType >::vector_matrix_mult().
|
inline |
Create an identity matrix (only for square matrices).
Requires that Trow == Tcol (enforced by static_assert).
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().
|
inlineprivatenoexcept |
Definition at line 89 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::epsilon, and Aleph::maps().
Referenced by Aleph::Matrix< Trow, Tcol, NumType >::Matrix(), Aleph::Matrix< Trow, Tcol, NumType >::Matrix(), Aleph::Matrix< Trow, Tcol, NumType >::are_equal(), Aleph::Matrix< Trow, Tcol, NumType >::get_entry(), and Aleph::Matrix< Trow, Tcol, NumType >::set_entry().
|
inline |
Matrix multiplication using matrix times column-vector approach.
| T2row | Row type of second matrix |
| T2col | Column type of second matrix |
| m | Matrix to multiply with |
| ah_domain_error | if 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().
Multiply all entries by a scalar (in-place).
| scalar | Value to multiply by |
Definition at line 808 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::entries, and Aleph::maps().
Referenced by demo_matrix_arithmetic().
|
inline |
Matrix-vector multiplication using dot products.
Computes each result entry as dot product of row vector and input.
| vec | Column vector to multiply |
| ah_domain_error | if 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.
|
inline |
return this*vec in terms of linear combinations
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*().
|
inline |
Matrix-vector multiplication using sparse iteration.
Iterates only over non-zero matrix entries for efficiency.
| vec | Column vector to multiply |
| ah_domain_error | if 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.
|
inline |
Vector-matrix multiplication using dot products.
Computes each result entry as dot product of input and column vector.
| vec | Row vector to multiply |
| ah_domain_error | if 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().
|
inline |
return vec*this in terms of linear combinations
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*().
|
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().
|
inline |
Add another matrix to this one.
| m | Matrix to add (must share same domains) |
| ah_domain_error | if 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.
|
inline |
Subtract another matrix from this one.
| m | Matrix to subtract (must share same domains) |
| ah_domain_error | if 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.
|
inline |
Copy assignment operator.
Definition at line 270 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::epsilon, Aleph::maps(), and Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr.
|
inlinenoexcept |
Move assignment operator.
Definition at line 283 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::epsilon, Aleph::maps(), and Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr.
|
inline |
Equality operator (uses equal_to).
Definition at line 986 of file al-matrix.H.
|
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().
Return a sorted list of row domain keys.
Definition at line 435 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and Aleph::sort().
Referenced by Aleph::Matrix< Trow, Tcol, NumType >::get_col_as_list(), Aleph::Matrix< Trow, Tcol, NumType >::to_collist(), Aleph::Matrix< Trow, Tcol, NumType >::to_rowlist(), and Aleph::Matrix< Trow, Tcol, NumType >::to_str().
|
inline |
Set an entry value.
If the value is within epsilon of zero, the entry is removed from the hash table (sparse storage optimization).
| row | Row index |
| col | Column index |
| val | Value to set |
Definition at line 403 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_linear_system(), demo_matrix_vector_mult(), demo_row_col_operations(), demo_sparse_matrix(), demo_transpose(), Aleph::Matrix< Trow, Tcol, NumType >::identity(), Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_col(), and Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_row().
Set the epsilon value for zero comparisons.
| e | New epsilon value (must be >= 0) |
| ah_domain_error | if 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().
|
inline |
Set a column from a vector.
| col | Column index |
| vec | Vector with row domain |
| ah_domain_error | if 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().
|
inline |
Set a row from a vector.
| row | Row index |
| vec | Vector with column domain |
| ah_domain_error | if 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().
Return a list of vectors corresponding to the columns.
Definition at line 495 of file al-matrix.H.
References Aleph::DynList< T >::append(), Aleph::Matrix< Trow, Tcol, NumType >::col_domain_list(), Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::epsilon, Aleph::for_each(), FunctionalMethods< Container, T >::for_each(), Aleph::maps(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, and Aleph::Matrix< Trow, Tcol, NumType >::row_domain_list().
Referenced by Aleph::Matrix< Trow, Tcol, NumType >::to_str().
|
inline |
Return a list of vectors corresponding to the rows.
Definition at line 474 of file al-matrix.H.
References Aleph::DynList< T >::append(), Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::col_domain_list(), Aleph::Matrix< Trow, Tcol, NumType >::entries, Aleph::Matrix< Trow, Tcol, NumType >::epsilon, Aleph::for_each(), FunctionalMethods< Container, T >::for_each(), Aleph::maps(), and Aleph::Matrix< Trow, Tcol, NumType >::row_domain_list().
Referenced by demo_row_col_operations().
|
inline |
Convert matrix to a formatted string representation.
Definition at line 875 of file al-matrix.H.
References Aleph::Matrix< Trow, Tcol, NumType >::cdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::get_row_as_list(), Aleph::maps(), Aleph::Matrix< Trow, Tcol, NumType >::rdomain_ptr, Aleph::Matrix< Trow, Tcol, NumType >::row_domain_list(), Aleph::HTList::size(), Aleph::sort(), Aleph::Matrix< Trow, Tcol, NumType >::to_collist(), Aleph::to_str(), and Aleph::zip().
Referenced by demo_linear_system(), demo_matrix_arithmetic(), demo_row_col_operations(), demo_transpose(), and Aleph::operator<<().
|
inline |
Compute the transpose of this matrix.
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().
|
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).
| m | Matrix to multiply with |
| ah_domain_error | if 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().
|
inline |
Matrix multiplication using row-vector times matrix approach.
| T2row | Row type of second matrix |
| T2col | Column type of second matrix |
| m | Matrix to multiply with |
| ah_domain_error | if 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().
|
private |
Definition at line 85 of file al-matrix.H.
Referenced by Aleph::Matrix< Trow, Tcol, NumType >::Matrix(), Aleph::Matrix< Trow, Tcol, NumType >::Matrix(), Aleph::Matrix< Trow, Tcol, NumType >::col_domain_list(), Aleph::Matrix< Trow, Tcol, NumType >::equal_to(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_as_list(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_domain(), Aleph::Matrix< Trow, Tcol, NumType >::get_col_domain_ptr(), 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_vector(), Aleph::Matrix< Trow, Tcol, NumType >::mult_vector_matrix_dot_product(), Aleph::Matrix< Trow, Tcol, NumType >::mult_vector_matrix_linear_comb(), 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 >::set_entry(), Aleph::Matrix< Trow, Tcol, NumType >::set_vector_as_row(), Aleph::Matrix< Trow, Tcol, NumType >::to_rowlist(), Aleph::Matrix< Trow, Tcol, NumType >::to_str(), Aleph::Matrix< Trow, Tcol, NumType >::transpose(), and Aleph::Matrix< Trow, Tcol, NumType >::validate_domains_for_mult().
Definition at line 82 of file al-matrix.H.
|
private |
Definition at line 86 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_vector(), Aleph::Matrix< Trow, Tcol, NumType >::mult_by_scalar(), 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 >::print(), Aleph::Matrix< Trow, Tcol, NumType >::set_entry(), Aleph::Matrix< Trow, Tcol, NumType >::to_collist(), Aleph::Matrix< Trow, Tcol, NumType >::to_rowlist(), and Aleph::Matrix< Trow, Tcol, NumType >::transpose().
|
private |
Definition at line 87 of file al-matrix.H.
Referenced by Aleph::Matrix< Trow, Tcol, NumType >::get_epsilon(), Aleph::Matrix< Trow, Tcol, NumType >::is_zero(), Aleph::Matrix< Trow, Tcol, NumType >::operator=(), Aleph::Matrix< Trow, Tcol, NumType >::operator=(), Aleph::Matrix< Trow, Tcol, NumType >::set_epsilon(), Aleph::Matrix< Trow, Tcol, NumType >::to_collist(), and Aleph::Matrix< Trow, Tcol, NumType >::to_rowlist().
|
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().