CGAL 6.2 - Homological Discrete Vector Fields
Loading...
Searching...
No Matches
CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat > Class Template Reference

#include <CGAL/OSM/Sparse_matrix.h>

Inherited by CGAL::OSM::Sub_sparse_matrix< CoefficientRing, StorageFormat >.

Definition

template<typename CoefficientRing, int StorageFormat>
class CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >

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 StorageFormat parameter determines this storage format). A column-major (resp. row-major) Sparse_matrix is a vector of Sparse_chain 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
CoefficientRinga model of the IntegralDomainWithoutDivision concept, providing the ring used to compute homology.
StorageFormatan integer constant encoding the storage format of matrices (OSM::COLUMN or OSM::ROW).
Examples
HDVF/matrix_chain.cpp.

Public Types

typedef CoefficientRing Coefficient_ring
 Type of coefficient ring.
 
typedef Sparse_chain< CoefficientRing, StorageFormat > Matrix_chain
 Type of chains associated to the matrix.
 

Public Member Functions

 Sparse_matrix ()
 Default constructor (empty new Sparse_matrix object).
 
 Sparse_matrix (const size_t rowCount, const size_t columnCount)
 Constructor with given rows/columns sizes.
 
template<int CTF>
 Sparse_matrix (const Sparse_matrix< CoefficientRing, CTF > &otherToCopy)
 Copy constructor.
 
Sparse_matrixoperator= (const Sparse_matrix &otherToCopy)
 Assigns to other matrix.
 
void nullify ()
 Cleans a SparseMatrix (set all coefficients to zero).
 
bool is_null ()
 Tests if a SparseMatrix is null.
 
template<int _CTF>
Sparse_matrix operator+ (const Sparse_matrix< CoefficientRing, _CTF > &other)
 Adds two matrices into a new matrix.
 
template<int _CTF>
Sparse_matrix operator- (const Sparse_matrix< CoefficientRing, _CTF > &other)
 Subtracts two matrices into a new matrix.
 
Sparse_matrix operator* (const CoefficientRing &lambda)
 Applies factor on each coefficients into a new matrix.
 
Sparse_matrixoperator*= (const CoefficientRing &lambda)
 Applies factor on each coefficients and assign.
 
Sparse_matrix operator- ()
 Computes the negative of a matrix (unary operator).
 
Matrix_chain operator[] (size_t index) const
 Gets the value of a chain from a const matrix.
 
Sparse_matrix operator/ (const std::vector< size_t > &_indices)
 Removes a set of chains from a copy of the matrix.
 
Sparse_matrix operator/ (size_t index)
 Removes the chain at a given index from a copy of the matrix.
 
Sparse_matrixoperator/= (const std::vector< size_t > &indices)
 Removes a set of chains from a matrix.
 
Sparse_matrixoperator/= (const size_t index)
 Removes the chain at a given index from a matrix.
 
Bitboard::iterator begin () const noexcept
 Iterator to the index of the first non null chain.
 
Bitboard::iterator end () const noexcept
 Iterator past-the-end of chain indices.
 
Bitboard::reverse_iterator reverse_begin () noexcept
 Reverse iterator to the index of the last non null chain.
 
Bitboard::reverse_iterator reverse_begin (size_t index) noexcept
 
Bitboard::reverse_iterator reverse_end () noexcept
 Reverse iterator past-the-end of chain indices.
 
Sparse_matrix< CoefficientRing, COLUMN+ROW - StorageFormat > transpose ()
 Transposes a matrix.
 
std::pair< size_t, size_t > dimensions () const
 Gets the matrix sizes.
 

Protected Member Functions

Matrix_chainoperator[] (const size_t _index)
 
void set_coefficient (const size_t i, const size_t j, const Coefficient_ring d)
 
Coefficient_ring get_coefficient (const size_t i, const size_t j) const
 
Sparse_matrixremove_column (size_t index)
 
Sparse_matrixremove_row (size_t index)
 
Sparse_matrixremove_coefficient (size_t i, size_t j)
 

Protected Attributes

std::vector< Sparse_chain< CoefficientRing, StorageFormat > > _chains
 
Bitboard _chainsStates
 
std::pair< size_t, size_t > _size
 

Friends

template<typename _CT , int _CTF>
class Sparse_matrix
 

Related Functions

(Note that these are not member functions.)

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)
 Writes a sparse 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 to a stream.
 
template<typename _CT >
std::ostream & write_matrix (const Sparse_matrix< _CT, OSM::ROW > &M, std::ostream &out)
 Writes a sparse ROW matrix to a stream.
 
