CGAL 6.3-dev - Homological Discrete Vector Fields
Loading...
Searching...
No Matches

Definition

The concept SparseMatrix describes the requirements for sparse matrices optimized for topological computations. Traditionally, sparse matrices data structures encode non zero coefficients of (sparse) matrices in order to optimize either matrices memory footprint, or linear algebra operations (which usually comes to optimize iterators over non zero coefficients and access to coefficients). However, topological operations require slightly different features:

  • fast access to row or columns of matrices (which are actually the images under the application encoded by the matrix)
  • fast block operations (especially along row or columns)

The SparseMatrix concept describes requirements for such sparse matrix. It relies on the model of SparseChain which encodes sparse row or column vectors. Matrices are either column major or row major (hence they either store column sparse chains or row sparse chains).

The following integer constants, called Storage_format, encode the major direction of both sparse chains and sparse matrices.

  • CGAL::OSM::COLUMN for column-major chains and matrices (which is the default),
  • CGAL::OSM::ROW for row-major chains and matrices.

For instance, given 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\).

  • A column-major representation of \(A\) is: \([0\mapsto c_0, 2\mapsto c_2]\) with the column-chains: \(c_0 = [0\mapsto 1, 1\mapsto -1]\) and \(c_2 = [1\mapsto 2, 2\mapsto 1]\).
  • A row-major representation of \(A\) is: \([0\mapsto c_0, 1\mapsto c_1, 2\mapsto c_2]\) with the row-chains: \(c_0 = [0\mapsto 1]\) and \(c_1 = [0\mapsto -1, 2\mapsto 2]\) and \(c_2 = [2\mapsto 1]\).
Has models
CGAL::OSM::Sparse_matrix<IntegralDomainWithoutDivision, Storage_format, SparseChain>
CGAL::OSM::Sub_sparse_matrix<IntegralDomainWithoutDivision, Storage_format, SparseChain>
See also
IntegralDomainWithoutDivision
SparseChain

Types

typedef unspecified_type Coefficient_ring
 Type of coefficients stored in the matrix (a model of IntegralDomainWithoutDivision).
typedef unspecified_type Sparse_chain_type
 Type of SparseChain used for storage.
typedef unspecified_type Non_zero_chain_indices
 A range of indices of non empty chains.
typedef unspecified_type Matrix_chain
 Type of the chains stored in the matrix.

Member data

int Storage_format
 Matrix storage format (either CGAL::OSM::ROW or CGAL::OSM::COLUMN).

Creation, Filling

 SparseMatrix ()
 Creates an empty new sparse matrix object.
 SparseMatrix (const size_t rowCount, const size_t columnCount)
 Creates a new sparse matrix object with given rows/columns sizes.
void nullify ()
 Cleans a sparse matrix (set all coefficients to zero).
void eye (size_t nrows, size_t ncols)
 Sets an identity matrix.
void eye (std::pair< size_t, size_t > dimensions)
 Sets an identity matrix.

Matrix informations and iterators

bool is_null ()
 Tests if a sparse matrix is null.
bool is_empty ()
 Tests if a Sparse_matrix is empty.
int storage_format ()
 Returns the storage format of the matrix.
std::pair< size_t, size_t > dimensions () const
 Gets the matrix size.
Non_zero_chain_indices::iterator begin () const noexcept
 Iterator to the index of the first non null chain.
Non_zero_chain_indices::iterator end () const noexcept
 Iterator past-the-end of chain indices.
Non_zero_chain_indices::iterator reverse_begin () const noexcept
 Reverse iterator to the index of the last non null chain.
Non_zero_chain_indices::iterator reverse_end () const noexcept
 Reverse iterator past-the-end of chain indices.

Linear algebra operators

SparseMatrix & operator-= (SparseMatrix &matrix, const SparseMatrix &other)
 Subtracts two matrices into a new matrix.
SparseMatrix & operator*= (const Coefficient_ring &lambda)
 Applies factor on each coefficient and assign.
SparseMatrix transpose ()
 Transposes a matrix.
