The SparseMatrix class represents a sparse square matrix in CSR format.
More...
#include <SparseMatrix.hpp>
|
| SparseMatrix () |
| Construct a new SparseMatrix object.
|
|
| SparseMatrix (std::string const &fileName, std::string const &fileType="bin") |
| Construct a new SparseMatrix object using the read method.
|
|
| SparseMatrix (const SparseMatrix &other)=default |
| Copy constructor.
|
|
| SparseMatrix (SparseMatrix &&other)=default |
| Move constructor.
|
|
T | operator() (Id row, Id col) const |
| Returns the element at the specified row and column.
|
|
SparseMatrix & | operator= (const SparseMatrix &other)=default |
|
SparseMatrix & | operator= (SparseMatrix &&other)=default |
|
bool | operator== (const SparseMatrix &other) const |
|
size_t | size () const noexcept |
| Returns the number of (non-zero) elements in the matrix.
|
|
bool | empty () const noexcept |
| Returns true if the matrix is empty.
|
|
size_t | n () const noexcept |
| Returns the number of rows (columns) in the matrix.
|
|
std::map< Id, T > | row (Id idRow) const |
| Returns a row of the matrix as a map of column indices and values.
|
|
std::map< Id, T > | col (Id idCol) const |
| Returns a column of the matrix as a map of row indices and values.
|
|
void | setDefaultValue (T value) |
| Set the default value of the matrix (default is 0)
|
|
void | insert (Id row, Id col, T value) |
| Insert a new element of given value at the specified row and column.
|
|
void | normalize (const axis_t axis=true, const T value=static_cast< T >(1)) |
| Normalize the rows of the matrix.
|
|
void | read (std::string const &fileName, std::string const &fileType="bin", std::unordered_map< std::string, Id > const &mapping={}) |
| Read the sparse matrix from a binary file.
|
|
void | save (std::string const &fileName) const |
| Save the sparse matrix to a binary file.
|
|
template<typename T>
requires (std::is_arithmetic_v<T>)
class dsm::SparseMatrix< T >
The SparseMatrix class represents a sparse square matrix in CSR format.
This implementations is optimized for row access.
◆ SparseMatrix() [1/3]
template<typename T>
requires (std::is_arithmetic_v<T>)
dsm::SparseMatrix< T >::SparseMatrix |
( |
std::string const & | fileName, |
|
|
std::string const & | fileType = "bin" ) |
Construct a new SparseMatrix object using the read method.
- Parameters
-
fileName | The name of the file containing the sparse matrix |
fileType | The type of the file (default is "bin") |
◆ SparseMatrix() [2/3]
Copy constructor.
- Parameters
-
◆ SparseMatrix() [3/3]
Move constructor.
- Parameters
-
◆ col()
template<typename T>
requires (std::is_arithmetic_v<T>)
Returns a column of the matrix as a map of row indices and values.
- Parameters
-
- Returns
- A map of row indices and values for the specified column
◆ empty()
Returns true if the matrix is empty.
- Returns
- true if the matrix is empty, false otherwise
◆ insert()
template<typename T>
requires (std::is_arithmetic_v<T>)
Insert a new element of given value at the specified row and column.
- Parameters
-
row | The row index of the element |
col | The column index of the element |
value | The value of the element |
This function actually inserts element a_{ij} of the sparse matrix. Where i is the row index and j is the column index. The function will automatically resize the matrix to fit the new element.
◆ n()
Returns the number of rows (columns) in the matrix.
- Returns
- The number of rows (columns) in the matrix
◆ normalize()
template<typename T>
requires (std::is_arithmetic_v<T>)
void dsm::SparseMatrix< T >::normalize |
( |
const axis_t | axis = true, |
|
|
const T | value = static_cast<T>(1) ) |
Normalize the rows of the matrix.
- Parameters
-
axis | If 1, normalize the rows, otherwise (0) normalize the columns |
value | The value to normalize the rows to (default is 1) |
The function will normalize the rows of the matrix to have the sum equal to the given value.
◆ operator()()
template<typename T>
requires (std::is_arithmetic_v<T>)
Returns the element at the specified row and column.
- Parameters
-
row | The row index of the element |
col | The column index of the element |
- Returns
- The element at the specified row and column
◆ read()
template<typename T>
requires (std::is_arithmetic_v<T>)
void dsm::SparseMatrix< T >::read |
( |
std::string const & | fileName, |
|
|
std::string const & | fileType = "bin", |
|
|
std::unordered_map< std::string, Id > const & | mapping = {} ) |
Read the sparse matrix from a binary file.
- Parameters
-
fileName | The name of the file containing the sparse matrix |
fileType | The type of the file (default is "bin") |
mapping | A mapping of the indices from strings to 0 -> N-1 |
- Exceptions
-
std::runtime_error | if the file cannot be opened |
◆ row()
template<typename T>
requires (std::is_arithmetic_v<T>)
Returns a row of the matrix as a map of column indices and values.
- Parameters
-
- Returns
- A map of column indices and values for the specified row
◆ save()
template<typename T>
requires (std::is_arithmetic_v<T>)
Save the sparse matrix to a binary file.
- Parameters
-
fileName | The name of the file to save the sparse matrix |
- Exceptions
-
std::runtime_error | if the file cannot be opened |
◆ setDefaultValue()
Set the default value of the matrix (default is 0)
- Parameters
-
value | The default value of the matrix |
◆ size()
Returns the number of (non-zero) elements in the matrix.
- Returns
- The number of elements in the matrix
The documentation for this class was generated from the following file:
- src/dsm/headers/SparseMatrix.hpp