template<typename _CT >
void write_matrix (const Sparse_matrix< _CT, OSM::COLUMN > &M, std::string filename)
 Writes a sparse COLUMN matrix to a file.
 
template<typename _CT >
void write_matrix (const Sparse_matrix< _CT, OSM::ROW > &M, std::string filename)
 Writes a sparse ROW matrix to a file.
 
template<typename _CT >
std::istream & read_matrix (Sparse_matrix< _CT, OSM::COLUMN > &M, std::istream &in)
 Reads a sparse COLUMN matrix from a stream.
 
template<typename _CT >
std::istream & read_matrix (Sparse_matrix< _CT, OSM::ROW > &M, std::istream &in)
 Reads a sparse ROW matrix from a stream.
 
template<typename _CT >
void read_matrix (Sparse_matrix< _CT, OSM::COLUMN > &M, std::string filename)
 Reads a sparse COLUMN matrix from a file.
 
template<typename _CT >
void read_matrix (Sparse_matrix< _CT, OSM::ROW > &M, std::string filename)
 Reads a sparse ROW matrix from a file.
 
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 >
Sparse_matrix< _CT, COLUMNoperator* (const Sparse_matrix< _CT, COLUMN > &first, const Sparse_matrix< _CT, COLUMN > &second)
 Matrix multiplication: COLUMN x COLUMN -> COLUMN.
 
template<typename _CT >
Sparse_matrix< _CT, COLUMNoperator* (const Sparse_matrix< _CT, ROW > &first, const Sparse_matrix< _CT, COLUMN > &second)
 Matrix multiplication: ROW x COLUMN -> COLUMN.
 
template<typename _CT >
Sparse_matrix< _CT, COLUMNoperator* (const Sparse_matrix< _CT, COLUMN > &first, const Sparse_matrix< _CT, ROW > &second)
 Matrix multiplication: COLUMN x ROW -> COLUMN.
 
template<typename _CT >
Sparse_matrix< _CT, COLUMNoperator* (const Sparse_matrix< _CT, ROW > &first, const Sparse_matrix< _CT, ROW > &second)
 Matrix multiplication: ROW x ROW -> COLUMN.
 
template<typename _CT >
Sparse_chain< _CT, COLUMNoperator* (const Sparse_matrix< _CT, COLUMN > &_matrix, const Sparse_chain< _CT, COLUMN > &_column)
 Matrix/column chain multiplication: COLUMN matrix x COLUMN chain -> COLUMN chain.
 
template<typename _CT >
Sparse_chain< _CT, COLUMNoperator* (const Sparse_matrix< _CT, ROW > &_matrix, const Sparse_chain< _CT, COLUMN > &_column)
 Matrix/column chain multiplication: ROW matrix x COLUMN chain -> COLUMN chain.
 
template<typename _CT >
Sparse_chain< _CT, ROWoperator* (const Sparse_chain< _CT, ROW > &_row, const Sparse_matrix< _CT, ROW > &_matrix)
 Row chain/matrix multiplication: ROW chain x COLUMN matrix -> ROW chain.
 
template<typename _CT >
Sparse_chain< _CT, ROWoperator* (const Sparse_chain< _CT, ROW > &_row, const Sparse_matrix< _CT, COLUMN > &_matrix)
 Row chain/matrix multiplication: ROW chain x ROW matrix -> ROW chain.
 
template<typename _CT >
Sparse_matrix< _CT, ROWoperator% (const Sparse_matrix< _CT, COLUMN > &_first, const Sparse_matrix< _CT, COLUMN > &_second)
 matrix multiplication: COLUMN x COLUMN -> ROW
 
template<typename _CT >
Sparse_matrix< _CT, ROWoperator% (const Sparse_matrix< _CT, ROW > &_first, const Sparse_matrix< _CT, COLUMN > &_second)
 matrix multiplication: ROW x COLUMN -> ROW
 
template<typename _CT >
Sparse_matrix< _CT, ROWoperator% (const Sparse_matrix< _CT, COLUMN > &_first, const Sparse_matrix< _CT, ROW > &_second)
 matrix multiplication: COLUMN x ROW -> ROW
 
template<typename _CT >
Sparse_matrix< _CT, ROWoperator% (const Sparse_matrix< _CT, ROW > &_first, const Sparse_matrix< _CT, ROW > &_second)
 matrix multiplication: ROW x ROW -> ROW
 
Sparse_matrixoperator+= (const Sparse_matrix &other)
 Matrices sum and assign: COLUMN += COLUMN or 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.
 
Sparse_matrixoperator-= (const Sparse_matrix &other)
 Matrices subtraction and assign: COLUMN -= COLUMN or ROW -= ROW.
 
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.
 
