6#ifndef hSparseMatrix_hh
7#define hSparseMatrix_hh
13# define EPS DBL_EPSILON
16# define EPS std::numeric_limits<double>::epsilon()
46 typedef typename Cmplxtype<T>::type
c_type;
48 typedef typename std::conditional<std::is_same<typename Realtype<T>::type, T>::value ,
71 Value(
Value* l,
int i, T v = 0.0) { lnk = l; idx = i; val = v; }
72 void*
operator new(
size_t sz) {
return new char[sz]; }
75 return pool.alloc(); }
92 inline uint HashBits()
const {
return hashBits; }
109 template<
typename F,
typename G>
119 template<
typename F,
typename G>
124 float memory()
const {
129 void write(std::ostream&
ofs)
const;
130 void outputMatlab(std::ostream&
ofs)
const;
131 void outputSparseQR(std::ostream&
ofs)
const;
157 std::ostream& info(std::ostream&
os)
const;
204 template<
class F,
class G>
206 uint r = nofRows << hashBits;
209 for(
Value* v = matrix[r]; v !=
NULL; v = v->lnk)
210 g[v->idx] += v->val * f[r >> hashBits];
219 uint r = nofRows << hashBits;
222 for (
Value* v= matrix[r]; v != 0; v = v->lnk) {
223 for (
uint k = 0; k <
fact->nofCols; ++k) {
225 for (; w != 0 && w->idx != k; w = w->lnk);
227 T
sum = v->val * w->val;
243 uint r = nofRows << hashBits;
246 for (
Value* v= matrix[r]; v != 0; v = v->lnk) {
248 T
sum = v->val * (*fact)(v->idx,k);
257 template<
class F,
class G>
260 uint r = nofRows << hashBits;
263 for(
Value* v = matrix[r]; v !=
NULL; v = v->lnk)
264 sum += v->val * f[v->idx];
265 if (!(r & hashMsk)) {
266 g[r >> hashBits] =
sum;
uint used() const
Returns the number of used entries in the matrix.
T & operator()(const uint r, const uint c)
const uint cols() const
Number of columns.
Cmplxtype< T >::type c_type
Complex type of data type.
void multiply(const HashedSparseMatrix< T > *const fact, concepts::Matrix< T > &dest) const
Multiplies this matrix and fact and adds the result to dest.
iterator begin(uint row=0)
static iterator end()
Last entrance of the particular order.
void transpMult(const F f[], G g[]) const
const uint rows() const
Number of rows.
void operator()(const F f[], G g[]) const
Multiplies the matrix with f. The result is g.
Realtype< T >::type r_type
Real type of data type.
void multiply(const concepts::Matrix< T > *const fact, concepts::Matrix< T > &dest) const
Multiplies this matrix and fact and adds the result to dest.
std::conditional< std::is_same< typenameRealtype< T >::type, T >::value, typenameRealtype< T >::type, typenameCmplxtype< T >::type >::type d_type
Data type, depending if F is real or complex.
const_iterator begin(uint row=0) const
HashedSparseMatrix(uint r, uint c, uint h)
HashedSparseMatrix< T > & operator*=(const T factor)
Multiplies all entrices with a certain constant.
void compress(Real threshold=EPS)
#define conceptsAssert(cond, exc)
Set< F > makeSet(uint n, const F &first,...)
Value & operator*=(const T factor)
Mulitply value with a certain constant.
Value(Value *l, int i, T v=0.0)