|
CGAL 6.2 - Homological Discrete Vector Fields
|
#include <CGAL/OSM/Sparse_chain.h>
The class Sparse_chain implements the concept SparseChain, that is, sparse vectors (encoding homological chains) optimized for topological computations.
Given a complex (for instance a simplicial, cubical or cellular complex) which cells in a given dimension \(q\) are numbered \(\{\sigma_i\,;\, i=1\ldots n_q\}\), homology with coefficients in a given ring \(\mathbb K\) defines \(q\)-chains as formal linear combinations:
\[\gamma = \sum_{i=1}^{n_q}\lambda_i\cdot \sigma_i\]
with coefficients \(\lambda_i\in\mathbb K\). In the basis \(\{\sigma_i\,;\, i=1\ldots n_q\}\), the coordinates of \(\gamma\) are given by the vector: \([\lambda_1,\ldots \lambda_{n_q}]\).
Now, as chains considered in homology are boundaries of cells, most \(\lambda_i\) coefficients are null. Hence Sparse_chain encodes such vectors in a "sparse" way, that is, storing only non zero coefficients through a map:
\[i\mapsto \lambda_i\ \ \ \forall i=1\ldots n_q\text{ such that }\lambda_i\neq 0\]
Moreover, as per any linear algebra vector, a Sparse_chain is either a column or row vector (the StorageFormat parameter determines this storage format).
The class Sparse_chain provides standard linear algebra operators and fast iterators and block operations (set, get and nullify) which are required to implement efficiently HDVFs.
SparseChain | CoefficientRing | a model of the IntegralDomainWithoutDivision concept, providing the ring used to compute homology. |
| StorageFormat | an integer constant encoding the storage format of matrices (CGAL::OSM::COLUMN or CGAL::OSM::ROW). |
Public Types | |
| typedef CoefficientRing | Coefficient_ring |
| Type of the coefficient ring. | |
| typedef std::unordered_map< size_t, CoefficientRing >::iterator | iterator |
| Type of chains iterators. | |
| typedef std::unordered_map< size_t, CoefficientRing >::const_iterator | const_iterator |
| Type of chains constant iterators. | |
Public Member Functions | |
| Sparse_chain () | |
| Creates new empty sparse chain. | |
| Sparse_chain (const size_t chain_size) | |
| Creates new empty sparse chain (ie. | |
| Sparse_chain (const Sparse_chain &otherToCopy) | |
| Creates new SparseChain by copy. | |
| Sparse_chain & | operator= (const Sparse_chain &otherToCopy) |
| Assigns to other chain. | |
| size_t | dimension () const |
| Size of the chain. | |
| Sparse_chain | operator+ (const Sparse_chain &other) |
| Adds two chains. | |
| Sparse_chain | operator- (const Sparse_chain &other) |
| Subtracts a chain from current chain. | |
| Sparse_chain | operator* (const CoefficientRing &lambda) |
| Applies multiplication on each coefficient. | |
| Sparse_chain & | operator+= (const Sparse_chain &other) |
Adds a chain to this. | |
| Sparse_chain & | operator-= (const Sparse_chain &other) |
Sustracts a chain to this. | |
| Sparse_chain & | operator*= (const CoefficientRing &lambda) |
Applies multiplication on each coefficient of this. | |
| Coefficient_ring | operator[] (size_t index) const |
| Gets the value of a coefficient of the chain. | |
| Coefficient_ring | get_coefficient (size_t index) const |
| Gets the value of a coefficient of the chain. | |
| void | set_coefficient (size_t index, Coefficient_ring d) |
| Sets a given coefficient of the chain. | |
| const bool | is_null (size_t index) const |
| Checks if a coefficient is null. | |
| const bool | is_null () const |
| Checks if the chain is null. | |
| Sparse_chain | operator/ (const std::vector< size_t > &indices) |
| Gets a subchain from the chain. | |
| Sparse_chain | operator/ (size_t index) |
| Gets a subchain from the chain. | |
| Sparse_chain & | operator/= (const std::vector< size_t > &indices) |
| Restricts the chain to a sub-chain by removing indices. | |
| Sparse_chain & | operator/= (const size_t index) |
| Restricts the chain to a sub-chain by removing a given index. | |
| void | nullify () |
| Removes all coefficients from the chain. | |
| iterator | begin () noexcept |
| Iterator to the beginning of the chain. | |
| const_iterator | begin () const noexcept |
| Constant iterator to the beginning of the chain. | |
| const_iterator | cbegin () const noexcept |
| Constant iterator to the beginning of the chain. | |
| iterator | end () noexcept |
| Iterator to the end of the chain. | |
| const_iterator | end () const noexcept |
| Constant iterator to the end of the chain. | |
| const_iterator | cend () const noexcept |
| Constant iterator to the end of the chain. | |
| Sparse_chain< CoefficientRing, COLUMN+ROW - StorageFormat > | transpose () |
| Transposes a sparse chain. | |
| bool | is_column () const |
| Checks if chain is a column. | |
| bool | is_row () const |
| Checks if chain is a row. | |
Protected Types | |
| typedef std::pair< size_t, CoefficientRing > | pair |
Protected Attributes | |
| std::unordered_map< size_t, CoefficientRing > | _chainData |
| size_t | _upperBound |
Friends | |
| template<typename _CT , int _CTF> | |
| class | Sparse_chain |
| template<typename _CT , int _CTF> | |
| class | Sparse_matrix |
| template<typename _CT > | |
| bool | operator== (const Sparse_chain< _CT, OSM::COLUMN > &chain, const Sparse_chain< _CT, OSM::COLUMN > &other) |
Comparison of two COLUMN chains. | |
| template<typename _CT > | |
| bool | operator== (const Sparse_chain< _CT, OSM::COLUMN > &chain, const Sparse_chain< _CT, OSM::ROW > &other) |
Comparison of a COLUMN and a ROW chain. | |
| template<typename _CT > | |
| bool | operator== (const Sparse_chain< _CT, OSM::ROW > &chain, const Sparse_chain< _CT, OSM::COLUMN > &other) |
Comparison of a ROW and a COLUMN chain. | |
| template<typename _CT > | |
| bool | operator== (const Sparse_chain< _CT, OSM::ROW > &chain, const Sparse_chain< _CT, OSM::ROW > &other) |
Comparison of two ROW chains. | |
Related Functions | |
(Note that these are not member functions.) | |
| std::ostream & | operator<< (std::ostream &stream, const Sparse_chain &chain) |
| writes a sparse chain in the output stream. | |
| template<int _CTF> | |
| Sparse_chain | operator* (const CoefficientRing &lambda, const Sparse_chain< CoefficientRing, _CTF > &chain) |
| Applies multiplication on each coefficient. | |
| template<typename _CT > | |
| Sparse_matrix< _CT, COLUMN > | operator* (const Sparse_chain< _CT, COLUMN > &column, const Sparse_chain< _CT, ROW > &row) |
| Performs matrix multiplication between two chains (COLUMN x ROW) and return a COLUMN matrix. | |
| template<typename _CT > | |
| Sparse_matrix< _CT, ROW > | operator% (const Sparse_chain< _CT, COLUMN > &column, const Sparse_chain< _CT, ROW > &row) |
| Performs matrix multiplication between two chains (COLUMN x ROW) and return a ROW matrix. | |
| template<typename _CT > | |
| _CT | operator* (const Sparse_chain< _CT, ROW > &row, const Sparse_chain< _CT, COLUMN > &column) |
| Performs dot product between two chains (ROW x COLUMN). | |
| CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::Sparse_chain | ( | ) |
Creates new empty sparse chain.
Creates a sparse chain encoding an empty linear combination of cells.
| CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::Sparse_chain | ( | const size_t | chain_size | ) |
Creates new empty sparse chain (ie.
zero-chain) of given size.
Constructor with size, initializes an empty sparse chain encoding a linear combination of cells with all coefficients null.
| chain_size | The size of the sparse chain. |
| CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::Sparse_chain | ( | const Sparse_chain< CoefficientRing, StorageFormat > & | otherToCopy | ) |
Creates new SparseChain by copy.
Copy constructor, initialize a sparse chain from an existing sparse chain.
CoefficientRing and StorageFormat.| otherToCopy | The chain to copy. |
|
noexcept |
Constant iterator to the beginning of the chain.
|
noexcept |
Iterator to the beginning of the chain.
|
noexcept |
Constant iterator to the beginning of the chain.
|
noexcept |
Constant iterator to the end of the chain.
| size_t CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::dimension | ( | ) | const |
Size of the chain.
|
noexcept |
Constant iterator to the end of the chain.
|
noexcept |
Iterator to the end of the chain.
| Coefficient_ring CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::get_coefficient | ( | size_t | index | ) | const |
Gets the value of a coefficient of the chain.
| index | The coefficient index. |
| bool CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::is_column | ( | ) | const |
Checks if chain is a column.
| const bool CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::is_null | ( | ) | const |
Checks if the chain is null.
| const bool CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::is_null | ( | size_t | index | ) | const |
Checks if a coefficient is null.
| index | The index to check. |
| bool CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::is_row | ( | ) | const |
Checks if chain is a row.
| void CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::nullify | ( | ) |
Removes all coefficients from the chain.
The function comes to set all coefficients to zero.
| Sparse_chain CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator* | ( | const CoefficientRing & | lambda | ) |
Applies multiplication on each coefficient.
| lambda | The factor to apply. |
| Sparse_chain & CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator*= | ( | const CoefficientRing & | lambda | ) |
Applies multiplication on each coefficient of this.
If lambda is null, this function comes to nullify the chain.
| lambda | The factor to apply. |
| Sparse_chain CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator+ | ( | const Sparse_chain< CoefficientRing, StorageFormat > & | other | ) |
Adds two chains.
Adds two chains and return the result in a new matrix.
CoefficientRing and the same StorageFormat.CoefficientRing. StorageFormat.| other | The other chain. |
| Sparse_chain & CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator+= | ( | const Sparse_chain< CoefficientRing, StorageFormat > & | other | ) |
Adds a chain to this.
Add a chain to this.
CoefficientRing and the same StorageFormat.CoefficientRing. StorageFormat.| other | The other chain. |
| Sparse_chain CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator- | ( | const Sparse_chain< CoefficientRing, StorageFormat > & | other | ) |
Subtracts a chain from current chain.
Subtract other chain from current chain and return the result in a new matrix.
CoefficientRing and the same StorageFormat.CoefficientRing. StorageFormat.| other | The other chain. |
| Sparse_chain & CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator-= | ( | const Sparse_chain< CoefficientRing, StorageFormat > & | other | ) |
Sustracts a chain to this.
Subtract a chain to this.
CoefficientRing and the same StorageFormat.CoefficientRing. StorageFormat.| other | The other chain. |
| Sparse_chain CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator/ | ( | const std::vector< size_t > & | indices | ) |
Gets a subchain from the chain.
Return a new chain where all coefficients of indices provided in the vector are removed.
indices is empty.| indices | The indices to remove. |
| Sparse_chain CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator/ | ( | size_t | index | ) |
Gets a subchain from the chain.
Return a new chain where the coefficients at a given index is removed.
| index | The index to remove. |
| Sparse_chain & CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator/= | ( | const size_t | index | ) |
Restricts the chain to a sub-chain by removing a given index.
Removes the index provided from the chain.
| index | The index to remove. |
| Sparse_chain & CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator/= | ( | const std::vector< size_t > & | indices | ) |
Restricts the chain to a sub-chain by removing indices.
Removes all indices provided in the vector from the chain. Return a reference to the modified chain.
indices is empty.| indices | The indices to remove. |
| Sparse_chain & CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator= | ( | const Sparse_chain< CoefficientRing, StorageFormat > & | otherToCopy | ) |
Assigns to other chain.
Assign to other chain coefficient-wise, equivalent to copying it.
CoefficientRing.| otherToCopy | The chain we want to copy. |
| Coefficient_ring CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::operator[] | ( | size_t | index | ) | const |
Gets the value of a coefficient of the chain.
| index | The coefficient index. |
| void CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::set_coefficient | ( | size_t | index, |
| Coefficient_ring | d | ||
| ) |
Sets a given coefficient of the chain.
Set the value of the coefficient in the chain at index.
| index | The coefficient index. |
| d | Value of the coefficient |
| Sparse_chain< CoefficientRing, COLUMN+ROW - StorageFormat > CGAL::OSM::Sparse_chain< CoefficientRing, StorageFormat >::transpose | ( | ) |
Transposes a sparse chain.
The result is a chain with StorageFormat switched between COLUMN and ROW.
StorageFormat is changed.
|
friend |
Performs matrix multiplication between two chains (COLUMN x ROW) and return a ROW matrix.
Generate a row-based matrix from the matrix multiplication and return it.
CoefficientRing.CoefficientRing.| column | The column chain. |
| row | The row chain. |
|
friend |
Applies multiplication on each coefficient.
| lambda | The factor to apply. |
| chain | The chain. |
|
friend |
Performs matrix multiplication between two chains (COLUMN x ROW) and return a COLUMN matrix.
Generate a column-based matrix from the matrix multiplication and return it.
CoefficientRing.CoefficientRing.| column | The column chain. |
| row | The row chain. |
|
friend |
Performs dot product between two chains (ROW x COLUMN).
CoefficientRing.CoefficientRing.| row | The row chain. |
| column | The column chain. |
|
friend |
writes a sparse chain in the output stream.
| stream | The output stream. |
| chain | The chain to display. |