template<typename _CT >
Sparse_matrix< _CT, COLUMN > & operator*= (Sparse_matrix< _CT, COLUMN > &matrix, const Sparse_matrix< _CT, COLUMN > &other)
 Matrix multiplication and assign: COLUMN *= COLUMN.
 
template<typename _CT >
Sparse_matrix< _CT, ROW > & operator*= (Sparse_matrix< _CT, ROW > &matrix, const Sparse_matrix< _CT, ROW > &other)
 Matrix multiplication and assign: ROW *= ROW.
 
template<typename _CT >
Sparse_matrix< _CT, COLUMN > & operator*= (Sparse_matrix< _CT, COLUMN > &matrix, const Sparse_matrix< _CT, ROW > &other)
 Matrix multiplication and assign: COLUMN *= ROW.
 
template<typename _CT >
Sparse_matrix< _CT, ROW > & operator*= (Sparse_matrix< _CT, ROW > &matrix, const Sparse_matrix< _CT, COLUMN > &other)
 Matrix multiplication and assign: ROW *= COLUMN.
 
template<typename _CT , int _CTF>
void set_coefficient (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_coefficient (const Sparse_matrix< _CT, _CTF > &matrix, size_t i, size_t j)
 Gets a given coefficient.
 
template<typename _CT >
Sparse_chain< _CT, COLUMNget_column (const Sparse_matrix< _CT, COLUMN > &matrix, size_t index)
 Gets a column from a COLUMN matrix.
 
template<typename _CT >
Sparse_chain< _CT, COLUMNget_column (const Sparse_matrix< _CT, ROW > &matrix, size_t index)
 Gets a column from a ROW matrix.
 
template<typename _CT >
Sparse_chain< _CT, ROWget_row (const Sparse_matrix< _CT, COLUMN > &matrix, size_t index)
 Gets a row from a COLUMN matrix.
 
template<typename _CT >
Sparse_chain< _CT, ROWget_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 > &column)
 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 > &column)
 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 > &row)
 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 > &row)
 Sets a row in a ROW matrix.
 
template<typename _CT , int _CTF>
Sparse_matrix< _CT, _CTF > & remove_column (Sparse_matrix< _CT, _CTF > &matrix, size_t index)
 Removes a column from the matrix.
 
template<typename _CT , int _CTF>
Sparse_matrix< _CT, _CTF > & remove_row (Sparse_matrix< _CT, _CTF > &matrix, size_t index)
 Removes a row from the matrix.
 
template<typename _CT , int _CTF>
Sparse_matrix< _CT, _CTF > & remove_coefficient (Sparse_matrix< _CT, _CTF > &matrix, size_t i, size_t j)
 Removes a coefficient from the matrix.
 

Constructor & Destructor Documentation

◆ Sparse_matrix() [1/3]

template<typename CoefficientRing , int StorageFormat>
CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::Sparse_matrix ( )

Default constructor (empty new Sparse_matrix object).

Create an empty matrix of type StorageFormat with coefficients of type CoefficientRing. The default matrix size is 0x0.

◆ Sparse_matrix() [2/3]

template<typename CoefficientRing , int StorageFormat>
CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::Sparse_matrix ( const size_t  rowCount,
const size_t  columnCount 
)

Constructor with given rows/columns sizes.

Create a new empty Sparse_matrix object of type StorageFormat with coefficients of type CoefficientRing and a given size along rows/columns.

Parameters
rowCountThe number of rows to preallocate.
columnCountThe number of columns to preallocate.

◆ Sparse_matrix() [3/3]

template<typename CoefficientRing , int StorageFormat>
template<int CTF>
CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::Sparse_matrix ( const Sparse_matrix< CoefficientRing, CTF > &  otherToCopy)

Copy constructor.

Create a new SparseMatrix from another SparseMatrix object (with possibly a different StorageFormat). Initialize a SparseMatrix of same sizes, containing the same coefficients (but not necessarly of the same StorageFormat). If types are different, the constructor performs conversion.

Parameters
otherToCopyThe matrix copied.

Member Function Documentation

◆ begin()

template<typename CoefficientRing , int StorageFormat>
Bitboard::iterator CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::begin ( ) const
noexcept

Iterator to the index of the first non null chain.

Return an iterator to the index of the first non null chain (the iterator visits indices of non null chains along the major dimension of the matrix).

Returns
The iterator to the index of the first non null chain.

◆ dimensions()

template<typename CoefficientRing , int StorageFormat>
std::pair< size_t, size_t > CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::dimensions ( ) const

Gets the matrix sizes.

