CGAL 6.1 - Homological Discrete Vector Fields
Loading...
Searching...
No Matches
CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag > Class Template Reference

#include <CGAL/OSM/Sparse_matrix.h>

Inherited by CGAL::OSM::Sub_sparse_matrix< CoefficientType, ChainTypeFlag >.

Definition

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
CoefficientTypea model of the Ring concept, providing the ring used to compute homology.
ChainTypeFlagan integer constant encoding the type of matrices (OSM::COLUMN or OSM::ROW).
Examples
HDVF/example_matrix_chain.cpp.

Public Types

typedef Sparse_chain< CoefficientType, ChainTypeFlag > MatrixChain
 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< CoefficientType, 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.
 
Sparse_matrixoperator+= (const Sparse_matrix &other)
 Matrices sum and assign: COLUMN += COLUMN or ROW += ROW.
 
Sparse_matrixoperator-= (const Sparse_matrix &other)
 Matrices subtraction and assign: COLUMN -= COLUMN or ROW -= ROW.
 
Sparse_matrixoperator*= (const CoefficientType &lambda)
 Applies factor on each coefficients and assign.
 
MatrixChain operator[] (size_t index) const
 Gets the value of a chain from a const matrix.
 
Sparse_matrixoperator/= (const std::vector< size_t > &indexes)
 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 to the ending of chains 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 to the ending of chains indices.
 
Sparse_matrix< CoefficientType, COLUMN+ROW - ChainTypeFlag > transpose ()
 Transposes a matrix.
 
std::pair< size_t, size_t > dimensions () const
 Gets the matrix sizes.
 

Protected Member Functions

MatrixChainoperator[] (const size_t _index)
 
void set_coef (const size_t i, const size_t j, const CoefficientType d)
 
CoefficientType get_coef (const size_t i, const size_t j) const
 
Sparse_matrixdel_column (size_t index)
 
Sparse_matrixdel_row (size_t index)
 
Sparse_matrixdel_coef (size_t i, size_t j)
 

Protected Attributes

std::vector< Sparse_chain< CoefficientType, ChainTypeFlag > > _chains
 
Bitboard _chainsStates
 
std::pair< size_t, size_t > _size
 

Friends

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, COLUMNoperator* (const Sparse_matrix< _CT, COLUMN > &first, const Sparse_matrix< _CT, COLUMN > &second)
 Matrices product: COLUMN x COLUMN -> COLUMN.
 
template<typename _CT >
Sparse_matrix< _CT, COLUMNoperator* (const Sparse_matrix< _CT, ROW > &first, const Sparse_matrix< _CT, COLUMN > &second)
 Matrices product: ROW x COLUMN -> COLUMN.
 
template<typename _CT >
Sparse_matrix< _CT, COLUMNoperator* (const Sparse_matrix< _CT, COLUMN > &first, const Sparse_matrix< _CT, ROW > &second)
 Matrices product: COLUMN x ROW -> COLUMN.
 
template<typename _CT >
Sparse_matrix< _CT, COLUMNoperator* (const Sparse_matrix< _CT, ROW > &first, const Sparse_matrix< _CT, ROW > &second)
 Matrices product: ROW x ROW -> COLUMN.
 