SparseMatrix & operator+= (SparseMatrix &matrix, const SparseMatrix &other)
 Perform addition of matrices and assign the result to matrix.
SparseMatrix operator+ (const SparseMatrix &first, const SparseMatrix &second)
 Perform addition of matrices and assign the result to matrix.
SparseMatrix operator- (const SparseMatrix &first, const SparseMatrix &second)
 Subtracts two matrices into a new matrix.
SparseMatrix operator- (const SparseMatrix &matrix)
 Computes the negative of a matrix (unary operator).
SparseMatrix operator* (const Coefficient_ring &lambda, const SparseMatrix &matrix)
 Applies factor on each coefficients into a new matrix.
SparseMatrix operator* (const SparseMatrix &matrix, const Coefficient_ring &lambda)
 Applies factor on each coefficients into a new matrix.
SparseMatrix & operator*= (SparseMatrix &matrix, const SparseMatrix &other)
 Perform multiplication of matrices and assign the result to matrix.
SparseMatrix operator* (const SparseMatrix &first, const SparseMatrix &second)
 Perform multiplication of matrices and return a new column-major matrix.
SparseMatrix operator% (const SparseMatrix &first, const SparseMatrix &second)
 Perform multiplication of matrices and return a new row-major matrix.
SparseChain operator* (const SparseMatrix &matrix, const SparseChain &column)
 Perform multiplication of a sparse matrix (column or row major) and a column-chain.
SparseChain operator* (const SparseChain &row, const SparseMatrix &matrix)
 Perform multiplication of a row-chain and a sparse matrix (column or row major).

Access and blocks operations

Matrix_chain operator[] (size_t index) const
 Gets the value of a chain from a const matrix.
const SparseChain & cget_column (const SparseMatrix &matrix, size_t index)
 Gets a const reference over a column from a column matrix.
const SparseChain & cget_row (const SparseMatrix &matrix, size_t index)
 Gets a constant reference over a row from a row matrix.
void set_column (SparseMatrix &matrix, size_t index, const SparseChain &column)
 Set the value of the column at a given index from the matrix to column (whatever the Storage_format of the matrix).
void set_row (SparseMatrix &matrix, size_t index, const SparseChain &row)
 Set the value of the row at a given index from the matrix to chain (whatever the StorageFormat of the matrix).
SparseMatrix & operator/= (size_t index)
 Remove the chain at a given index.
SparseMatrix & operator/= (const std::vector< size_t > &indices)
 Build and return a new matrix by copying a matrix and removing all chains with indices in the indices vector.
void set_coefficient (SparseMatrix &matrix, size_t i, size_t j, const Coefficient_ring d)
 Sets a given coefficient in matrix.
Coefficient_ring get_coefficient (const SparseMatrix &matrix, size_t i, size_t j)
 Gets a given coefficient.
SparseChain get_column (const SparseMatrix &matrix, size_t index)
 Gets the value of the column at a given index from the matrix (whatever the Storage_format of the matrix).
SparseChain get_row (const SparseMatrix &matrix, size_t index)
 Get sthe value of the row at a given index from the matrix (whatever the Storage_format of the matrix).
SparseMatrix operator/ (const SparseMatrix &matrix, size_t index)
 Build and return a new matrix by copying a matrix and removing the chain at a given index.
SparseMatrix operator/ (const SparseMatrix &matrix, const std::vector< size_t > &indices)
 Build and return a new matrix by copying a matrix and removing the chains with indices in the indices vector.
SparseMatrix & remove_column (SparseMatrix &matrix, size_t index)
 Removes a column from the matrix.
SparseMatrix & remove_row (SparseMatrix &matrix, size_t index)
 Removes a row from the matrix.
SparseMatrix & remove_coefficient (SparseMatrix &matrix, size_t i, size_t j)
 Removes a coefficient from the matrix.
Sparse_matrix & swap_columns (Sparse_matrix &matrix, size_t i, size_t j)
 Swaps columns in a matrix.