Returns
The matrix size as a row/column pair.

◆ end()

template<typename CoefficientRing , int StorageFormat>
Bitboard::iterator CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::end ( ) const
noexcept

Iterator past-the-end of chain indices.

Returns
The iterator past-the-end of chain indices.

◆ is_null()

template<typename CoefficientRing , int StorageFormat>
bool CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::is_null ( )

Tests if a SparseMatrix is null.

The function return true is the SparseMatrix is null (that is, empty) and false otherwise.

◆ nullify()

template<typename CoefficientRing , int StorageFormat>
void CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::nullify ( )

Cleans a SparseMatrix (set all coefficients to zero).

Empty all structures of the sparse matrix.

◆ operator*()

template<typename CoefficientRing , int StorageFormat>
Sparse_matrix CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::operator* ( const CoefficientRing &  lambda)

Applies factor on each coefficients into a new matrix.

This method creates a new matrix obtained by multiplying the matrix by a scalar factor lambda.

If lambda is zero, the function comes to nullify the matrix (when possible, prefer *= for efficiency).

Parameters
lambdaThe factor to apply.
Returns
A new matrix representing the result.

◆ operator*=()

template<typename CoefficientRing , int StorageFormat>
Sparse_matrix & CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::operator*= ( const CoefficientRing &  lambda)

Applies factor on each coefficients and assign.

If lambda is 0, this comes to nullify the matrix.

Parameters
lambdaThe factor to apply.
Returns
The modified matrix representing the result.

◆ operator+()

template<typename CoefficientRing , int StorageFormat>
template<int _CTF>
Sparse_matrix CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::operator+ ( const Sparse_matrix< CoefficientRing, _CTF > &  other)

Adds two matrices into a new matrix.

Adds each coefficient of the matrices and returns a new matrix (of the same type as this) representing the result (when possible, prefer += for efficiency).

Precondition
Matrices must have the same CoefficientRing but can have different StorageFormat.
Warning
Will raise an error if the other matrix is not the same CoefficientRing.
Parameters
otherThe second matrix.
Returns
A new matrix representing the result.

◆ operator-() [1/2]

template<typename CoefficientRing , int StorageFormat>
Sparse_matrix CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::operator- ( )

Computes the negative of a matrix (unary operator).

Returns
The resulting matrix.

◆ operator-() [2/2]

template<typename CoefficientRing , int StorageFormat>
template<int _CTF>
Sparse_matrix CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::operator- ( const Sparse_matrix< CoefficientRing, _CTF > &  other)

Subtracts two matrices into a new matrix.

Subtracts each coefficient of the matrix other and returns a new matrix (of the same type as this) representing the result (when possible, prefer -= for efficiency).

Precondition
Matrices must have the same CoefficientRing but can have different StorageFormat.
Warning
Will raise an error if the other matrix is not the same CoefficientRing.
Parameters
otherThe second matrix.
Returns
A new matrix representing the result.

◆ operator=()

template<typename CoefficientRing , int StorageFormat>
Sparse_matrix & CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::operator= ( const Sparse_matrix< CoefficientRing, StorageFormat > &  otherToCopy)

Assigns to other matrix.

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

Precondition
The matrices must have the same type.
Parameters
otherToCopyThe matrix we want to copy.
Returns
The reference to the modified matrix.

◆ operator[]()

template<typename CoefficientRing , int StorageFormat>
Matrix_chain CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::operator[] ( size_t  index) const

Gets the value of a chain from a const matrix.

Warning
The matrix will perform boundary check.
Parameters
indexThe chain index.
Returns
The chain stored at given index.

◆ reverse_begin()

template<typename CoefficientRing , int StorageFormat>
Bitboard::reverse_iterator CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::reverse_begin ( )
noexcept

Reverse iterator to the index of the last non null chain.

Return a reverse iiterator to the index of the last non null chain (the iterator visits indices of non null chains, in decreading order, along the major dimension of the matrix).

Returns
The reverse iterator to the index of the last non null chain.

◆ reverse_end()

template<typename CoefficientRing , int StorageFormat>
Bitboard::reverse_iterator CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::reverse_end ( )
noexcept

Reverse iterator past-the-end of chain indices.

Returns
The reverse iterator past-the-end of chain indices.

◆ transpose()

template<typename CoefficientRing , int StorageFormat>
Sparse_matrix< CoefficientRing, COLUMN+ROW - StorageFormat > CGAL::OSM::Sparse_matrix< CoefficientRing, StorageFormat >::transpose ( )

Transposes a matrix.

Returns
A new matrix where the StorageFormat has been swapped between COLUMN and ROW and data chains have been transposed.