template<typename _CT >
Sparse_chain< _CT, COLUMNoperator* (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, COLUMNoperator* (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, ROWoperator* (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, ROWoperator* (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, ROWoperator% (const Sparse_matrix< _CT, COLUMN > &_first, const Sparse_matrix< _CT, COLUMN > &_second)
 Matrices product: COLUMN x COLUMN -> ROW.
 
template<typename _CT >
Sparse_matrix< _CT, ROWoperator% (const Sparse_matrix< _CT, ROW > &_first, const Sparse_matrix< _CT, COLUMN > &_second)
 Matrices product: ROW x COLUMN -> ROW.
 
template<typename _CT >
Sparse_matrix< _CT, ROWoperator% (const Sparse_matrix< _CT, COLUMN > &_first, const Sparse_matrix< _CT, ROW > &_second)
 Matrices product: COLUMN x ROW -> ROW.
 
template<typename _CT >
Sparse_matrix< _CT, ROWoperator% (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, 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 > &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.
 

Constructor & Destructor Documentation

◆ Sparse_matrix() [1/3]

template<typename CoefficientType , int ChainTypeFlag>
CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag >::Sparse_matrix ( )

Default constructor (empty new Sparse_matrix object).

Create an empty matrix of type ChainTypeFlag with coefficients of type CoefficientType. The default matrix size is 0x0.

◆ Sparse_matrix() [2/3]

template<typename CoefficientType , int ChainTypeFlag>
CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag >::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 ChainTypeFlag with coefficients of type CoefficientType and a given size along rows/columns.

Parameters
[in]rowCountThe number of rows to preallocate.
[in]columnCountThe number of columns to preallocate.

◆ Sparse_matrix() [3/3]

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

Copy constructor.

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

Parameters
[in]otherToCopyThe matrix copied.

Member Function Documentation

◆ begin()

template<typename CoefficientType , int ChainTypeFlag>
Bitboard::iterator CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag >::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 CoefficientType , int ChainTypeFlag>
std::pair< size_t, size_t > CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag >::dimensions ( ) const

Gets the matrix sizes.

Returns
The matrix size as a row/column pair.

◆ end()

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

Iterator to the ending of chains indices.

Returns
The iterator to the ending of chains indices.

◆ is_null()

template<typename CoefficientType , int ChainTypeFlag>
bool CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag >::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 CoefficientType , int ChainTypeFlag>
void CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag >::nullify ( )

Cleans a SparseMatrix (set all coefficients to zero).

Empty all structures of the sparse matrix.

◆ operator*=()

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

Applies factor on each coefficients and assign.

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

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

◆ operator=()

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

Assigns to other matrix.

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

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

◆ operator[]()

template<typename CoefficientType , int ChainTypeFlag>
MatrixChain CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag >::operator[] ( size_t  index) const

Gets the value of a chain from a const matrix.

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

◆ reverse_begin()

template<typename CoefficientType , int ChainTypeFlag>
Bitboard::reverse_iterator CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag >::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 CoefficientType , int ChainTypeFlag>
Bitboard::reverse_iterator CGAL::OSM::Sparse_matrix< CoefficientType, ChainTypeFlag >::reverse_end ( )
noexcept

Reverse iterator to the ending of chains indices.

Returns
The reverse iterator to the ending of chains indices.

◆ transpose()

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

Transposes a matrix.

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

Friends And Related Function Documentation

◆ cget_column

template<typename CoefficientType , int ChainTypeFlag>
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
[in]matrixThe matrix considered.
[in]indexThe column index.
Returns
A constant reference over the column stored at given index.

◆ cget_row

template<typename CoefficientType , int ChainTypeFlag>
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
[in]matrixThe matrix considered.
[in]indexThe row index.
Returns
A const reference over the row stored at given index.

◆ del_coef

template<typename CoefficientType , int ChainTypeFlag>
template<typename _CT , int _CTF>
Sparse_matrix< _CT, _CTF > & del_coef ( 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
[in]matrixReference on the matrix to modify.
[in]iIndex of the row
[in]jIndex of the column
Returns
The modified matrix representing the result.

◆ del_column

template<typename CoefficientType , int ChainTypeFlag>
template<typename _CT , int _CTF>
Sparse_matrix< _CT, _CTF > & del_column ( Sparse_matrix< _CT, _CTF > &  matrix,
size_t  index 
)
friend

Removes a column from the matrix.

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

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

◆ del_row

template<typename CoefficientType , int ChainTypeFlag>
template<typename _CT , int _CTF>
Sparse_matrix< _CT, _CTF > & del_row ( Sparse_matrix< _CT, _CTF > &  matrix,
size_t  index 
)
friend

Removes a row from the matrix.

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

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

◆ get_coef

template<typename CoefficientType , int ChainTypeFlag>
template<typename _CT , int _CTF>
_CT get_coef ( 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
[in]matrixConstant reference on the matrix.
[in]iThe row index.
[in]jThe column index.
Returns
The value of the given coefficient.

◆ operator* [1/2]

template<typename CoefficientType , int ChainTypeFlag>
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
[in]lambdaThe factor to apply.
[in]matrixThe matrix.
Returns
A new matrix representing the result.

◆ operator* [2/2]

template<typename CoefficientType , int ChainTypeFlag>
template<typename _CT , int _CTF>
Sparse_matrix operator* ( const Sparse_matrix< _CT, _CTF > &  matrix,
const _CT &  lambda 
)
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
[in]matrixThe matrix.
[in]lambdaThe factor to apply.
Returns
A new matrix representing the result.

◆ operator+

template<typename CoefficientType , int ChainTypeFlag>
template<int _CTF>
Sparse_matrix operator+ ( const Sparse_matrix< CoefficientType, ChainTypeFlag > &  first,
const Sparse_matrix< CoefficientType, _CTF > &  second 
)
friend

Adds two matrices together into a new matrix.

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

Precondition
Matrices must have the same CoefficientType but can have different ChainTypeFlag.
Warning
Will raise an error if the other matrix is not the same CoefficientType.
Parameters
[in]firstThe first matrix.
[in]secondThe second matrix.
Returns
A new matrix representing the result.

◆ operator- [1/2]

template<typename CoefficientType , int ChainTypeFlag>
template<int _CTF>
Sparse_matrix operator- ( const Sparse_matrix< CoefficientType, ChainTypeFlag > &  first,
const Sparse_matrix< CoefficientType, _CTF > &  second 
)
friend

Substracts two matrices together into a new matrix.

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

Precondition
Matrices must have the same CoefficientType but can have different ChainTypeFlag.
Warning
Will raise an error if the other matrix is not the same CoefficientType.
Parameters
[in]firstThe first matrix.
[in]secondThe second matrix.
Returns
A new matrix representing the result.

◆ operator- [2/2]

template<typename CoefficientType , int ChainTypeFlag>
Sparse_matrix operator- ( const Sparse_matrix< CoefficientType, ChainTypeFlag > &  matrix)
friend

Computes the negative of a matrix (unary operator).

Returns
The resulting matrix.

◆ operator<<

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

Displays a matrix in the output stream.

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

◆ set_coef

template<typename CoefficientType , int ChainTypeFlag>
template<typename _CT , int _CTF>
void set_coef ( 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
[in]matrixReference on the matrix to modify.
[in]iThe row index.
[in]jThe column index.
[in]dThe value.