34 #include "SparseMatrix.hpp"
35 #include "Triplet.hpp"
49 template<
typename T,
typename _i_value=LI >
67 if( one->
i() < two->
i() )
69 if ( one->
i() > two->
i() )
71 return one->
j() < two->
j();
76 if( one->
i() < two->
i() )
78 if ( one->
i() > two->
i() )
80 return one->
j() > two->
j();
92 ZZ_CRS( std::string file, T zero = 0 ) {
105 ZZ_CRS(
const long int number_of_nonzeros,
const long int number_of_rows,
const long int number_of_cols, T zero ):
106 SparseMatrix< T, unsigned long int >( number_of_nonzeros, number_of_rows, number_of_cols, zero ) {
107 ds =
new T[ this->
nnz ];
121 ds =
new T[ this->
nnz ];
124 for(
long int i=0; i<this->
nnz; i = i + 1 ) {
125 ds[ i ] = toCopy.
ds[ i ];
128 for(
long int i=0; i<=this->
nor; i++ )
143 load( input, m, n, zero );
149 this->
nnz = input.size();
153 std::vector< std::vector< Triplet< T >* > >
ds( this->
nor );
156 typename std::vector< Triplet< T > >::iterator in_it = input.begin();
157 for( ; in_it != input.end(); in_it++ ) {
159 const long int currow = cur->
i();
160 const T value = cur->
value;
162 ds.at( currow ).push_back( cur );
166 this->ds =
new T[ this->
nnz ];
173 for(
long int currow = 0; currow < this->
nor; currow++ ) {
175 if( ds.at( currow ).size() == 0 )
continue;
181 typename std::vector< Triplet< T >* >::iterator row_it = ds.at( currow ).begin();
182 for( ; row_it!=ds.at( currow ).end(); row_it++ ) {
184 this->ds[ index ] = cur.
value;
189 assert( index == this->
nnz );
195 row =
static_cast< unsigned long int >( this->
row_start[ 0 ] );
196 col =
static_cast< unsigned long int >( this->
col_ind[ 0 ] );
205 virtual void zxa(
const T* x, T* z ) {
206 T*__restrict__ ds_p =
ds;
207 LI*__restrict__ col_ind_p =
col_ind;
209 for( row = 0; row < this->
nor; row++, x++ ) {
211 z[ *col_ind_p++ ] += *ds_p++ * *x;
221 virtual void zax(
const T*__restrict__ x, T*__restrict z ) {
222 T*__restrict__ ds_p =
ds;
223 _i_value*__restrict__ col_ind_p =
col_ind;
224 long int index=0,row=0;
225 for( ; row < this->
nor; row++, z++ )
227 *z += *ds_p++ * x[ *col_ind_p++ ];
231 return sizeof( LI ) * ( this->
nnz + this->
nor + 1 ) +
sizeof( T ) * this->
nnz;
LI nnz
Number of non-zeros.
Definition: SparseMatrix.hpp:58
virtual void zxa(const T *x, T *z)
In-place z=xA multiplication algorithm.
Definition: ZZ_CRS.hpp:205
ZZ_CRS()
Base constructor.
Definition: ZZ_CRS.hpp:86
ZZ_CRS(std::string file, T zero=0)
Base constructor.
Definition: ZZ_CRS.hpp:92
LI * row_start
Array containing the row jumps.
Definition: ZZ_CRS.hpp:63
ULI i() const
Definition: Triplet.hpp:70
virtual size_t bytesUsed()
Function to query the amount of storage required by this sparse matrix.
Definition: ZZ_CRS.hpp:230
virtual unsigned long int m()
Queries the number of rows this matrix contains.
Definition: SparseMatrix.hpp:107
T * ds
Array containing the actual this->nnz non-zeros.
Definition: ZZ_CRS.hpp:57
ZZ_CRS(ZZ_CRS< T > &toCopy)
Copy constructor.
Definition: ZZ_CRS.hpp:116
ZZ_CRS(const long int number_of_nonzeros, const long int number_of_rows, const long int number_of_cols, T zero)
Base constructor which only initialises the internal arrays.
Definition: ZZ_CRS.hpp:105
void loadFromFile(const std::string file, const T zero=0)
Function which loads a matrix from a matrix market file.
Definition: SparseMatrix.hpp:89
Interface common to all sparse matrix storage schemes.
Definition: SparseMatrix.hpp:46
static bool compareTripletsRTL(const Triplet< T > *one, const Triplet< T > *two)
Comparison function used for sorting input data.
Definition: ZZ_CRS.hpp:75
static bool compareTripletsLTR(const Triplet< T > *one, const Triplet< T > *two)
Comparison function used for sorting input data.
Definition: ZZ_CRS.hpp:66
LI * col_ind
Array containing the column jumps.
Definition: ZZ_CRS.hpp:60
LI noc
Number of columns.
Definition: SparseMatrix.hpp:55
T value
Value stored at this triplet.
Definition: Triplet.hpp:95
virtual void load(std::vector< Triplet< T > > &input, const LI m, const LI n, const T zero)
Definition: ZZ_CRS.hpp:147
LI nor
Number of rows.
Definition: SparseMatrix.hpp:52
ZZ_CRS(std::vector< Triplet< T > > &input, const LI m, const LI n, const T zero)
Constructor which transforms a collection of input triplets to CRS format.
Definition: ZZ_CRS.hpp:142
T zero_element
The element considered to be zero.
Definition: SparseMatrix.hpp:63
The zig-zag compressed row storage sparse matrix data structure.
Definition: ZZ_CRS.hpp:50
ULI j() const
Definition: Triplet.hpp:73
virtual void getFirstIndexPair(LI &row, LI &col)
Returns the first nonzero index, per reference.
Definition: ZZ_CRS.hpp:194
virtual unsigned long int n()
Queries the number of columns this matrix contains.
Definition: SparseMatrix.hpp:115
virtual void zax(const T *__restrict__ x, T *__restrict z)
In-place z=Ax multiplication algorithm.
Definition: ZZ_CRS.hpp:221
A single triplet value.
Definition: Triplet.hpp:52
~ZZ_CRS()
Base deconstructor.
Definition: ZZ_CRS.hpp:235