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

#include <sparvec.h>

Inheritance diagram for ABA_SPARVEC:

ABA_ABACUSROOT ABA_COLUMN ABA_ROW List of all members.

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_SPARVECoperator= (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_GLOBALglob_
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.

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.


Constructor & Destructor Documentation

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.

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.

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.

Parameters:
rhs The sparse vector that is copied.

ABA_SPARVEC::~ABA_SPARVEC (  ) 

The destructor.


Member Function Documentation

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.

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.

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.

double ABA_SPARVEC::origCoeff ( int  i  )  const

Returns:
The coefficient having support i.
Parameters:
i The number of the original coefficient.

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.

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.

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.

void ABA_SPARVEC::clear (  )  [inline]

Removes all nonzeros from the sparse vector.

Definition at line 327 of file sparvec.h.

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.

int ABA_SPARVEC::size (  )  const [inline]

Returns:
The maximal length of the sparse vector.

Definition at line 332 of file sparvec.h.

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.

double ABA_SPARVEC::norm (  ) 

Returns:
The Euclidean norm of the sparse vector.

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.

Parameters:
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.

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


Friends And Related Function Documentation

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.


Member Data Documentation

ABA_GLOBAL* ABA_SPARVEC::glob_ [protected]

A pointer to the corresponding global object.

Definition at line 273 of file sparvec.h.

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.

int ABA_SPARVEC::nnz_ [protected]

The number of stored elements (``nonzeros'').

Definition at line 282 of file sparvec.h.

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.

int* ABA_SPARVEC::support_ [protected]

The array storing the nonzero variables.

Definition at line 292 of file sparvec.h.

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:
Generated on Tue Aug 14 18:09:59 2007 for ABACUS by  doxygen 1.5.1