39 #include "FileToVT.hpp"
40 #include "alignment.hpp"
45 template<
typename T,
typename IND >
82 virtual void load( std::vector<
Triplet< T > >& input,
const IND
m,
const IND
n,
const T zero ) = 0;
91 const size_t pos = file.find_last_of(
'.' );
92 const std::string ext = file.substr( pos + 1, file.length() );
93 std::vector< Triplet< T > > VT;
94 if( ext.compare(
"trp" ) == 0 ) {
96 }
else if( ext.compare(
"crs" ) == 0 || ext.compare(
"csr" ) == 0 ) {
100 this->
load( VT, m, n, zero );
107 virtual unsigned long int m() {
108 return static_cast< unsigned long int >(
nor );
115 virtual unsigned long int n() {
116 return static_cast< unsigned long int >(
noc );
123 virtual unsigned long int nzs() {
124 return static_cast< unsigned long int >(
nnz );
142 virtual T*
mv(
const T* x ) {
145 if( posix_memalign( (
void**)&ret, 64,
nor *
sizeof( T ) ) != 0 ) {
146 std::cerr <<
"SparseMatrix::mv(): could not allocate output vector; returning NULL..." << std::endl;
150 for( IND i=0; i<
nor; i++ ) {
165 virtual void zax(
const T*__restrict__ x, T*__restrict__ z ) = 0;
173 virtual void zxa(
const T*__restrict__ x, T*__restrict__ z ) = 0;
IND nnz
Number of non-zeros.
Definition: SparseMatrix.hpp:58
static std::vector< Triplet< T > > load(const std::string fn, ULI &m, ULI &n)
Loads an array of triplets from a binary file.
Definition: Triplet.hpp:123
static std::vector< Triplet< double > > parse(std::string filename)
Parses a matrix-market input file.
Definition: FileToVT.cpp:36
virtual ~SparseMatrix()
Base deconstructor.
Definition: SparseMatrix.hpp:73
SparseMatrix(const IND nzs, const IND nr, const IND nc, const T zero)
Base constructor.
Definition: SparseMatrix.hpp:69
virtual void zxa(const T *__restrict__ x, T *__restrict__ z)=0
In-place z=xA function.
SparseMatrix()
Base constructor.
Definition: SparseMatrix.hpp:66
virtual unsigned long int m()
Queries the number of rows this matrix contains.
Definition: SparseMatrix.hpp:107
virtual void load(std::vector< Triplet< T > > &input, const IND m, const IND n, const T zero)=0
Function reading in from std::vector< Triplet< T > > format.
void loadFromFile(const std::string file, const T zero=0)
Function which loads a matrix from a matrix market file.
Definition: SparseMatrix.hpp:89
virtual unsigned long int nzs()
Queries the number of nonzeroes stored in this matrix.
Definition: SparseMatrix.hpp:123
Interface common to all sparse matrix storage schemes.
Definition: SparseMatrix.hpp:46
IND noc
Number of columns.
Definition: SparseMatrix.hpp:55
Defines operations common to all matrices, which are implemented in this library. ...
Definition: Matrix.hpp:70
static std::vector< Triplet< T > > loadCRS(const std::string fn, ULI &m, ULI &n)
Loads a CRS text file and transforms it into a vector of Triplets.
Definition: Triplet.hpp:160
IND nor
Number of rows.
Definition: SparseMatrix.hpp:52
virtual void zax(const T *__restrict__ x, T *__restrict__ z)=0
In-place z=Ax function.
T zero_element
The element considered to be zero.
Definition: SparseMatrix.hpp:63
virtual T * mv(const T *x)
Calculates and returns z=Ax.
Definition: SparseMatrix.hpp:142
virtual void getFirstIndexPair(IND &row, IND &col)=0
Returns the first nonzero index, per reference.
virtual unsigned long int n()
Queries the number of columns this matrix contains.
Definition: SparseMatrix.hpp:115
A single triplet value.
Definition: Triplet.hpp:52