Friends And Related Function Documentation

◆ cget_column

template<typename CoefficientRing , int StorageFormat>
template<typename _CT >
const Sparse_chain< _CT, COLUMN > & cget_column ( const Sparse_matrix< _CT, COLUMN > &  matrix,
size_t  index 
)
friend

Gets a const reference over a column from a column matrix.

Constant time get.

Warning
The matrix will perform boundary check.
Parameters
matrixThe matrix considered.
indexThe column index.
Returns
A constant reference over the column stored at given index.

◆ cget_row

template<typename CoefficientRing , int StorageFormat>
template<typename _CT >
const Sparse_chain< _CT, ROW > & cget_row ( const Sparse_matrix< _CT, ROW > &  matrix,
const size_t  index 
)
friend

Gets a constant reference over a row from a row matrix.

Constant time get.

Warning
The matrix will perform boundary check.
Parameters
matrixThe matrix considered.
indexThe row index.
Returns
A const reference over the row stored at given index.

◆ get_coefficient

template<typename CoefficientRing , int StorageFormat>
template<typename _CT , int _CTF>
_CT get_coefficient ( const Sparse_matrix< _CT, _CTF > &  matrix,
size_t  i,
size_t  j 
)
friend

Gets a given coefficient.

Returns the coefficient on row i and column j of the matrix.

Warning
The matrix will perform boundary check.
Parameters
matrixConstant reference on the matrix.
iThe row index.
jThe column index.
Returns
The value of the given coefficient.

◆ operator*

template<typename CoefficientRing , int StorageFormat>
template<typename _CT , int _CTF>
Sparse_matrix operator* ( const _CT &  lambda,
const Sparse_matrix< _CT, _CTF > &  matrix 
)
friend

Applies factor on each coefficients into a new matrix.

This method creates a new matrix obtained by multiplying the matrix by a scalar factor lambda.

If lambda is zero, the function comes to nullify the matrix (when possible, prefer *= for efficiency).

Parameters
lambdaThe factor to apply.
matrixThe matrix.
Returns
A new matrix representing the result.

◆ operator<<

template<typename CoefficientRing , int StorageFormat>
std::ostream & operator<< ( std::ostream &  stream,
const Sparse_matrix< CoefficientRing, StorageFormat > &  matrix 
)
friend

Writes a sparse matrix in the output stream.

Parameters
streamThe output stream.
matrixThe matrix to display.
Returns
A reference to the modified stream.

◆ remove_coefficient

template<typename CoefficientRing , int StorageFormat>
template<typename _CT , int _CTF>
Sparse_matrix< _CT, _CTF > & remove_coefficient ( Sparse_matrix< _CT, _CTF > &  matrix,
size_t  i,
size_t  j 
)
friend

Removes a coefficient from the matrix.

Removes coefficient at row i and column j.

Parameters
matrixReference on the matrix to modify.
iIndex of the row
jIndex of the column
Returns
The modified matrix representing the result.

◆ remove_column

template<typename CoefficientRing , int StorageFormat>
template<typename _CT , int _CTF>
Sparse_matrix< _CT, _CTF > & remove_column ( Sparse_matrix< _CT, _CTF > &  matrix,
size_t  index 
)
friend

Removes a column from the matrix.

Removes column of index index whatever the StorageFormat of the matrix. For column matrices, it just comes to the \= operator and for row matrices, it entails a traversal of the matrix.

Parameters
matrixReference on the matrix to modify.
indexThe index to remove.
Returns
The modified matrix representing the result.

◆ remove_row

template<typename CoefficientRing , int StorageFormat>
template<typename _CT , int _CTF>
Sparse_matrix< _CT, _CTF > & remove_row ( Sparse_matrix< _CT, _CTF > &  matrix,
size_t  index 
)
friend

Removes a row from the matrix.

Removes row of index index whatever the StorageFormat of the matrix. For row matrices, it just comes to the \= operator and for column matrices, it entails a traversal of the matrix.

Parameters
matrixReference on the matrix to modify.
indexThe index to remove.
Returns
The modified matrix representing the result.

◆ set_coefficient

template<typename CoefficientRing , int StorageFormat>
template<typename _CT , int _CTF>
void set_coefficient ( Sparse_matrix< _CT, _CTF > &  matrix,
size_t  i,
size_t  j,
const _CT  d 
)
friend

Sets a given coefficient in matrix.

Assign the scalar d to the coefficient on row i and column j.

Warning
The matrix will perform boundary check.
Parameters
matrixReference on the matrix to modify.
iThe row index.
jThe column index.
dThe value.