template<typename CoefficientType, int ChainTypeFlag>
class CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag >
The class Sparse_matrix implements the concept SparseMatrix, that is, sparse matrices optimized for topological computations.
It provides standard linear algebra operators and fast iterators and block operations (set, get and nullify) which are required to implement efficiently HDVFs.
The implementation is based on mapped sparse matrices. Hence matrices of the Sparse_matrix class are either column of row major (the ChainTypeFlag parameter determines the type). A column-major (resp. row-major) Sparse_matrix is a vector of Sparse_chains which encode columns (res. rows). Moreover, in order to efficiently iterate over non empty columns (resp. rows) the Bitboard data structure implements the concept SparseMatrix::NonZeroChainIndices. A bitboard is basically a bucket of bits recording the indices of non empty chains. However, this data structure has been designed in order to efficiently remove or add indices, as well as provide efficient iterators to visit non empty chains.
For instance, let us consider the \(5\times 4\) matrix:
\[
A = \left(\begin{array}{cccc}
1 & \cdot & \cdot & \cdot \\
-1 & \cdot & 2 & \cdot\\
\cdot & \cdot & 1 & \cdot \\
\cdot & \cdot & \cdot & \cdot \\
\cdot & \cdot & \cdot & \cdot \\
\end{array}\right)
\]
where \(\cdot\) means \(0\).
Figures below shows the data structures are created according to the chosen representation (left: column-major, right: row-major):

