CGAL 6.2 - Homological Discrete Vector Fields
Loading...
Searching...
No Matches

Definition

The concept SparseChain describes the requirements for sparse vectors (called sparse chains in homology) optimized for topological computations. More precisely, SparseChain provides all the operations on chains required by the SparseMatrix concept.

SparseChain encodes non zero coefficients of a sparse vector.

SparseChain can be either row or column vectors. The following constants, called StorageFormat, encode the direction of sparse chains (and sparse matrices).

Has models
CGAL::OSM::Sparse_chain<CoefficientRing, StorageFormat>
See also
IntegralDomainWithoutDivision
SparseMatrix

Types

typedef unspecified_type Coefficient_ring
 Type of coefficients stored in the matrix (a model of IntegralDomainWithoutDivision).
 
typedef int Storage_format
 Matrix and chain storage format (either CGAL::OSM::ROW or CGAL::OSM::COLUMN).
 
typedef unspecified_type iterator
 Sparse chain iterator type.
 
typedef unspecified_type const_iterator
 Sparse chain constant iterator type.
 

Creation, filling

 SparseChain ()
 Creates new empty sparse chain.
 
 SparseChain (size_t chainSize)
 Creates new empty sparse chain (ie. zero-chain) of given size.
 
 SparseChain (const SparseChain &other)
 Creates new sparse chain by copy.
 
SparseChainoperator= (const SparseChain &other)
 Assigns to other chain.
 

Matrix informations and iterators

size_t dimension () const
 Returns the dimension of the basis (that is, size of 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
 Past-the-end iterator of the chain.
 
const_iterator end () const noexcept
 Constant past-the-end iterator of the chain.
 
const_iterator cend () const noexcept
 Constant past-the-end iterator of the chain.
 

Linear algebra operators

SparseChainoperator+= (const SparseChain &_other)
 Adds a chain to this.
 
SparseChainoperator-= (const SparseChain &_other)
 Subtracts a chain from this.
 
SparseChainoperator*= (const Coefficient_ring &lambda)
 Applies multiplication on each coefficient of this.
 
SparseChain transpose ()
 Transposes a sparse chain.
 
SparseChain operator+ (const SparseChain &first, const SparseChain &second)
 Adds two chains together.
 
SparseChain operator- (const SparseChain &first, const SparseChain &second)
 Subtracts a chain from another chain.
 
SparseChain operator* (const Coefficient_ring &lambda, const SparseChain &chain)
 Applies multiplication on each coefficient.
 
SparseChain operator* (const SparseChain &_chain, const Coefficient_ring &lambda)
 Applies multiplication on each coefficient.
 
SparseMatrix operator* (const SparseChain &column, const SparseChain &row)
 Performs matrix multiplication between a column chain and a row chain and returns a column-based matrix.
 
SparseMatrix operator% (const Sparse_chain &column, const Sparse_chain &row)
 Performs matrix multiplication between a column chain and a row chain and returns a row-based matrix.
 
Coefficient_ring operator* (const Sparse_chain &row, const Sparse_chain &column)
 Performs dot product between a row chain and a column chain.
 

Access and modifications

bool operator== (const SparseChain &other_chain)
 Compares two chains.
 
Coefficient_ring operator[] (size_t index)
 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.
 
bool is_null (size_t index) const
 Checks if a coefficient of the chain is null.
 
bool is_null () const
 Checks if the chain is null.
 
SparseChainoperator/= (const std::vector< size_t > &indices)
 Restricts the chain to a sub-chain by removing indices.
 
SparseChainoperator/= (size_t index)
 Restricts the chain to a sub-chain by removing a given index.
 
void nullify ()
 Removes all coefficients from the chain.
 
bool is_column () const
 Checks if chain is a column.
 
bool is_row () const
 Checks if chain is a row.
 
SparseChain operator/ (const SparseChain &chain, const std::vector< size_t > &indices)
 Gets a sub-chain from the chain.
 
SparseChain operator/ (const SparseChain &chain, size_t indices)
 Gets a sub-chain from the chain.
 

Output

std::ostream & operator<< (std::ostream &stream, const SparseChain &chain)
 Inserts chain in the output stream.
 

Constructor & Destructor Documentation

◆ SparseChain() [1/3]

SparseChain::SparseChain ( )

Creates new empty sparse chain.

Creates a sparse chain encoding an empty linear combination of cells.

◆ SparseChain() [2/3]

SparseChain::SparseChain ( size_t  chainSize)

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.

◆ SparseChain() [3/3]

SparseChain::SparseChain ( const SparseChain other)

Creates new sparse chain by copy.

Copy constructor, initialize a sparse chain from an existing sparse chain of same storage format.

Member Function Documentation

◆ begin() [1/2]

const_iterator SparseChain::begin ( ) const
noexcept

Constant iterator to the beginning of the chain.

The function returns a constant iterator to the first non zero index.

◆ begin() [2/2]

iterator SparseChain::begin ( )
noexcept

Iterator to the beginning of the chain.

The function returns an iterator to the first non zero index.

◆ cbegin()

const_iterator SparseChain::cbegin ( ) const
noexcept

Constant iterator to the beginning of the chain.

The function returns a constant iterator to the first non zero index.

◆ cend()

const_iterator SparseChain::cend ( ) const
noexcept

Constant past-the-end iterator of the chain.

The function returns a constant iterator past the endi of the chain.

◆ end() [1/2]

const_iterator SparseChain::end ( ) const
noexcept

Constant past-the-end iterator of the chain.

The function returns a constant iterator past the end of the chain.

◆ end() [2/2]

iterator SparseChain::end ( )
noexcept

Past-the-end iterator of the chain.

The function returns an iterator past the end of the chain.

◆ nullify()

void SparseChain::nullify ( )

Removes all coefficients from the chain.

The function comes to set all coefficients to zero.

◆ operator+=()

SparseChain & SparseChain::operator+= ( const SparseChain _other)

Adds a chain to this.

Add a chain to this. Chains must have the same Coefficient_ring and the same storage format.

◆ operator-=()

SparseChain & SparseChain::operator-= ( const SparseChain _other)

Subtracts a chain from this.

Subtract a chain from this. Chains must have the same Coefficient_ring and the same storage format.

◆ operator/=() [1/2]

SparseChain & SparseChain::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.

◆ operator/=() [2/2]

SparseChain & SparseChain::operator/= ( size_t  index)

Restricts the chain to a sub-chain by removing a given index.

Removes the index provided from the chain. Return a reference to the modified chain.

◆ operator=()

SparseChain & SparseChain::operator= ( const SparseChain other)

Assigns to other chain.

Assign to other chain coefficient-wise, equivalent to copying it.

SparseChain must have the same Coefficient_ring.

◆ transpose()

SparseChain SparseChain::transpose ( )

Transposes a sparse chain.

The result is a chain with storage format switched between column and row.

Friends And Related Function Documentation

◆ operator%

SparseMatrix operator% ( const Sparse_chain &  column,
const Sparse_chain &  row 
)
friend

Performs matrix multiplication between a column chain and a row chain and returns a row-based matrix.

Generate a row-based matrix from the matrix multiplication and return it.

Precondition
chains must have the same Coefficient_ring.
column.is_column() and row.is_row() must be true

◆ operator* [1/2]

Coefficient_ring operator* ( const Sparse_chain &  row,
const Sparse_chain &  column 
)
friend

Performs dot product between a row chain and a column chain.

Precondition
chains must have the same Coefficient_ring.
row.is_row() and column.is_column() must be true

◆ operator* [2/2]

SparseMatrix operator* ( const SparseChain column,
const SparseChain row 
)
friend

Performs matrix multiplication between a column chain and a row chain and returns a column-based matrix.

Generate a column-based matrix from the matrix multiplication and return it.

Precondition
chains must have the same Coefficient_ring.
column.is_column() and row.is_row() must be true

◆ operator+

SparseChain operator+ ( const SparseChain first,
const SparseChain second 
)
friend

Adds two chains together.

Add two chains and return the result in a new matrix. Chains must have the same Coefficient_ring and the same storage format.

◆ operator-

SparseChain operator- ( const SparseChain first,
const SparseChain second 
)
friend

Subtracts a chain from another chain.

Subtract two chains and return the result in a new matrix. Chains must have the same Coefficient_ring and the same storage format.

◆ operator/ [1/2]

SparseChain operator/ ( const SparseChain chain,
const std::vector< size_t > &  indices 
)
friend

Gets a sub-chain from the chain.

Return a new chain where all coefficients of indices provided in the vector are removed.

◆ operator/ [2/2]

SparseChain operator/ ( const SparseChain chain,
size_t  indices 
)
friend

Gets a sub-chain from the chain.

Return a new chain where the coefficients at a given index is removed.