SMG2S
Sparse Matrix Generator with Given Spectrum
MatrixCSR< T, S > Struct Template Reference

A struct which stores a sparse matrix in CSR format. More...

#include <MatrixCSR.hpp>

Public Member Functions

 MatrixCSR (S nnz_in, S nrows_in)
 A constructor of `MatrixCSR`. The three arrays MatrixCSR::rows, MatrixCSR::cols and MatrixCSR::vals are allocated, without further filling in. More...
 
 MatrixCSR (std::vector< S > rowoffs, std::vector< S > colidxs, std::vector< T > values)
 A constructor of `MatrixCSR`. The three arrays MatrixCSR::rows, MatrixCSR::cols and MatrixCSR::vals are filled with user-provided arrays. More...
 
 ~MatrixCSR ()
 This a destructor of MatrixCSR.
 
GetValue (S row, S col)
 Get the value of position `(row, col)` from sparse matrix. More...
 
void SetValue (S row, S col, T val)
 Overwrite the value of entry of position `(row, col)` in sparse matrix by `val`. More...
 
void InsertValue (S row, S col, T val)
 Insert a value `val` in the position `(row, col)` in sparse matrix. More...
 
void show ()
 Print the sparse matrix in COO format. More...
 

Public Attributes

nrows
 number of rows of a sparse matrix More...
 
nnz
 number of non-zero entries of a sparse matrix More...
 
ncols
 dimension of the array MatrixCSR::cols More...
 
std::vector< S > rows
 An array points to row starts in indices and data. More...
 
std::vector< S > cols
 An array stores the column indices of non-zero elements. More...
 
std::vector< T > vals
 An array stores the values of non-zero elements. More...
 

Detailed Description

template<typename T, typename S>
struct MatrixCSR< T, S >

A struct which stores a sparse matrix in CSR format.

This struct defines a CSR format to store a sparse matrix. This format stores a sparse matrix with three arrays

  • `rows` points to row starts in indices and data
  • `cols` is array of column indices
  • `val` is array of corresponding nonzero values
Template Parameters
Tdescribes the scalar types of the entries of a sparse matrix.
Stype of integer to describes the dimension of matrices to be generated.

Constructor & Destructor Documentation

◆ MatrixCSR() [1/2]

template<typename T , typename S >
MatrixCSR< T, S >::MatrixCSR ( nnz_in,
nrows_in 
)
inline

A constructor of `MatrixCSR`. The three arrays MatrixCSR::rows, MatrixCSR::cols and MatrixCSR::vals are allocated, without further filling in.

Parameters
[in]nnz_innumber of non-zero elements in the sparse matrix to be allocated
[in]nrows_innumber of rows of the sparse matrix to be allocated

◆ MatrixCSR() [2/2]

template<typename T , typename S >
MatrixCSR< T, S >::MatrixCSR ( std::vector< S >  rowoffs,
std::vector< S >  colidxs,
std::vector< T >  values 
)
inline

A constructor of `MatrixCSR`. The three arrays MatrixCSR::rows, MatrixCSR::cols and MatrixCSR::vals are filled with user-provided arrays.

Parameters
[in]rowoffsuser-provided array stored in a `std::vector` for MatrixCSR::rows
[in]colidxsuser-provided array stored in a `std::vector` for MatrixCSR::cols
[in]valuesuser-provided array stored in a `std::vector` for MatrixCSR::vals

Member Function Documentation

◆ GetValue()

template<typename T , typename S >
T MatrixCSR< T, S >::GetValue ( row,
col 
)
inline

Get the value of position `(row, col)` from sparse matrix.

Parameters
[in]rowindex of row of the poisition in sparse matrix
[in]colindex of column of the poisition in sparse matrix

◆ InsertValue()

template<typename T , typename S >
void MatrixCSR< T, S >::InsertValue ( row,
col,
val 
)
inline

Insert a value `val` in the position `(row, col)` in sparse matrix.

  • unlike MatrixCSR<T>::SetValue, in this function, the position `(row, col)` can be anyone which is still not available in the matrix.
    Parameters
    [in]rowindex of row of the poisition in sparse matrix
    [in]colindex of column of the poisition in sparse matrix
    [in]valthe value should be set on the position `(row, col)` of sparse matrix

◆ SetValue()

template<typename T , typename S >
void MatrixCSR< T, S >::SetValue ( row,
col,
val 
)
inline

Overwrite the value of entry of position `(row, col)` in sparse matrix by `val`.

Parameters
[in]rowindex of row of the poisition in sparse matrix
[in]colindex of column of the poisition in sparse matrix
[in]valthe value should be set on the position `(row, col)` of sparse matrix

◆ show()

template<typename T , typename S >
void MatrixCSR< T, S >::show ( )
inline

Print the sparse matrix in COO format.

Print the sparse matrix in COO format

Member Data Documentation

◆ cols

template<typename T , typename S >
std::vector<S> MatrixCSR< T, S >::cols

An array stores the column indices of non-zero elements.

Its size is `nnz`

  • non-zero entry of the `i`-th row are `vals[rows[i]:rows[i+1]]`, with column indices `cols[rows[i]:rows[i+1]]`
  • item `(i,j)` can be accessed as `vals[rows[i]+k]`, where `k` is the position of `j` in `cols[rows[i]:rows[i+1]]`

◆ ncols

template<typename T , typename S >
S MatrixCSR< T, S >::ncols

dimension of the array MatrixCSR::cols

dimension of the array MatrixCSR::cols, which stores the column indices of all non-zero entries.

◆ nnz

template<typename T , typename S >
S MatrixCSR< T, S >::nnz

number of non-zero entries of a sparse matrix

number of non-zero entries of a sparse matrix

◆ nrows

template<typename T , typename S >
S MatrixCSR< T, S >::nrows

number of rows of a sparse matrix

number of rows of a sparse matrix

◆ rows

template<typename T , typename S >
std::vector<S> MatrixCSR< T, S >::rows

An array points to row starts in indices and data.

Its size is `nrows+1`

  • non-zero entry of the `i`-th row are `vals[rows[i]:rows[i+1]]`, with column indices `cols[rows[i]:rows[i+1]]`
  • item `(i,j)` can be accessed as `vals[rows[i]+k]`, where `k` is the position of `j` in `cols[rows[i]:rows[i+1]]`

◆ vals

template<typename T , typename S >
std::vector<T> MatrixCSR< T, S >::vals

An array stores the values of non-zero elements.

Its size is `nnz`

  • non-zero entry of the `i`-th row are `vals[rows[i]:rows[i+1]]`, with column indices `cols[rows[i]:rows[i+1]]`
  • item `(i,j)` can be accessed as `vals[rows[i]+k]`, where `k` is the position of `j` in `cols[rows[i]:rows[i+1]]`

The documentation for this struct was generated from the following file: