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
34#pragma GCC visibility push(default)
35namespace abacus {
36
37
39
48class SparVec : public AbacusRoot {
49public:
50
52
63 int size,
64 double reallocFac = 10.0);
65
67
87 int size,
88 const Array<int> &s,
89 const Array<double> &c,
90 double reallocFac = 10.0);
91
93
111 int size,
112 int *s,
113 double *c,
114 double reallocFac = 10.0);
115
117
120 SparVec(const SparVec& rhs);
121
124
126
135
137
145 friend std::ostream& operator<<(std::ostream& out, const SparVec& rhs);
146
152 int support(int i) const {
153#ifdef OGDF_DEBUG
154 rangeCheck(i);
155#endif
156 return support_[i];
157 }
158
164 double coeff(int i) const {
165#ifdef OGDF_DEBUG
166 rangeCheck(i);
167#endif
168 return coeff_[i];
169 }
170
176 double origCoeff(int i) const;
177
179
185 void insert(int s, double c) {
186 if (nnz_ == size_) realloc();
187
188 support_[nnz_] = s;
189 coeff_[nnz_] = c;
190 ++nnz_;
191 }
192
194
202
204
211 void copy (const SparVec &vec);
212
214 void clear() { nnz_ = 0; }
215
217
222 void rename(Array<int> &newName);
223
225 int size() const { return size_; }
226
228
233 int nnz() const { return nnz_; }
234
236 double norm();
237
239 /***
240 * This function is called if an automatic reallocation takes place.
241 */
242 void realloc();
243
245
250 void realloc(int newSize);
251
252protected:
253
255
265 void rangeCheck(int i) const;
266
269
271 int size_;
272
274 int nnz_;
275
279
282
284 double *coeff_;
285};
286
287}
288#pragma GCC visibility pop
Global data and functions.
Definition global.h:58
Base class of all other classes of ABACUS.
Definition abacusroot.h:69
Sparse vectors.
Definition sparvec.h:48
AbacusGlobal * glob_
A pointer to the corresponding global object.
Definition sparvec.h:268
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:214
int size() const
Returns the maximal length of the sparse vector.
Definition sparvec.h:225
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:271
int nnz_
The number of stored elements ("nonzeros").
Definition sparvec.h:274
int support(int i) const
Definition sparvec.h:152
void realloc(int newSize)
Reallocates the sparse vector to a given length.
double coeff(int i) const
Definition sparvec.h:164
void rangeCheck(int i) const
Checks whether i is a valid index.
int * support_
The array storing the nonzero variables.
Definition sparvec.h:281
void insert(int s, double c)
Adds a new support/coefficient pair to the vector.
Definition sparvec.h:185
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:233
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:284
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:278
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:64
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
global.