Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
sparvec.h
Go to the documentation of this file.
1
30#pragma once
31
33
34namespace abacus {
35
36
38
47class SparVec : public AbacusRoot {
48public:
49
51
62 int size,
63 double reallocFac = 10.0);
64
66
86 int size,
87 const Array<int> &s,
88 const Array<double> &c,
89 double reallocFac = 10.0);
90
92
110 int size,
111 int *s,
112 double *c,
113 double reallocFac = 10.0);
114
116
119 SparVec(const SparVec& rhs);
120
123
125
134
136
144 friend std::ostream& operator<<(std::ostream& out, const SparVec& rhs);
145
151 int support(int i) const {
152#ifdef OGDF_DEBUG
153 rangeCheck(i);
154#endif
155 return support_[i];
156 }
157
163 double coeff(int i) const {
164#ifdef OGDF_DEBUG
165 rangeCheck(i);
166#endif
167 return coeff_[i];
168 }
169
175 double origCoeff(int i) const;
176
178
184 void insert(int s, double c) {
185 if (nnz_ == size_) realloc();
186
187 support_[nnz_] = s;
188 coeff_[nnz_] = c;
189 ++nnz_;
190 }
191
193
201
203
210 void copy (const SparVec &vec);
211
213 void clear() { nnz_ = 0; }
214
216
222
224 int size() const { return size_; }
225
227
232 int nnz() const { return nnz_; }
233
235 double norm();
236
238 /***
239 * This function is called if an automatic reallocation takes place.
240 */
241 void realloc();
242
244
249 void realloc(int newSize);
250
251protected:
252
254
264 void rangeCheck(int i) const;
265
268
270 int size_;
271
273 int nnz_;
274
278
281
283 double *coeff_;
284};
285
286}
Global data and functions.
Definition global.h:57
Base class of all other classes of ABACUS.
Definition abacusroot.h:68
Sparse vectors.
Definition sparvec.h:47
AbacusGlobal * glob_
A pointer to the corresponding global object.
Definition sparvec.h:267
SparVec(AbacusGlobal *glob, int size, int *s, double *c, double reallocFac=10.0)
Creates a sparse vector and initializes support and coefficients.
void clear()
Removes all nonzeros from the sparse vector.
Definition sparvec.h:213
int size() const
Returns the maximal length of the sparse vector.
Definition sparvec.h:224
double origCoeff(int i) const
void copy(const SparVec &vec)
Copies vector vec.
void leftShift(ArrayBuffer< int > &del)
Deletes the elements listed in a buffer from the sparse vector.
int size_
The maximal number of nonzero coefficients which can be stored without reallocation.
Definition sparvec.h:270
int nnz_
The number of stored elements ("nonzeros").
Definition sparvec.h:273
int support(int i) const
Definition sparvec.h:151
void realloc(int newSize)
Reallocates the sparse vector to a given length.
double coeff(int i) const
Definition sparvec.h:163
void rangeCheck(int i) const
Checks whether i is a valid index.
int * support_
The array storing the nonzero variables.
Definition sparvec.h:280
void insert(int s, double c)
Adds a new support/coefficient pair to the vector.
Definition sparvec.h:184
void rename(Array< int > &newName)
Replaces the index of the support by new names.
int nnz() const
Returns the number of nonzero elements.
Definition sparvec.h:232
SparVec(AbacusGlobal *glob, int size, const Array< int > &s, const Array< double > &c, double reallocFac=10.0)
Creates a sparse vector and initializes support and coefficients.
~SparVec()
The destructor.
SparVec(AbacusGlobal *glob, int size, double reallocFac=10.0)
Creates an empty sparse vector.
SparVec & operator=(const SparVec &rhs)
The assignment operator.
void realloc()
Increases the size of the sparse vector by reallocFac_ percent of the original size.
double norm()
Returns the Euclidean norm of the sparse vector.
double * coeff_
The array storing the corresponding nonzero coefficients.
Definition sparvec.h:283
friend std::ostream & operator<<(std::ostream &out, const SparVec &rhs)
The output operator.
SparVec(const SparVec &rhs)
Copy constructor.
double reallocFac_
If a new element is inserted but the sparse vector is full, then its size is increased by reallocFac_...
Definition sparvec.h:277
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:56
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
global.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()