Sparse_matrix & swap_rows (Sparse_matrix &matrix, size_t i, size_t j)
 Swaps rows in a matrix.

Input, output

std::ostream & operator<< (std::ostream &_stream, const SparseMatrix &matrix)
 Writes a sparse matrix in the output stream with a compact "user friendly" format.
std::ostream & write_matrix (const SparseMatrix &matrix, std::ostream &out)
 Write a sparse matrix to an output stream using the .osm file format.
std::ostream & write_matrix (const SparseMatrix &matrix, std::string filename)
 Write a sparse matrix to a file using the .osm file format.
template<typename _CT>
std::istream & read_matrix (SparseMatrix &matrix, std::istream &in)
 Read a sparse matrix from an input stream using the .osm file format.
template<typename _CT>
std::istream & read_matrix (SparseMatrix &matrix, std::string filename)
 Read a sparse matrix from a file using the .osm file format.

Constructor & Destructor Documentation

◆ SparseMatrix() [1/2]

SparseMatrix::SparseMatrix ( )

Creates an empty new sparse matrix object.

Default constructor, initialize an empty matrix of type Storage_format with coefficients of type Coefficient_ring. The default matrix size is 0x0.

◆ SparseMatrix() [2/2]

SparseMatrix::SparseMatrix ( const size_t rowCount,
const size_t columnCount )

Creates a new sparse matrix object with given rows/columns sizes.

Constructor with sizes, initialize an empty matrix of type Storage_format with coefficients of type Coefficient_ring and a given size along rows/columns.

Member Function Documentation

◆ begin()

Non_zero_chain_indices::iterator SparseMatrix::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.

◆ cget_column()

const SparseChain & SparseMatrix::cget_column ( const SparseMatrix & matrix,
size_t index )

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.
Precondition
matrix.is_column() must be true.

◆ cget_row()

const SparseChain & SparseMatrix::cget_row ( const SparseMatrix & matrix,
size_t index )

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.
Precondition
matrix.is_row() must be true.

◆ dimensions()

std::pair< size_t, size_t > SparseMatrix::dimensions ( ) const

Gets the matrix size.

The matrix size as a row/column pair.

◆ end()

Non_zero_chain_indices::iterator SparseMatrix::end ( ) const
noexcept

Iterator past-the-end of chain indices.

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

◆ eye() [1/2]

void SparseMatrix::eye ( size_t nrows,
size_t ncols )

Sets an identity matrix.

Parameters
nrowsNumber of rows of the matrix.
ncolsNumber of columns of the matrix.

◆ eye() [2/2]

void SparseMatrix::eye ( std::pair< size_t, size_t > dimensions)

Sets an identity matrix.

Parameters
dimensionsPair containing the number of rows and number of columns of the matrix.

◆ is_empty()

bool SparseMatrix::is_empty ( )

Tests if a Sparse_matrix is empty.

The function return true is the Sparse_matrix is empty (that is, if the number of columns or rows is null) and false otherwise.

◆ is_null()

bool SparseMatrix::is_null ( )

Tests if a sparse matrix is null.

The function returns true if the sparse matrix is null (technically, the sparse matrix is empty, and thus encodes a matrix in which all coefficients are zero) and false otherwise.

◆ nullify()

void SparseMatrix::nullify ( )

Cleans a sparse matrix (set all coefficients to zero).

Empties all structures of the sparse matrix.

◆ operator*=()

SparseMatrix & SparseMatrix::operator*= ( const Coefficient_ring & lambda)

Applies factor on each coefficient and assign.

This method multiplies the matrix by a scalar factor lambda.

◆ operator-=()

SparseMatrix & SparseMatrix::operator-= ( SparseMatrix & matrix,
const SparseMatrix & 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 matrix) representing the result (when possible, prefer -= for efficiency).

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

◆ operator/=() [1/2]

SparseMatrix & SparseMatrix::operator/= ( const std::vector< size_t > & indices)

Build and return a new matrix by copying a matrix and removing all chains with indices in the indices vector.

The result is thus a block of the initial matrix. When possible, for efficiency, prefer /=.