- Is model of
SparseMatrix
- Template Parameters
-
| CoefficientType | a model of the Ring concept, providing the ring used to compute homology. |
| ChainTypeFlag | an integer constant encoding the type of matrices (OSM::COLUMN or OSM::ROW). |
- Examples
- HDVF/example_matrix_chain.cpp.
|
|
template<typename _CT , int _CTF> |
| class | Sparse_matrix |
| |
|
template<typename _CT > |
| bool | operator== (const Sparse_matrix< _CT, OSM::COLUMN > &matrix, const Sparse_matrix< _CT, OSM::COLUMN > &other) |
| | Comparison of two COLUMN matrices.
|
| |
|
template<typename _CT > |
| bool | operator== (const Sparse_matrix< _CT, OSM::COLUMN > &matrix, const Sparse_matrix< _CT, OSM::ROW > &other) |
| | Comparison of a COLUMN and a ROW matrix.
|
| |
|
template<typename _CT > |
| bool | operator== (const Sparse_matrix< _CT, OSM::ROW > &matrix, const Sparse_matrix< _CT, OSM::COLUMN > &other) |
| | Comparison of a ROW and a COLUMN matrix.
|
| |
|
template<typename _CT > |
| bool | operator== (const Sparse_matrix< _CT, OSM::ROW > &matrix, const Sparse_matrix< _CT, OSM::ROW > &other) |
| | Comparison of two ROW matrices.
|
| |
| std::ostream & | operator<< (std::ostream &stream, const Sparse_matrix &matrix) |
| | Displays a matrix in the output stream.
|
| |
|
template<typename _CT > |
| std::ostream & | write_matrix (const Sparse_matrix< _CT, OSM::COLUMN > &M, std::ostream &out) |
| | Writes a sparse COLUMN matrix.
|
| |
|
template<typename _CT > |
| std::ostream & | write_matrix (const Sparse_matrix< _CT, OSM::ROW > &M, std::ostream &out) |
| | Writes a sparse ROW matrix.
|
| |
|
template<typename _CT > |
| std::istream & | read_matrix (Sparse_matrix< _CT, OSM::COLUMN > &M, std::istream &in) |
| | Reads a sparse COLUMN matrix.
|
| |
|
template<typename _CT > |
| std::istream & | read_matrix (Sparse_matrix< _CT, OSM::ROW > &M, std::istream &in) |
| | Reads a sparse ROW matrix.
|
| |
| template<int _CTF> |
| Sparse_matrix | operator+ (const Sparse_matrix &first, const Sparse_matrix< CoefficientType, _CTF > &second) |
| | Adds two matrices together into a new matrix.
|
| |
| template<int _CTF> |
| Sparse_matrix | operator- (const Sparse_matrix &first, const Sparse_matrix< CoefficientType, _CTF > &second) |
| | Substracts two matrices together into a new matrix.
|
| |
| template<typename _CT , int _CTF> |
| Sparse_matrix | operator* (const _CT &lambda, const Sparse_matrix< _CT, _CTF > &matrix) |
| | Applies factor on each coefficients into a new matrix.
|
| |
| template<typename _CT , int _CTF> |
| Sparse_matrix | operator* (const Sparse_matrix< _CT, _CTF > &matrix, const _CT &lambda) |
| | Applies factor on each coefficients into a new matrix.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, COLUMN > | operator* (const Sparse_matrix< _CT, COLUMN > &first, const Sparse_matrix< _CT, COLUMN > &second) |
| | Matrices product: COLUMN x COLUMN -> COLUMN.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, COLUMN > | operator* (const Sparse_matrix< _CT, ROW > &first, const Sparse_matrix< _CT, COLUMN > &second) |
| | Matrices product: ROW x COLUMN -> COLUMN.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, COLUMN > | operator* (const Sparse_matrix< _CT, COLUMN > &first, const Sparse_matrix< _CT, ROW > &second) |
| | Matrices product: COLUMN x ROW -> COLUMN.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, COLUMN > | operator* (const Sparse_matrix< _CT, ROW > &first, const Sparse_matrix< _CT, ROW > &second) |
| | Matrices product: ROW x ROW -> COLUMN.
|
| |
|
template<typename _CT > |
| Sparse_chain< _CT, COLUMN > | operator* (const Sparse_matrix< _CT, COLUMN > &_first, const Sparse_chain< _CT, COLUMN > &_second) |
| | Matrix/column chain product: COLUMN matrix x COLUMN chain -> COLUMN chain.
|
| |
|
template<typename _CT > |
| Sparse_chain< _CT, COLUMN > | operator* (const Sparse_matrix< _CT, ROW > &_first, const Sparse_chain< _CT, COLUMN > &_second) |
| | Matrix/column chain product: ROW matrix x COLUMN chain -> COLUMN chain.
|
| |
|
template<typename _CT > |
| Sparse_chain< _CT, ROW > | operator* (const Sparse_chain< _CT, ROW > &_first, const Sparse_matrix< _CT, ROW > &_second) |
| | Row chain/matrix product: ROW chain x COLUMN matrix -> ROW chain.
|
| |
|
template<typename _CT > |
| Sparse_chain< _CT, ROW > | operator* (const Sparse_chain< _CT, ROW > &_first, const Sparse_matrix< _CT, COLUMN > &_second) |
| | Row chain/matrix product: ROW chain x ROW matrix -> ROW chain.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, ROW > | operator% (const Sparse_matrix< _CT, COLUMN > &_first, const Sparse_matrix< _CT, COLUMN > &_second) |
| | Matrices product: COLUMN x COLUMN -> ROW.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, ROW > | operator% (const Sparse_matrix< _CT, ROW > &_first, const Sparse_matrix< _CT, COLUMN > &_second) |
| | Matrices product: ROW x COLUMN -> ROW.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, ROW > | operator% (const Sparse_matrix< _CT, COLUMN > &_first, const Sparse_matrix< _CT, ROW > &_second) |
| | Matrices product: COLUMN x ROW -> ROW.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, ROW > | operator% (const Sparse_matrix< _CT, ROW > &_first, const Sparse_matrix< _CT, ROW > &_second) |
| | Matrices product: ROW x ROW -> ROW.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, COLUMN > & | operator+= (Sparse_matrix< _CT, COLUMN > &matrix, const Sparse_matrix< _CT, ROW > &other) |
| | Matrices sum and assign: COLUMN += ROW.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, ROW > & | operator+= (Sparse_matrix< _CT, ROW > &matrix, const Sparse_matrix< _CT, COLUMN > &other) |
| | Matrices sum and assign: ROW += COLUMN.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, COLUMN > & | operator-= (Sparse_matrix< _CT, COLUMN > &matrix, const Sparse_matrix< _CT, ROW > &other) |
| | Matrices subtraction and assign: COLUMN -= ROW.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, ROW > & | operator-= (Sparse_matrix< _CT, ROW > &matrix, const Sparse_matrix< _CT, COLUMN > &other) |
| | Matrices subtraction and assign: ROW -= COLUMN.
|
| |
| Sparse_matrix | operator- (const Sparse_matrix &matrix) |
| | Computes the negative of a matrix (unary operator).
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, COLUMN > & | operator*= (Sparse_matrix< _CT, COLUMN > &matrix, const Sparse_matrix< _CT, COLUMN > &other) |
| | Matrices product and assign: COLUMN *= COLUMN.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, ROW > & | operator*= (Sparse_matrix< _CT, ROW > &matrix, const Sparse_matrix< _CT, ROW > &other) |
| | Matrices product and assign: ROW *= ROW.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, COLUMN > & | operator*= (Sparse_matrix< _CT, COLUMN > &matrix, const Sparse_matrix< _CT, ROW > &other) |
| | Matrices product and assign: COLUMN *= ROW.
|
| |
|
template<typename _CT > |
| Sparse_matrix< _CT, ROW > & | operator*= (Sparse_matrix< _CT, ROW > &matrix, const Sparse_matrix< _CT, COLUMN > &other) |
| | Matrices product and assign: ROW *= COLUMN.
|
| |
| template<typename _CT , int _CTF> |
| void | set_coef (Sparse_matrix< _CT, _CTF > &matrix, size_t i, size_t j, const _CT d) |
| | Sets a given coefficient in matrix.
|
| |
| template<typename _CT , int _CTF> |
| _CT | get_coef (const Sparse_matrix< _CT, _CTF > &matrix, size_t i, size_t j) |
| | Gets a given coefficient.
|
| |
|
template<typename _CT > |
| Sparse_chain< _CT, COLUMN > | get_column (const Sparse_matrix< _CT, COLUMN > &matrix, size_t index) |
| | Gets a column from a COLUMN matrix.
|
| |
|
template<typename _CT > |
| Sparse_chain< _CT, COLUMN > | get_column (const Sparse_matrix< _CT, ROW > &matrix, size_t index) |
| | Gets a column from a ROW matrix.
|
| |
|
template<typename _CT > |
| Sparse_chain< _CT, ROW > | get_row (const Sparse_matrix< _CT, COLUMN > &matrix, size_t index) |
| | Gets a row from a COLUMN matrix.
|
| |
|
template<typename _CT > |
| Sparse_chain< _CT, ROW > | get_row (const Sparse_matrix< _CT, ROW > &matrix, size_t index) |
| | Gets a row from a ROW matrix.
|
| |
| template<typename _CT > |
| const Sparse_chain< _CT, COLUMN > & | cget_column (const Sparse_matrix< _CT, COLUMN > &matrix, size_t index) |
| | Gets a const reference over a column from a column matrix.
|
| |
| template<typename _CT > |
| const Sparse_chain< _CT, ROW > & | cget_row (const Sparse_matrix< _CT, ROW > &matrix, const size_t index) |
| | Gets a constant reference over a row from a row matrix.
|
| |
|
template<typename _CT > |
| void | set_column (Sparse_matrix< _CT, COLUMN > &matrix, size_t index, const Sparse_chain< _CT, COLUMN > &chain) |
| | Sets a column in a COLUMN matrix.
|
| |
|
template<typename _CT > |
| void | set_column (Sparse_matrix< _CT, ROW > &matrix, size_t index, const Sparse_chain< _CT, COLUMN > &chain) |
| | Sets a column in a ROW matrix.
|
| |
|
template<typename _CT > |
| void | set_row (Sparse_matrix< _CT, COLUMN > &matrix, size_t index, const Sparse_chain< _CT, ROW > &chain) |
| | Sets a row in a COLUMN matrix.
|
| |
|
template<typename _CT > |
| void | set_row (Sparse_matrix< _CT, ROW > &matrix, size_t index, const Sparse_chain< _CT, ROW > &chain) |
| | Sets a row in a ROW matrix.
|
| |
|
Sparse_matrix | operator/ (const Sparse_matrix &matrix, const std::vector< size_t > &_indices) |
| | Removes a set of chains from a copy of a matrix.
|
| |
|
Sparse_matrix | operator/ (const Sparse_matrix &matrix, size_t index) |
| | Removes the chain at a given index from a copy of a matrix.
|
| |
| template<typename _CT , int _CTF> |
| Sparse_matrix< _CT, _CTF > & | del_column (Sparse_matrix< _CT, _CTF > &matrix, size_t index) |
| | Removes a column from the matrix.
|
| |
| template<typename _CT , int _CTF> |
| Sparse_matrix< _CT, _CTF > & | del_row (Sparse_matrix< _CT, _CTF > &matrix, size_t index) |
| | Removes a row from the matrix.
|
| |
| template<typename _CT , int _CTF> |
| Sparse_matrix< _CT, _CTF > & | del_coef (Sparse_matrix< _CT, _CTF > &matrix, size_t i, size_t j) |
| | Removes a coefficient from the matrix.
|
| |