#include <sparvec.h>
Inheritance diagram for ABA_SPARVEC:
Public Member Functions | |
ABA_SPARVEC (ABA_GLOBAL *glob, int size, double reallocFac=10.0) | |
ABA_SPARVEC (ABA_GLOBAL *glob, int size, const ABA_ARRAY< int > &s, const ABA_ARRAY< double > &c, double reallocFac=10.0) | |
A constructor with initialization of the support and coefficients of the sparse vector. | |
ABA_SPARVEC (ABA_GLOBAL *glob, int size, int *s, double *c, double reallocFac=10.0) | |
This constructor is equivalent to the previous one except that it is using C-style arrays for the initialization of the sparse vector. | |
ABA_SPARVEC (const ABA_SPARVEC &rhs) | |
~ABA_SPARVEC () | |
The destructor. | |
const ABA_SPARVEC & | operator= (const ABA_SPARVEC &rhs) |
The assignment operator requires that the left hand and the right hand side have the same length (otherwise use the function copy()). | |
int | support (int i) const |
A range check is performed if the function is compiled with -DABACUSSAFE. | |
double | coeff (int i) const |
A range check is performed if the function is compiled with -DABACUSSAFE. | |
double | origCoeff (int i) const |
void | insert (int s, double c) |
void | leftShift (ABA_BUFFER< int > &del) |
void | copy (const ABA_SPARVEC &vec) |
Is very similar to the assignment operator, yet the size of the two vectors need not be equal and only the support, the coefficients, and the number of nonzeros is copied. A reallocation is performed if required. | |
void | clear () |
void | rename (ABA_ARRAY< int > &newName) |
int | size () const |
int | nnz () const |
double | norm () |
void | realloc () |
void | realloc (int newSize) |
This other version of realloc() reallocates the sparse vector to a given length. | |
Protected Member Functions | |
void | rangeCheck (int i) const |
Terminates the program with an error message if i is negative or greater or equal than the number of nonzero elements. | |
Protected Attributes | |
ABA_GLOBAL * | glob_ |
int | size_ |
The maximal number of nonzero coefficients which can be stored without reallocation. | |
int | nnz_ |
double | reallocFac_ |
If a new element is inserted but the sparse vector is full, then its size is increased by reallocFac_ percent. | |
int * | support_ |
double * | coeff_ |
Friends | |
ostream & | operator<< (ostream &out, const ABA_SPARVEC &rhs) |
The output operator writes the elements of the support and their coefficients line by line on an output stream. |
Definition at line 50 of file sparvec.h.
ABA_SPARVEC::ABA_SPARVEC | ( | ABA_GLOBAL * | glob, | |
int | size, | |||
double | reallocFac = 10.0 | |||
) |
The constructor for an empty sparse vector.
glob | A pointer to the corresponding global object. | |
size | The maximal number of nonzeros of the sparse vector (without reallocation). | |
reallocFac | The reallocation factor (in percent of the original size), which is used in a default reallocation if a variable is inserted when the sparse vector is already full. Its default value is 10. |
ABA_SPARVEC::ABA_SPARVEC | ( | ABA_GLOBAL * | glob, | |
int | size, | |||
const ABA_ARRAY< int > & | s, | |||
const ABA_ARRAY< double > & | c, | |||
double | reallocFac = 10.0 | |||
) |
A constructor with initialization of the support and coefficients of the sparse vector.
The minimum value of size and s.size is the number of nonzeros of the sparse vector.
glob | A pointer to the corresponding global object. | |
size | The maximal number of nonzeros (without reallocation). | |
s | An array storing the support of the sparse vector, i.e., the elements for which a (normally nonzero) coefficient is given in c. | |
c | An array storing the coefficients of the support elements given in s. This array must have at least the length of the minimum of size and s.size(). | |
reallocFac | The reallocation factor (in percent of the original size), which is used in a default reallocation if a variable is inserted when the sparse vector is already full. Its default value is 10. |
ABA_SPARVEC::ABA_SPARVEC | ( | ABA_GLOBAL * | glob, | |
int | size, | |||
int * | s, | |||
double * | c, | |||
double | reallocFac = 10.0 | |||
) |
This constructor is equivalent to the previous one except that it is using C-style arrays for the initialization of the sparse vector.
ABA_SPARVEC::ABA_SPARVEC | ( | const ABA_SPARVEC & | rhs | ) |
The copy constructor.
rhs | The sparse vector that is copied. |
ABA_SPARVEC::~ABA_SPARVEC | ( | ) |
The destructor.
const ABA_SPARVEC& ABA_SPARVEC::operator= | ( | const ABA_SPARVEC & | rhs | ) |
The assignment operator requires that the left hand and the right hand side have the same length (otherwise use the function copy()).
rhs | The right hand side of the assignment. |
int ABA_SPARVEC::support | ( | int | i | ) | const [inline] |
double ABA_SPARVEC::coeff | ( | int | i | ) | const [inline] |
double ABA_SPARVEC::origCoeff | ( | int | i | ) | const |
i | The number of the original coefficient. |
void ABA_SPARVEC::insert | ( | int | s, | |
double | c | |||
) | [inline] |
void ABA_SPARVEC::leftShift | ( | ABA_BUFFER< int > & | del | ) |
Deletes the elements listed in a buffer from the sparse vector.
The numbers of indices in this buffer must be upward sorted. The elements before the first element in the buffer are unchanged. Then the elements which are not deleted are shifted left in the arrays.
del | The numbers of the elements removed from the sparse vector. |
void ABA_SPARVEC::copy | ( | const ABA_SPARVEC & | vec | ) |
Is very similar to the assignment operator, yet the size of the two vectors need not be equal and only the support, the coefficients, and the number of nonzeros is copied. A reallocation is performed if required.
vec | The sparse vector that is copied. |
void ABA_SPARVEC::clear | ( | ) | [inline] |
void ABA_SPARVEC::rename | ( | ABA_ARRAY< int > & | newName | ) |
Replaces the index of the support by new names.
newName | The new names (support) of the elements of the sparse vector. The array newName must have at least a length equal to the maximal element in the support of the sparse vector. |
int ABA_SPARVEC::size | ( | ) | const [inline] |
int ABA_SPARVEC::nnz | ( | ) | const [inline] |
double ABA_SPARVEC::norm | ( | ) |
void ABA_SPARVEC::realloc | ( | ) |
Increases the size of the sparse vector by reallocFac_ percent of the original size.
This function is called if an automatic reallocation takes place.
void ABA_SPARVEC::realloc | ( | int | newSize | ) |
This other version of realloc() reallocates the sparse vector to a given length.
It is an error to decrease size below the current number of nonzeros.
newSize | The new maximal number of nonzeroes that can be stored in the sparse vector. |
void ABA_SPARVEC::rangeCheck | ( | int | i | ) | const [protected] |
Terminates the program with an error message if i is negative or greater or equal than the number of nonzero elements.
If the class ABA_SPARVEC is compiled with the flag -DABACUSSAFE, then before each access operation on element i of the sparse vector the function rangeCheck() is called.
i | An integer that should be checked if it is in the range of the sparse vector. |
ostream& operator<< | ( | ostream & | out, | |
const ABA_SPARVEC & | rhs | |||
) | [friend] |
The output operator writes the elements of the support and their coefficients line by line on an output stream.
out | The output stream. | |
rhs | The sparse vector being output. |
ABA_GLOBAL* ABA_SPARVEC::glob_ [protected] |
int ABA_SPARVEC::size_ [protected] |
int ABA_SPARVEC::nnz_ [protected] |
double ABA_SPARVEC::reallocFac_ [protected] |
int* ABA_SPARVEC::support_ [protected] |
double* ABA_SPARVEC::coeff_ [protected] |