Note
Will return a copy of the matrix if given vector is empty.
Warning
The matrix will perform boundary check.
Parameters
indicesThe indices of the chains to remove.
Returns
A new matrix containing the result.

◆ operator/=() [2/2]

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

Remove the chain at a given index.

The result is thus a block of the initial matrix.

Warning
The matrix will perform boundary check.
Parameters
indexThe index of the chain to remove.
Returns
A reference on the modified matrix.

◆ operator[]()

Matrix_chain SparseMatrix::operator[] ( size_t index) const

Gets the value of a chain from a const matrix.

For COLUMN matrices, returns the index-th column, for ROW matrices, returns the index-th row.

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

◆ reverse_begin()

Non_zero_chain_indices::iterator SparseMatrix::reverse_begin ( ) const
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()

Non_zero_chain_indices::iterator SparseMatrix::reverse_end ( ) const
noexcept

Reverse iterator past-the-end of chain indices.

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

◆ set_column()

void SparseMatrix::set_column ( SparseMatrix & matrix,
size_t index,
const SparseChain & column )

Set the value of the column at a given index from the matrix to column (whatever the Storage_format of the matrix).

Note
For column-matrices, the operation copies non zero coefficients of the column chain, for row-matrices a traversal of the matrix is required (in \(\mathcal O(n)\)).
Warning
The matrix will perform boundary check.
Parameters
matrixThe matrix.
indexThe column index.
columnThe new column value.
Precondition
column.is_column() must be true

◆ set_row()

void SparseMatrix::set_row ( SparseMatrix & matrix,
size_t index,
const SparseChain & row )

Set the value of the row at a given index from the matrix to chain (whatever the StorageFormat of the matrix).

Note
For row-matrices, the operation copies non zero coefficients of the row chain, for column-matrices a traversal of the matrix is required (in \(\mathcal O(n)\)).
Warning
The matrix will perform boundary check.
Parameters
matrixThe matrix.
indexThe row index.
rowThe new row value.
Precondition
row.is_row() must be true

◆ transpose()

SparseMatrix SparseMatrix::transpose ( )

Transposes a matrix.

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

◆ get_coefficient

