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

The sparse vector matrix format. More...

#include <SVM.hpp>

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

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

Detailed Description

template<typename T>
class SVM< T >

The sparse vector matrix format.

Constructor & Destructor Documentation

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

Base constructor.

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

Base constructor which only initialises the internal arrays.

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 to be stored.
zeroWhich element is considered to be the zero element.
template<typename T>
SVM< T >::SVM ( SVM< T > &  toCopy)
inline

Copy constructor.

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

template<typename T>
SVM< T >::SVM ( const std::vector< Triplet< T > > &  input,
const ULI  m,
const ULI  n,
const T  zero,
const char  direction = 0 
)
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.

Parameters
inputThe input collection.
mTotal number of rows.
nTotal number of columns.
zeroWhich element is considered zero.
direction0 for row-major, 1 for column major.

References SVM< T >::load().

template<typename T>
SVM< T >::~SVM ( )
inline

Base deconstructor.

Member Function Documentation

template<typename T>
virtual size_t SVM< T >::bytesUsed ( )
inlinevirtual

Function to query the amount of storage required by this sparse matrix.

Returns
The size of the sparse matrix in bytes.

Implements Matrix< T >.

References SparseMatrix< T, ULI >::nnz, and SparseMatrix< T, ULI >::nor.

template<typename T>
bool SVM< T >::find ( const ULI  col_index,
const ULI  row_index,
Triplet< double > &  ret 
)
inlineprotected

Helper function which finds a value with a given index.

Parameters
col_indexThe given column index.
row_indexThe given row index.
retReference to the variable where the return triplet is stored (if found).
Returns
Whether or not a non-zero value was found.

References SVM< T >::ds, Triplet< T >::i(), Triplet< T >::j(), and SVM< T >::major.

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

template<typename T>
std::vector< std::vector< Triplet< double > > >& SVM< T >::getData ( )
inline
Returns
Direct access to the SVM datastructure.

References SVM< T >::ds.

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

Returns the first nonzero index, per reference.

Implements SparseMatrix< T, ULI >.

References SVM< T >::ds.

template<typename T>
virtual void SVM< T >::load ( std::vector< Triplet< T > > &  input,
const ULI  m,
const ULI  n,
const T  zero 
)
inlinevirtual

This will default to row-major SVM format.

See also
SparseMatrix::load

Implements SparseMatrix< T, ULI >.

Referenced by SVM< T >::SVM().

template<typename T>
void SVM< T >::load ( const std::vector< Triplet< T > > &  input,
const ULI  m,
const ULI  n,
const T  zero,
const char  direction 
)
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.

Parameters
inputThe input collection.
mTotal number of rows.
nTotal number of columns.
zeroWhich element is considered zero.
direction0 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.

template<typename T>
T& SVM< 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 SVM< T >::find(), Triplet< T >::value, and SparseMatrix< T, ULI >::zero_element.

template<typename T>
virtual void SVM< 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 >.

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.

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

In-place z=xA function.

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


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