34 #ifndef _H_COMPRESSED_HILBERT
35 #define _H_COMPRESSED_HILBERT
39 #include "Triplet.hpp"
40 #include "SparseMatrix.hpp"
41 #include "custom_quicksort.hpp"
42 #include "HilbertArray.hpp"
51 template<
typename T >
85 load( input, m, n, zero );
89 virtual void load( std::vector<
Triplet< T > >& input,
const ULI
m,
const ULI
n,
const T zero ) {
93 this->
nnz = input.size();
96 std::vector< BigInt > hilbert_values;
97 typename std::vector< Triplet< T > >::const_iterator it;
99 for( it = input.begin(); it != input.end(); ++it ) {
101 hilbert_values.push_back(
BigInt( h1, h2 ) );
105 custom_quicksort< BigInt, Triplet< T > >( hilbert_values, input, 0, input.size() );
108 std::vector< BigInt >::iterator b_it1 = hilbert_values.begin();
109 std::vector< BigInt >::iterator b_it2 = hilbert_values.begin() + 1;
110 for( ; b_it2 != hilbert_values.end(); ++b_it1, ++b_it2 ) {
111 assert( *b_it1 < *b_it2 );
115 indices = getDiffArray< T >( hilbert_values,
m,
n );
120 for( it = input.begin(); it != input.end(); ++it )
121 values[ c++ ] = it->value;
128 row =
static_cast< ULI
>(
indices->getFirstRowIndex() );
129 col =
static_cast< ULI
>(
indices->getFirstColumnIndex() );
138 virtual void zxa(
const T* x, T* z ) {
143 const T *
const val_end =
values + this->
nnz;
144 const T *__restrict__ p_v =
values;
146 indices->zxa( x, z, p_v, val_end );
155 virtual void zax(
const T* x, T* z ) {
160 const T *
const val_end =
values + this->
nnz;
161 const T *__restrict__ p_v =
values;
163 indices->zax( x, z, p_v, val_end );
ULI nnz
Number of non-zeros.
Definition: SparseMatrix.hpp:58
A Hilbert scheme backed by a specialised storage format.
Definition: CompressedHilbert.hpp:52
virtual void getFirstIndexPair(ULI &row, ULI &col)
Returns the first nonzero index, per reference.
Definition: CompressedHilbert.hpp:127
CompressedHilbert(std::vector< Triplet< T > > &input, const ULI m, const ULI n, const T zero=0)
Base constructor initialising from direct input.
Definition: CompressedHilbert.hpp:84
virtual void zxa(const T *x, T *z)
Calculates z=xA.
Definition: CompressedHilbert.hpp:138
CompressedHilbert(std::string file, T zero=0)
Base constructor initialising from file.
Definition: CompressedHilbert.hpp:79
Class providing an interface to an efficient storage of a 1D array of Hilbert coordinate increments...
Definition: HilbertArray.hpp:49
A 128-bit integer, with overloaded comparison operators.
Definition: BigInt.hpp:38
virtual unsigned long int m()
Queries the number of rows this matrix contains.
Definition: SparseMatrix.hpp:107
static void IntegerToHilbert(const size_t i, const size_t j, size_t &h1, size_t &h2)
New method, October 2010.
Definition: Matrix2HilbertCoordinates.cpp:48
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
virtual size_t bytesUsed()
Definition: CompressedHilbert.hpp:180
ULI noc
Number of columns.
Definition: SparseMatrix.hpp:55
HilbertArrayInterface< T > * indices
Pointer to indices in Hilbert-coordinate form.
Definition: CompressedHilbert.hpp:62
ULI nor
Number of rows.
Definition: SparseMatrix.hpp:52
virtual ~CompressedHilbert()
Base deconstructor.
Definition: CompressedHilbert.hpp:67
T zero_element
The element considered to be zero.
Definition: SparseMatrix.hpp:63
T * values
Array of nonzero values.
Definition: CompressedHilbert.hpp:59
virtual void load(std::vector< Triplet< T > > &input, const ULI m, const ULI n, const T zero)
Definition: CompressedHilbert.hpp:89
CompressedHilbert()
Base constructor.
Definition: CompressedHilbert.hpp:73
virtual unsigned long int n()
Queries the number of columns this matrix contains.
Definition: SparseMatrix.hpp:115
virtual void zax(const T *x, T *z)
Calculates z=Ax.
Definition: CompressedHilbert.hpp:155
A single triplet value.
Definition: Triplet.hpp:52