SparseLibrary  Version 1.6.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
CRS< T > Class Template Reference

The compressed row storage sparse matrix data structure. More...

#include <CRS.hpp>

Inheritance diagram for CRS< T >:
Inheritance graph
[legend]
Collaboration diagram for CRS< T >:
Collaboration graph
[legend]

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 >
zero_element
 The element considered to be zero. More...
 

Detailed Description

template<typename T>
class CRS< T >

The compressed row storage sparse matrix data structure.

Constructor & Destructor Documentation

template<typename T>
CRS< T >::CRS ( )
inline

Base constructor.

template<typename T>
CRS< T >::CRS ( std::string  file,
zero = 0 
)
inline

Base constructor.

Will read in from Matrix Market file.

See also
SparseMatrix::SparseMatrix( file, zero )

References SparseMatrix< T, ULI >::loadFromFile().

template<typename T>
CRS< T >::CRS ( const ULI  number_of_nonzeros,
const ULI  number_of_rows,
const ULI  number_of_cols,
zero 
)
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).

Parameters
number_of_nonzerosThe number of non-zeros to be stored.
number_of_rowsThe number of rows to be stored.
number_of_colsThe number of columns of the matrix.
zeroThe 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.

template<typename T>
CRS< T >::CRS ( CRS< T > &  toCopy)
inline

Copy constructor.

Parameters
toCopyreference 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.

template<typename T>
CRS< T >::CRS ( std::vector< Triplet< T > >  input,
ULI  m,
ULI  n,
zero 
)
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.

Parameters
inputThe input collection.
mTotal number of rows.
nTotal number of columns.
zeroThe element considered to be zero.

References CRS< T >::load().

template<typename T>
virtual CRS< T >::~CRS ( )
inlinevirtual

Base deconstructor.

References CRS< T >::col_ind, CRS< T >::ds, and CRS< T >::row_start.

Member Function Documentation

template<typename T>
virtual size_t CRS< T >::bytesUsed ( )
inlinevirtual
template<typename T>
ULI* CRS< T >::columnIndices ( )
inline

Returns pointer to the column index vector.

References CRS< T >::col_ind.

template<typename T>
bool CRS< T >::find ( const ULI  col_index,
const ULI  search_start,
const ULI  search_end,
ULI &  ret 
)
inlineprotected

Helper function which finds a value with a given column index on a given subrange of indices.

Parameters
col_indexThe given column index.
search_startThe start index of the subrange (inclusive).
search_endThe end index of the subrange (exlusive).
retReference to the variable where the return index is stored.
Returns
Whether or not a non-zero value should be returned.

References CRS< T >::col_ind.

Referenced by CRS< T >::random_access().

template<typename T>
virtual void CRS< T >::getFirstIndexPair ( ULI &  row,
ULI &  col 
)
inlinevirtual

Returns the first nonzero index, per reference.

Implements SparseMatrix< T, ULI >.

References CRS< T >::col_ind, and CRS< T >::row_start.

template<typename T>
virtual void CRS< T >::load ( std::vector< Triplet< T > > &  input,
ULI  m,
ULI  n,
zero 
)
inlinevirtual
template<typename T>
T& CRS< T >::random_access ( ULI  i,
ULI  j 
)
inline

Method which provides random matrix access to the stored sparse matrix.

Parameters
iRow index.
jColumn index.
Returns
Matrix valuei at (i,j).

References CRS< T >::ds, CRS< T >::find(), CRS< T >::row_start, and SparseMatrix< T, ULI >::zero_element.

template<typename T>
ULI* CRS< T >::rowJump ( )
inline

Returns pointer to the row_start vector.

References CRS< T >::row_start.

template<typename T>
T* CRS< T >::values ( )
inline

Returns pointer to the matrix nonzeros vector.

References CRS< T >::ds.

template<typename T>
virtual void CRS< T >::zax ( const T *__restrict__  x,
T *__restrict__  z 
)
inlinevirtual

In-place z=Ax function.

Parameters
xThe x vector to multiply current matrix with.
zThe 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.

template<typename T>
template<size_t k>
void CRS< T >::ZaX ( const T *__restrict__ const *__restrict__ const  X,
T *__restrict__ const *__restrict__ const  Z 
)
inline
template<typename T>
template<size_t k>
void CRS< T >::ZXa ( const T *__restrict__ const *__restrict__ const  X,
T *__restrict__ const *__restrict__ const  Z 
)
inline

Member Data Documentation

template<typename T>
ULI* CRS< T >::col_ind
protected
template<typename T>
T* CRS< T >::ds
protected
template<typename T>
ULI* CRS< T >::row_start
protected

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