35 #include "SparseMatrix.hpp"
40 #include "ZZ_ICRS.hpp"
44 #include "CCSWrapper.hpp"
77 template<
typename _t_value >
103 for( LI i=0; i<this->
nnz; i++ )
115 HBICRS( std::string file, _t_value zero = 0 ) {
116 std::cerr <<
"Error: Hierarchical BICRS, loading in from MatrixMarket file not possible, since no way to infer a hierarchy!" << std::endl;
124 load( input, m, n, zero );
131 load( input, group_type, m, n, zero );
141 std::cerr <<
"Error: Hierarchical BICRS, loading in from plain triplets not possible, since no way to infer a hierarchy!" << std::endl;
147 LI* rrow =
new LI[ input.size() ];
148 LI* ccol =
new LI[ input.size() ];
150 if( group_type == NULL ) {
151 char *group_type =
new char[ input.size() ];
152 for(
unsigned int i=0; i<input.size(); i++ ) group_type[i] = 2;
157 unsigned long int g = 0;
158 typename std::vector< std::vector< Triplet< _t_value > > >::iterator it = input.begin();
159 for( ; it!=input.end(); it++, g++ ) {
161 if( it->size() == 0 ) {
166 switch( group_type[ g ] ) {
243 std::cerr <<
"Hierarchical sparse matrix: invalid subscheme ID (" <<
static_cast<int>(group_type[g]) <<
"), group " << g <<
"ignored!" << std::endl;
248 load( rrow, ccol, m, n, g );
254 void load( LI* row, LI* col, LI
m, LI
n, LI nb ) {
256 std::cerr <<
"Warning: _DEBUG flag set." << std::endl;
264 int prevrow = row[ 0 ];
265 for( LI i=1; i<this->
nnz; i++ ) {
266 if( row[ i ] != prevrow )
271 std::cout <<
jumps <<
" row jumps found." << std::endl;
274 c_inc =
new LI[ this->nnz + 1 ];
276 r_inc[ 0 ] = prevrow = row[ 0 ];
277 int prevcol =
c_inc[ 0 ] = col[ 0 ];
279 std::cout <<
"c_inc: " << prevcol << std::endl;
280 std::cout <<
"r_inc: " << prevrow << std::endl;
283 for( LI i=1; i<this->
nnz; i++ ) {
284 this->
c_inc[ i ] = col[ i ] - prevcol;
285 if( row[ i ] != prevrow ) {
287 this->
r_inc[ c++ ] = row[ i ] - prevrow;
289 std::cout <<
"c_inc: " <<
ntt << std::endl;
290 std::cout <<
"r_inc: " << row[ i ] - prevrow << std::endl;
296 std::cout <<
"c_inc: " << col[ i ] - prevcol << std::endl;
305 std::cout <<
"Construction done." << std::endl;
320 virtual void zxa(
const _t_value*__restrict__ x_p, _t_value*__restrict__ y_p ) {
321 const _t_value * y = y_p;
322 const _t_value * y_end = y+this->
noc;
323 LI *__restrict__ c_inc_p =
c_inc;
324 LI *__restrict__ r_inc_p =
r_inc;
327 const _t_value * x = x_p;
328 const _t_value *__restrict__ x_end = x+this->
nor;
329 const LI *__restrict__ c_inc_end =
c_inc+this->
nnz+1;
338 std::cout <<
"( " << xc <<
" , " << yc <<
" )" << std::endl;
340 for(
int i=1; i<this->
nnz; i++ ) {
342 if( yc > this->noc ) {
346 assert( yc < this->noc );
347 assert( xc < this->nor );
350 std::cout <<
"( " << yc <<
" , " << xc <<
" )" << std::endl;
355 while( v_p < v_end ) {
357 assert( y_p < y_end );
358 assert( v_p >=
vals );
359 assert( v_p < v_end );
361 assert( x_p < x_end );
362 assert( c_inc_p >=
c_inc );
363 assert( c_inc_p < c_inc_end );
364 assert( r_inc_p >=
r_inc );
365 while( y_p < y_end ) {
366 (*(v_p++))->zxa( x_p, y_p );
379 virtual void zax(
const _t_value*__restrict__ x_p, _t_value*__restrict__ y_p ) {
380 const _t_value * x_end = x_p+this->
noc;
381 LI *__restrict__ c_inc_p =
c_inc;
382 LI *__restrict__ r_inc_p =
r_inc;
384 const _t_value * x = x_p;
385 const _t_value *
const y = y_p;
386 const _t_value * y_end = y+this->
nor;
387 const LI *__restrict__ c_inc_end =
c_inc+this->
nnz+1;
397 std::cout <<
"( " << xc <<
" , " << yc <<
" )" << std::endl;
399 for(
int i=1; i<this->
nnz; i++ ) {
401 if( xc > this->noc ) {
405 assert( xc < this->nor );
406 assert( yc < this->noc );
409 std::cout <<
"( " << xc <<
" , " << yc <<
" )" << std::endl;
415 while( v_p < v_end ) {
417 assert( y_p < y_end );
418 assert( v_p >=
vals );
419 assert( v_p < v_end );
421 assert( x_p < x_end );
422 assert( c_inc_p >=
c_inc );
423 assert( c_inc_p < c_inc_end );
424 assert( r_inc_p >=
r_inc );
425 while( x_p < x_end ) {
426 (*(v_p++))->zax( x_p, y_p );
436 size_t ret =
sizeof( LI ) * ( this->
nnz +
jumps + 2 ) +
sizeof(
void* ) * this->
nnz;
438 for(
size_t i = 0; i < static_cast< size_t >(this->
nnz); ++i )
LI nnz
Number of non-zeros.
Definition: SparseMatrix.hpp:58
Automatically transforms a row-major scheme into an column-major scheme.
Definition: CCSWrapper.hpp:49
The incremental compressed row storage sparse matrix data structure.
Definition: ICRS.hpp:53
Bi-directional Incremental Compressed Row Storage scheme.
Definition: BICRS.hpp:58
~HBICRS()
Base deconstructor.
Definition: HBICRS.hpp:100
Hierarchical Bi-directional Incremental Compressed Row Storage scheme.
Definition: HBICRS.hpp:78
virtual unsigned long int m()
Queries the number of rows this matrix contains.
Definition: SparseMatrix.hpp:107
virtual void zax(const _t_value *__restrict__ x_p, _t_value *__restrict__ y_p)
Calculates y=Ax, but does not allocate y itself.
Definition: HBICRS.hpp:379
HBICRS(std::vector< std::vector< Triplet< _t_value > > > &input, signed char *group_type, LI m, LI n, _t_value zero=0)
Base constructor.
Definition: HBICRS.hpp:130
The compressed row storage sparse matrix data structure.
Definition: CRS.hpp:52
virtual void load(std::vector< Triplet< _t_value > > &input, LI m, LI n, _t_value zero)
This function will rewrite the std::vector< Triplet > structure to one suitable for the other load fu...
Definition: HBICRS.hpp:140
The triplet scheme; a storage scheme for sparse matrices using triplets.
Definition: TS.hpp:44
virtual void load(std::vector< std::vector< Triplet< _t_value > > > &input, signed char *group_type, LI m, LI n, _t_value zero)
Constructs the hierarchical part.
Definition: HBICRS.hpp:146
HBICRS(std::vector< Triplet< _t_value > > &input, LI m, LI n, _t_value zero)
Base constructor.
Definition: HBICRS.hpp:123
Matrix< _t_value > ** vals
Stores the values individual storage schemes.
Definition: HBICRS.hpp:92
Interface common to all sparse matrix storage schemes.
Definition: SparseMatrix.hpp:46
The zig-zag incremental compressed row storage sparse matrix data structure.
Definition: ZZ_ICRS.hpp:58
LI noc
Number of columns.
Definition: SparseMatrix.hpp:55
LI * r_inc
Stores the row jumps; size is at maximum the number of nonzeros.
Definition: HBICRS.hpp:86
The sparse vector matrix format.
Definition: SVM.hpp:51
LI nor
Number of rows.
Definition: SparseMatrix.hpp:52
virtual void zxa(const _t_value *__restrict__ x_p, _t_value *__restrict__ y_p)
Calculates y=xA, but does not allocate y itself.
Definition: HBICRS.hpp:320
_t_value 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
The Hilbert triplet scheme.
Definition: HTS.hpp:51
HBICRS()
Base constructor.
Definition: HBICRS.hpp:109
size_t jumps
The number of row jumps.
Definition: HBICRS.hpp:83
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
void load(LI *row, LI *col, LI m, LI n, LI nb)
Builds the BICRS structure.
Definition: HBICRS.hpp:254
HBICRS(std::string file, _t_value zero=0)
Base constructor.
Definition: HBICRS.hpp:115
virtual size_t bytesUsed()
Function to query the amount of storage required by this sparse matrix.
Definition: HBICRS.hpp:434
ULI ntt
Caches n times two.
Definition: HBICRS.hpp:95
LI * c_inc
Stores the column jumps; size is exactly the number of nonzeros.
Definition: HBICRS.hpp:89
virtual void getFirstIndexPair(LI &i, LI &j)
Definition: HBICRS.hpp:310