SparseLibrary
Version 1.6.0
|
The compressed row storage sparse matrix data structure. More...
#include <CRS.hpp>
Public Member Functions | |
CRS () | |
Base constructor. More... | |
CRS (std::string file, T zero=0) | |
Base constructor. More... | |
CRS (const ULI number_of_nonzeros, const ULI number_of_rows, const ULI number_of_cols, T zero) | |
Base constructor which only initialises the internal arrays. More... | |
CRS (CRS< T > &toCopy) | |
Copy constructor. More... | |
CRS (std::vector< Triplet< T > > input, ULI m, ULI n, T zero) | |
Constructor which transforms a collection of input triplets to CRS format. More... | |
virtual void | load (std::vector< Triplet< T > > &input, ULI m, ULI n, T zero) |
T & | random_access (ULI i, ULI j) |
Method which provides random matrix access to the stored sparse matrix. More... | |
virtual void | getFirstIndexPair (ULI &row, ULI &col) |
Returns the first nonzero index, per reference. More... | |
virtual void | zxa (const T *__restrict__ x, T *__restrict__ z) |
In-place z=xA function. | |
virtual void | zax (const T *__restrict__ x, T *__restrict__ z) |
In-place z=Ax function. More... | |
template<size_t k> | |
void | ZaX (const T *__restrict__ const *__restrict__ const X, T *__restrict__ const *__restrict__ const Z) |
template<size_t k> | |
void | ZXa (const T *__restrict__ const *__restrict__ const X, T *__restrict__ const *__restrict__ const Z) |
ULI * | rowJump () |
Returns pointer to the row_start vector. More... | |
ULI * | columnIndices () |
Returns pointer to the column index vector. More... | |
T * | values () |
Returns pointer to the matrix nonzeros vector. More... | |
virtual | ~CRS () |
Base deconstructor. More... | |
virtual size_t | bytesUsed () |
Public Member Functions inherited from SparseMatrix< T, ULI > | |
SparseMatrix () | |
Base constructor. More... | |
SparseMatrix (const ULInzs, const ULInr, const ULInc, const T zero) | |
Base constructor. More... | |
virtual | ~SparseMatrix () |
Base deconstructor. More... | |
void | loadFromFile (const std::string file, const T zero=0) |
Function which loads a matrix from a matrix market file. More... | |
virtual unsigned long int | m () |
Queries the number of rows this matrix contains. More... | |
virtual unsigned long int | n () |
Queries the number of columns this matrix contains. More... | |
virtual unsigned long int | nzs () |
Queries the number of nonzeroes stored in this matrix. More... | |
virtual T * | mv (const T *x) |
Calculates and returns z=Ax. More... | |
Public Member Functions inherited from Matrix< T > | |
Matrix () | |
Base constructor. More... | |
virtual | ~Matrix () |
Base deconstructor. More... | |
virtual void | zax (const T *__restrict__ x, T *__restrict__ z, const size_t k, const clockid_t clock_id=0, double *elapsed_time=NULL) |
Wrapper function to call the zax kernel multiple times successively, while timing the duration of the operation. More... | |
template<size_t k> | |
void | ZaX (const T *__restrict__ const *__restrict__ const X, T *__restrict__ const *__restrict__ const Z) |
In-place Z=AX function, where A is m x n, Z = m x k, and X is n x k. More... | |
template<size_t k> | |
void | ZXa (const T *__restrict__ const *__restrict__ const X, T *__restrict__ const *__restrict__ const Z) |
In-place Z=XA function, where A is m x n, Z = k x n, and X is k x m. More... | |
virtual void | zxa (const T *__restrict__ x, T *__restrict__ z, const unsigned long int repeat, const clockid_t clock_id=0, double *elapsed_time=NULL) |
Wrapper function to call the zxa kernel multiple times successively, while timing the operation duration. More... | |
Protected Member Functions | |
bool | find (const ULI col_index, const ULI search_start, const ULI search_end, ULI &ret) |
Helper function which finds a value with a given column index on a given subrange of indices. More... | |
Static Protected Member Functions | |
static int | compareTriplets (const void *left, const void *right) |
Sorts 1D columnwise. | |
Protected Attributes | |
ULI * | row_start |
Array keeping track of individual row starting indices. More... | |
T * | ds |
Array containing the actual nnz non-zeros. More... | |
ULI * | col_ind |
Array containing the column indeces corresponding to the elements in ds. More... | |
Protected Attributes inherited from SparseMatrix< T, ULI > | |
ULI | nor |
Number of rows. More... | |
ULI | noc |
Number of columns. | |
ULI | nnz |
Number of non-zeros. More... | |
Additional Inherited Members | |
Public Attributes inherited from SparseMatrix< T, ULI > | |
T | zero_element |
The element considered to be zero. More... | |
The compressed row storage sparse matrix data structure.
Base constructor.
Will read in from Matrix Market file.
References SparseMatrix< T, ULI >::loadFromFile().
|
inline |
Base constructor which only initialises the internal arrays.
Note that to gain a valid CRS structure, these arrays have to be filled by some external mechanism (i.e., after calling this constructor, the internal arrays contain garbage, resuling in invalid datastructure).
number_of_nonzeros | The number of non-zeros to be stored. |
number_of_rows | The number of rows to be stored. |
number_of_cols | The number of columns of the matrix. |
zero | The element considered to be zero. |
References CRS< T >::col_ind, CRS< T >::ds, SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, CRS< T >::row_start, and SparseMatrix< T, ULI >::zero_element.
Copy constructor.
toCopy | reference to the CRS datastructure to copy. |
References CRS< T >::col_ind, CRS< T >::ds, SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::nor, CRS< T >::row_start, and SparseMatrix< T, ULI >::zero_element.
|
inline |
Constructor which transforms a collection of input triplets to CRS format.
The input collection is considered to have at most one triplet with unique pairs of indeces. Unspecified behaviour occurs when this assumption is not met.
input | The input collection. |
m | Total number of rows. |
n | Total number of columns. |
zero | The element considered to be zero. |
References CRS< T >::load().
Base deconstructor.
References CRS< T >::col_ind, CRS< T >::ds, and CRS< T >::row_start.
|
inlinevirtual |
Implements Matrix< T >.
References SparseMatrix< T, ULI >::nnz, and SparseMatrix< T, ULI >::nor.
|
inline |
Returns pointer to the column index vector.
References CRS< T >::col_ind.
|
inlineprotected |
Helper function which finds a value with a given column index on a given subrange of indices.
col_index | The given column index. |
search_start | The start index of the subrange (inclusive). |
search_end | The end index of the subrange (exlusive). |
ret | Reference to the variable where the return index is stored. |
References CRS< T >::col_ind.
Referenced by CRS< T >::random_access().
|
inlinevirtual |
Returns the first nonzero index, per reference.
Implements SparseMatrix< T, ULI >.
References CRS< T >::col_ind, and CRS< T >::row_start.
|
inlinevirtual |
Implements SparseMatrix< T, ULI >.
References CRS< T >::col_ind, CRS< T >::compareTriplets(), CRS< T >::ds, Triplet< T >::j(), SparseMatrix< T, ULI >::m(), SparseMatrix< T, ULI >::n(), SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, CRS< T >::row_start, Triplet< T >::value, and SparseMatrix< T, ULI >::zero_element.
Referenced by CRS< T >::CRS(), and MKLCRS< T >::MKLCRS().
|
inline |
Method which provides random matrix access to the stored sparse matrix.
i | Row index. |
j | Column index. |
References CRS< T >::ds, CRS< T >::find(), CRS< T >::row_start, and SparseMatrix< T, ULI >::zero_element.
|
inline |
Returns pointer to the row_start vector.
References CRS< T >::row_start.
|
inline |
Returns pointer to the matrix nonzeros vector.
References CRS< T >::ds.
|
inlinevirtual |
In-place z=Ax function.
x | The x vector to multiply current matrix with. |
z | The result vector. Must be pre-allocated and its elements should be initialised to zero. |
Implements SparseMatrix< T, ULI >.
Reimplemented in MKLCRS< T >.
References CRS< T >::col_ind, CRS< T >::ds, SparseMatrix< T, ULI >::nor, and CRS< T >::row_start.
|
inline |
References CRS< T >::col_ind, CRS< T >::ds, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, and CRS< T >::row_start.
|
inline |
References CRS< T >::col_ind, CRS< T >::ds, SparseMatrix< T, ULI >::nor, and CRS< T >::row_start.
|
protected |
Array containing the column indeces corresponding to the elements in ds.
Referenced by CRS< T >::columnIndices(), CRS< T >::CRS(), CRS< T >::find(), CRS< T >::getFirstIndexPair(), CRS< T >::load(), MKLCRS< T >::MKLCRS(), MKLCRS< T >::prepare(), CRS< T >::zax(), CRS< T >::ZaX(), CRS< T >::zxa(), CRS< T >::ZXa(), and CRS< T >::~CRS().
|
protected |
Array containing the actual nnz non-zeros.
Referenced by CRS< T >::CRS(), CRS< T >::load(), MKLCRS< T >::MKLCRS(), CRS< T >::random_access(), CRS< T >::values(), MKLCRS< T >::zax(), CRS< T >::zax(), CRS< T >::ZaX(), CRS< T >::zxa(), CRS< T >::ZXa(), and CRS< T >::~CRS().
|
protected |
Array keeping track of individual row starting indices.
Referenced by CRS< T >::CRS(), CRS< T >::getFirstIndexPair(), CRS< T >::load(), MKLCRS< T >::MKLCRS(), MKLCRS< T >::prepare(), CRS< T >::random_access(), CRS< T >::rowJump(), CRS< T >::zax(), CRS< T >::ZaX(), CRS< T >::zxa(), CRS< T >::ZXa(), and CRS< T >::~CRS().