6.49 ABA_SPARVEC Class Reference

Since other classes, e.g., the class ABA_RO are derived from this class, all data members are protected in order to provide efficient access also in these derived classes.

#include <sparvec.h>

Inheritance diagram for ABA_SPARVEC::


PIC


Public Member Functions

Protected Member Functions

Protected Attributes

Friends

6.49.1 Detailed Description

Since other classes, e.g., the class ABA_RO are derived from this class, all data members are protected in order to provide efficient access also in these derived classes.

Definition at line 50 of file sparvec.h.

6.49.2 Constructor & Destructor Documentation

6.49.2.1 ABA_SPARVEC::ABA_SPARVEC (ABA_GLOBAL * glob, int size, double reallocFac = 10.0)

The constructor for an empty sparse vector.

Parameters:

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.

If no memory for support_ and coeff_ is allocated then an automatic allocation will be performed when the function insert() is called the first time.

6.49.2.2 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.

Parameters:

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.

If size is 0, then also no elements are copied in the for-loop since nnz_ will be also 0.

6.49.2.3 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.

6.49.2.4 ABA_SPARVEC::ABA_SPARVEC (const ABA_SPARVEC & rhs)

The copy constructor.

Parameters:

rhs
The sparse vector that is copied.

6.49.2.5 ABA_SPARVEC::~ABA_SPARVEC ()

The destructor.

6.49.3 Member Function Documentation

6.49.3.1 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()).

Returns:

A reference to the left hand side.

Parameters:

rhs
The right hand side of the assignment.

6.49.3.2 int ABA_SPARVEC::support (int i) const [inline]

A range check is performed if the function is compiled with -DABACUSSAFE.

Returns:

The support of the i-th nonzero element.

Parameters:

i
The number of the nonzero element.

Definition at line 300 of file sparvec.h.

6.49.3.3 double ABA_SPARVEC::coeff (int i) const [inline]

A range check is performed if the function is compiled with -DABACUSSAFE.

Returns:

The coefficient of the i-th nonzero element.

Parameters:

i
The number of the nonzero element.

Definition at line 308 of file sparvec.h.

6.49.3.4 double ABA_SPARVEC::origCoeff (int i) const

Returns:

The coefficient having support i.

Parameters:

i
The number of the original coefficient.

6.49.3.5 void ABA_SPARVEC::insert (int s, double c) [inline]

Adds a new support/coefficient pair to the vector.

If necessary a reallocation of the member data is performed automatically.

Parameters:

s
The new support.
c
The new coefficient.

Definition at line 316 of file sparvec.h.

6.49.3.6 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.

Parameters:

del
The numbers of the elements removed from the sparse vector.

6.49.3.7 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.

Parameters:

vec
The sparse vector that is copied.

6.49.3.8 void ABA_SPARVEC::clear () [inline]

Removes all nonzeros from the sparse vector.

Definition at line 327 of file sparvec.h.

6.49.3.9 void ABA_SPARVEC::rename (ABA_ARRAY< int > & newName)

Replaces the index of the support by new names.

Parameters:

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.

6.49.3.10 int ABA_SPARVEC::size () const [inline]

Returns:

The maximal length of the sparse vector.

Definition at line 332 of file sparvec.h.

6.49.3.11 int ABA_SPARVEC::nnz () const [inline]

Returns:

The number of nonzero elements. This is not necessarily the correct number of nonzeros, yet the number of coefficient/support pairs, which are stored. Some of these pairs may have a zero coefficient.

Definition at line 337 of file sparvec.h.

6.49.3.12 double ABA_SPARVEC::norm ()

Returns:

The Euclidean norm of the sparse vector.

6.49.3.13 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.

6.49.3.14 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.

Parameters:

newSize
The new maximal number of nonzeroes that can be stored in the sparse vector.

6.49.3.15 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.

Parameters:

i
An integer that should be checked if it is in the range of the sparse vector.

6.49.4 Friends And Related Function Documentation

6.49.4.1 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.

Returns:

A reference to the output stream.

Parameters:

out
The output stream.
rhs
The sparse vector being output.

6.49.5 Member Data Documentation

6.49.5.1 ABA_GLOBAL*ABA_SPARVEC::glob_ [protected]

A pointer to the corresponding global object.

Definition at line 273 of file sparvec.h.

6.49.5.2 int ABA_SPARVEC::size_ [protected]

The maximal number of nonzero coefficients which can be stored without reallocation.

Definition at line 278 of file sparvec.h.

6.49.5.3 int ABA_SPARVEC::nnz_ [protected]

The number of stored elements (“nonzeros”).

Definition at line 282 of file sparvec.h.

6.49.5.4 double ABA_SPARVEC::reallocFac_ [protected]

If a new element is inserted but the sparse vector is full, then its size is increased by reallocFac_ percent.

Definition at line 288 of file sparvec.h.

6.49.5.5 int*ABA_SPARVEC::support_ [protected]

The array storing the nonzero variables.

Definition at line 292 of file sparvec.h.

6.49.5.6 double*ABA_SPARVEC::coeff_ [protected]

The array storing the corresponding nonzero coefficients.

Definition at line 296 of file sparvec.h.

The documentation for this class was generated from the following file: