36 #include "Triplet.hpp"
37 #include "SparseMatrix.hpp"
43 template<
typename T >
68 TS( std::string file, T zero = 0 ) {
79 load( input, m, n, zero );
83 virtual void load( std::vector<
Triplet< T > >& input,
const ULI
m,
const ULI
n,
const T zero ) {
89 this->
nnz = input.size();
90 ds =
new T[ this->
nnz ];
91 i =
new ULI[ this->
nnz ];
92 j =
new ULI[ this->
nnz ];
93 for( ULI r=0; r<this->
nnz; r++ )
96 ds[ r - offset ] = input[ r ].value;
97 i[ r - offset ] = input[ r ].i();
98 j[ r - offset ] = input[ r ].j();
117 virtual void zxa(
const T* x, T* z ) {
118 for( ULI r=0; r<this->
nnz; r++ ) {
119 assert(
i[ r ] >= 0 );
120 assert(
i[ r ] < this->
nor );
121 assert(
j[ r ] >= 0 );
122 assert(
j[ r ] < this->
noc );
123 z[
j[ r ] ] +=
ds[ r ] * x[
i[ r ] ];
133 virtual void zax(
const T* x, T* z ) {
134 for( ULI r=0; r<this->
nnz; r++ ) {
135 assert(
i[ r ] >= 0 );
136 assert(
i[ r ] < this->
nor );
137 assert(
j[ r ] >= 0 );
138 assert(
j[ r ] < this->
noc );
139 z[
i[ r ] ] +=
ds[ r ] * x[
j[ r ] ];
145 void ZaX(
const T *__restrict__
const *__restrict__
const X, T *__restrict__
const *__restrict__
const Z ) {
146 for( ULI r = 0; r < this->
nnz; r++ ) {
147 assert(
i[ r ] >= 0 );
148 assert(
i[ r ] < this->
nor );
149 assert(
j[ r ] >= 0 );
150 assert(
j[ r ] < this->
noc );
152 for(
size_t s = 0; s < k; ++s ) {
153 Z[ s ][
i[ r ] ] +=
ds[ r ] * X[ s ][
j[ r ] ];
160 void ZXa(
const T *__restrict__
const *__restrict__
const X, T *__restrict__
const *__restrict__
const Z ) {
161 for( ULI r = 0; r < this->
nnz; r++ ) {
162 assert(
i[ r ] >= 0 );
163 assert(
i[ r ] < this->
nor );
164 assert(
j[ r ] >= 0 );
165 assert(
j[ r ] < this->
noc );
167 for(
size_t s = 0; s < k; ++s ) {
168 Z[ s ][
j[ r ] ] +=
ds[ r ] * X[ s ][
i[ r ] ];
175 return sizeof( ULI ) * 2 * this->
nnz +
sizeof( T ) * this->
nnz;
ULI nnz
Number of non-zeros.
Definition: SparseMatrix.hpp:58
virtual void zax(const T *x, T *z)
In-place z=Ax calculation algorithm.
Definition: TS.hpp:133
void ZXa(const T *__restrict__ const *__restrict__ const X, T *__restrict__ const *__restrict__ const Z)
Definition: TS.hpp:160
virtual size_t bytesUsed()
Definition: TS.hpp:174
ULI * j
The column indices of the nonzeros.
Definition: TS.hpp:54
TS()
Base constructor.
Definition: TS.hpp:62
virtual void getFirstIndexPair(ULI &row, ULI &col)
Returns the first nonzero index, per reference.
Definition: TS.hpp:106
virtual unsigned long int m()
Queries the number of rows this matrix contains.
Definition: SparseMatrix.hpp:107
The triplet scheme; a storage scheme for sparse matrices using triplets.
Definition: TS.hpp:44
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
ULI * i
The row indices of the nonzeros.
Definition: TS.hpp:51
ULI noc
Number of columns.
Definition: SparseMatrix.hpp:55
virtual void zxa(const T *x, T *z)
In-place z=xA calculation algorithm.
Definition: TS.hpp:117
void ZaX(const T *__restrict__ const *__restrict__ const X, T *__restrict__ const *__restrict__ const Z)
Definition: TS.hpp:145
virtual void load(std::vector< Triplet< T > > &input, const ULI m, const ULI n, const T zero)
Definition: TS.hpp:83
ULI nor
Number of rows.
Definition: SparseMatrix.hpp:52
TS(std::string file, T zero=0)
Base constructor.
Definition: TS.hpp:68
T zero_element
The element considered to be zero.
Definition: SparseMatrix.hpp:63
T * ds
The values of the nonzeros.
Definition: TS.hpp:57
TS(std::vector< Triplet< T > > &input, ULI m, ULI n, T zero=0)
Base constructor.
Definition: TS.hpp:78
virtual unsigned long int n()
Queries the number of columns this matrix contains.
Definition: SparseMatrix.hpp:115
~TS()
Base destructor.
Definition: TS.hpp:179
A single triplet value.
Definition: Triplet.hpp:52