Coefficient_ring get_coefficient ( const SparseMatrix & 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.

◆ get_column

SparseChain get_column ( const SparseMatrix & matrix,
size_t index )
friend

Gets the value of the column at a given index from the matrix (whatever the Storage_format of the matrix).

For column-matrices, the operation comes to copy non zero coefficients of the column; for row-matrices a traversal of the matrix is required (in \(\mathcal O(n)\)). Whenever possible, prefer cget_column().

Warning
The matrix will perform boundary check.
Parameters
matrixThe matrix considered.
indexThe coefficient index.
Returns
The column at given index.

◆ get_row

SparseChain get_row ( const SparseMatrix & matrix,
size_t index )
friend

Get sthe value of the row at a given index from the matrix (whatever the Storage_format of the matrix).

For row-matrices, the operation comes to copy non zero coefficients of the row; for column-matrices a traversal of the matrix is required (in \(\mathcal O(n)\)). Whenever possible, prefer cget_row().

Warning
The matrix will perform boundary check.
Parameters
matrixThe matrix considered.
indexThe coefficient index.
Returns
The row at given index.

◆ operator%

SparseMatrix operator% ( const SparseMatrix & first,
const SparseMatrix & second )
friend

Perform multiplication of matrices and return a new row-major matrix.

Perform standard linear algebra multiplication of matrices and return a new row-major matrix (when possible, prefer *= for efficiency). Matrices must have the same Coefficient_ring but can have different Storage_format. The multiplication is optimized (using standard definition or block multiplications) for each combination of Storage_format. However, efficiency depends on Storage_format.

Parameters
firstThe first matrix.
secondThe second matrix.
Returns
The result of the matrix multiplication, row-based.

◆ operator* [1/5]

SparseMatrix operator* ( const Coefficient_ring & lambda,
const SparseMatrix & 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* [2/5]

SparseChain operator* ( const SparseChain & row,
const SparseMatrix & matrix )
friend

Perform multiplication of a row-chain and a sparse matrix (column or row major).

The function returns a new row-major chain.

Perform standard linear algebra multiplication of a row-chain and a matrix (ie. row vector / matrix multiplication) and returns a new row-major chain. Both arguments must have the same Coefficient_ring but the matrix can have any Storage_format (and the multiplication is optimized for each of them).

Parameters
rowThe row-major chain.
matrixThe matrix.
Returns
The result of the matrix multiplication, row-based.
Precondition
the matrix and the chain must have the same Coefficient_ring.
row.is_row() must be true

◆ operator* [3/5]

SparseMatrix operator* ( const SparseMatrix & first,
const SparseMatrix & second )
friend

Perform multiplication of matrices and return a new column-major matrix.

Perform standard linear algebra multiplication of matrices and return a new column-major matrix (when possible, prefer *= for efficiency). Matrices must have the same Coefficient_ring but can have different Storage_format. The multiplication is optimized (using standard definition or block multiplications) for each combination of Storage_format. However, efficiency depends on Storage_format (when possible, prefer row-major by column-major multiplications).

Parameters
firstThe first matrix.
secondThe second matrix.
Returns
The result of the matrix multiplication, column-based.

◆ operator* [4/5]

SparseMatrix operator* ( const SparseMatrix & matrix,
const Coefficient_ring & 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
lambdaThe factor to apply.
Returns
A new matrix representing the result.

◆ operator* [5/5]

SparseChain operator* ( const SparseMatrix & matrix,
const SparseChain & column )
friend

Perform multiplication of a sparse matrix (column or row major) and a column-chain.

The function returns a new column-major chain.

Perform standard linear algebra multiplication of a matrix and a column-chain (ie. matrix / column vector multiplication) and returns a new column-major chain. Both arguments must have the same Coefficient_ring but the matrix can have any Storage_format (and the multiplication is optimized for each of them).

Parameters
matrixThe matrix.
columnThe column-major chain.
Returns
The result of the matrix multiplication, column-based.
Precondition
the matrix and the chain must have the same Coefficient_ring.
column.is_column() must be true

◆ operator*=

SparseMatrix & operator*= ( SparseMatrix & matrix,
const SparseMatrix & other )
friend

Perform multiplication of matrices and assign the result to matrix.

Perform standard linear algebra multiplication. Matrices must have the same Coefficient_ring but can have different Storage_format. The multiplication is optimized for each combination of Storage_format.

Parameters
matrixThe first matrix.
otherThe second matrix.
Returns
A reference to the modified matrix matrix containing the result.

◆ operator+

SparseMatrix operator+ ( const SparseMatrix & first,
const SparseMatrix & second )
friend

Perform addition of matrices and assign the result to matrix.

Perform standard linear algebra addition. Matrices must have the same Coefficient_ring but can have different Storage_format. The addition is optimized for each combination of Storage_format.

Parameters
firstThe first matrix.
secondThe second matrix.
Returns
A reference to the modified matrix matrix containing the result.

◆ operator+=

SparseMatrix & operator+= ( SparseMatrix & matrix,
const SparseMatrix & other )
friend

Perform addition of matrices and assign the result to matrix.

Perform standard linear algebra addition. Matrices must have the same Coefficient_ring but can have different Storage_format. The addition is optimized for each combination of Storage_format.

Parameters
matrixThe first matrix.
otherThe second matrix.
Returns
A reference to the modified matrix matrix containing the result.

◆ operator- [1/2]

SparseMatrix operator- ( const SparseMatrix & first,
const SparseMatrix & second )
friend

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 Coefficient_ring but can have different Storage_format.
Warning
Will raise an error if the other matrix is not the same Coefficient_ring.
Parameters
firstThe first matrix.
secondThe second matrix.
Returns
A new matrix representing the result.

◆ operator- [2/2]

SparseMatrix operator- ( const SparseMatrix & matrix)
friend

Computes the negative of a matrix (unary operator).

Returns
The resulting matrix.

◆ operator/ [1/2]

SparseMatrix operator/ ( const SparseMatrix & matrix,
const std::vector< size_t > & indices )
friend

Build and return a new matrix by copying a matrix and removing the chains with indices in the indices vector.

The result is thus a block of the initial matrix. When possible, for efficiency, prefer /=.

Note
Will return a copy of the matrix if given vector is empty.
Warning
The matrix will perform boundary check.
Parameters
matrixThe initial matrix.
indicesThe indices of the chains to remove.
Returns
A new matrix containing the result.

◆ operator/ [2/2]

SparseMatrix operator/ ( const SparseMatrix & matrix,
size_t index )
friend

Build and return a new matrix by copying a matrix and removing the chain at a given index.

The result is thus a block of the initial matrix. When possible, for efficiency, prefer /=.

Note
Will return a copy of the matrix if given vector is empty.
Warning
The matrix will perform boundary check.
Parameters
matrixThe initial matrix.
indexThe index of the chain to remove.
Returns
A new matrix containing the result.

◆ operator<<

std::ostream & operator<< ( std::ostream & _stream,
const SparseMatrix & matrix )
friend

Writes a sparse matrix in the output stream with a compact "user friendly" format.

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

◆ read_matrix [1/2]

template<typename _CT>
std::istream & read_matrix ( SparseMatrix & matrix,
std::istream & in )
friend

Read a sparse matrix from an input stream using the .osm file format.

Read a sparse matrix (the input must respect the .osm file format), .see OSM file format documentation.

◆ read_matrix [2/2]

template<typename _CT>
std::istream & read_matrix ( SparseMatrix & matrix,
std::string filename )
friend

Read a sparse matrix from a file using the .osm file format.

Read a sparse matrix (the input must respect the .osm file format), .see OSM file format documentation.

◆ remove_coefficient

SparseMatrix & remove_coefficient ( SparseMatrix & 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

SparseMatrix & remove_column ( SparseMatrix & matrix,
size_t index )
friend

Removes a column from the matrix.

Removes column of index index whatever the Storage_format 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
A reference over the modified matrix.

◆ remove_row

SparseMatrix & remove_row ( SparseMatrix & matrix,
size_t index )
friend

Removes a row from the matrix.

Removes row of index index whatever the Storage_format 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
A reference over the modified matrix.

◆ set_coefficient

void set_coefficient ( SparseMatrix & matrix,
size_t i,
size_t j,
const Coefficient_ring 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.

◆ swap_columns

Sparse_matrix & swap_columns ( Sparse_matrix & matrix,
size_t i,
size_t j )
friend

Swaps columns in a matrix.

Swaps columns at indices i and j whatever the StorageFormat of the matrix. For column matrices, the operation runs in constant time, while it entails a traversal of the matrix for row matrices.

Parameters
matrixReference on the matrix to modify.
iIndex of the first column.
jIndex of the second column.
Returns
A reference over the modified matrix.

◆ swap_rows

Sparse_matrix & swap_rows ( Sparse_matrix & matrix,
size_t i,
size_t j )
friend

Swaps rows in a matrix.

Swaps rows at indices i and j whatever the Storage_format of the matrix. For row matrices, the operation runs in constant time, while it entails a traversal of the matrix for column matrices.

Parameters
matrixReference on the matrix to modify.
iIndex of the first row.
jIndex of the second row.
Returns
A reference over the modified matrix.

◆ write_matrix [1/2]

std::ostream & write_matrix ( const SparseMatrix & matrix,
std::ostream & out )
friend

Write a sparse matrix to an output stream using the .osm file format.

Output a sparse matrix (the matrix can be reloaded using read_matrix), see OSM file format documentation.

◆ write_matrix [2/2]

std::ostream & write_matrix ( const SparseMatrix & matrix,
std::string filename )
friend

Write a sparse matrix to a file using the .osm file format.

Output a sparse matrix (the matrix can be reloaded using read_matrix), see OSM file format documentation.