SparseLibrary
Version 1.6.0
|
The sparse vector matrix format. More...
#include <SVM.hpp>
Public Member Functions | |
SVM () | |
Base constructor. More... | |
SVM (std::string file, T zero=0) | |
Base constructor. More... | |
SVM (const ULI number_of_nonzeros, const ULI number_of_rows, const ULI number_of_cols, const T zero) | |
Base constructor which only initialises the internal arrays. More... | |
SVM (SVM< T > &toCopy) | |
Copy constructor. More... | |
SVM (const std::vector< Triplet< T > > &input, const ULI m, const ULI n, const T zero, const char direction=0) | |
Constructor which transforms a collection of input triplets to SVM format. More... | |
virtual void | load (std::vector< Triplet< T > > &input, const ULI m, const ULI n, const T zero) |
This will default to row-major SVM format. More... | |
void | load (const std::vector< Triplet< T > > &input, const ULI m, const ULI n, const T zero, const char direction) |
Will load a collection of triplets into SVM format. More... | |
std::vector< std::vector < Triplet< double > > > & | getData () |
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. More... | |
virtual void | zax (const T *__restrict__ x, T *__restrict__ z) |
In-place z=Ax function. More... | |
virtual size_t | bytesUsed () |
Function to query the amount of storage required by this sparse matrix. More... | |
~SVM () | |
Base deconstructor. More... | |
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 row_index, Triplet< double > &ret) |
Helper function which finds a value with a given index. More... | |
Static Protected Member Functions | |
static int | compareTripletsR (const void *left, const void *right) |
Sorts 1D columnwise. | |
static int | compareTripletsC (const void *left, const void *right) |
Sorts 1D rowwise. | |
Protected Attributes | |
char | major |
Row major (0), column major (1) | |
std::vector< std::vector < Triplet< T > > > | ds |
SVM structure. | |
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 sparse vector matrix format.
Base constructor.
Will read in from Matrix Market file.
References SparseMatrix< T, ULI >::loadFromFile().
|
inline |
Base constructor which only initialises the internal arrays.
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 to be stored. |
zero | Which element is considered to be the zero element. |
Copy constructor.
toCopy | reference to the CRS datastructure to copy. |
References SVM< T >::ds, SVM< T >::major, SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, and SparseMatrix< T, ULI >::zero_element.
|
inline |
Constructor which transforms a collection of input triplets to SVM 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 | Which element is considered zero. |
direction | 0 for row-major, 1 for column major. |
References SVM< T >::load().
|
inlinevirtual |
Function to query the amount of storage required by this sparse matrix.
Implements Matrix< T >.
References SparseMatrix< T, ULI >::nnz, and SparseMatrix< T, ULI >::nor.
|
inlineprotected |
Helper function which finds a value with a given index.
col_index | The given column index. |
row_index | The given row index. |
ret | Reference to the variable where the return triplet is stored (if found). |
References SVM< T >::ds, Triplet< T >::i(), Triplet< T >::j(), and SVM< T >::major.
Referenced by SVM< T >::random_access().
References SVM< T >::ds.
|
inlinevirtual |
Returns the first nonzero index, per reference.
Implements SparseMatrix< T, ULI >.
References SVM< T >::ds.
|
inlinevirtual |
This will default to row-major SVM format.
Implements SparseMatrix< T, ULI >.
Referenced by SVM< T >::SVM().
|
inline |
Will load a collection of triplets into SVM 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 | Which element is considered zero. |
direction | 0 for row-major, 1 for column major. |
References SVM< T >::compareTripletsC(), SVM< T >::compareTripletsR(), SVM< T >::ds, Triplet< T >::i(), Triplet< T >::j(), SparseMatrix< T, ULI >::m(), SVM< T >::major, SparseMatrix< T, ULI >::n(), SparseMatrix< T, ULI >::nnz, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, Triplet< T >::value, and SparseMatrix< T, ULI >::zero_element.
|
inline |
Method which provides random matrix access to the stored sparse matrix.
i | Row index. |
j | Column index. |
References SVM< T >::find(), Triplet< T >::value, and SparseMatrix< T, ULI >::zero_element.
|
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 >.
References SVM< T >::ds, Triplet< T >::i(), Triplet< T >::j(), SVM< T >::major, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, and Triplet< T >::value.
|
inlinevirtual |
In-place z=xA function.
x | The x vector to left-multiply current matrix with. |
z | The result vector. Must be pre-allocated and its elements should be initialised to zero. |
Implements SparseMatrix< T, ULI >.
References SVM< T >::ds, Triplet< T >::i(), Triplet< T >::j(), SVM< T >::major, SparseMatrix< T, ULI >::noc, SparseMatrix< T, ULI >::nor, and Triplet< T >::value.