IBSimu 1.0.4
Classes | Public Member Functions | Friends
Vector Class Reference

Dense math vector class. More...

#include <mvector.hpp>

List of all members.

Classes

struct  VectorLA
 Container object for linear algebra operations. More...
struct  VectorRef
 Container object for coefficient-vector pairs. More...

Public Member Functions

 Vector ()
 Default constructor.
 Vector (int n)
 Constructor with set dimensionality.
 Vector (int n, const double *val)
 Constructor with preset dimensionality and coordinate values.
 Vector (int n, double val)
 Constructor with preset dimensionality and a value for all coordinates.
 Vector (const Vector &vec)
 Copy constructor.
 Vector (const VectorLA &vecla)
 Constructor for setting vector to the result of linear algebra.
 Vector (const struct MatrixMulVec &matvec)
 Constructor for setting vector to the result of matrix multiplication.
 ~Vector ()
 Destructor for vectors.
int size (void) const
 Returns the size of vector.
void resize (int n)
 Resizes a vector.
void clear (void)
 Clears the vector.
void merge (Vector &vec)
 Merges vector vec into the vector leaving vec empty.
double * get_data (void)
 Returns a pointer to the coordinate value data of the vector.
const double * get_data (void) const
 Returns a const pointer to the coordinate value data of the vector.
VectorLA operator+ (const VectorLA &vecla) const
 Operator for adding vectors.
VectorLA operator- (const VectorLA &vecla) const
 Operator for subtracting vectors.
VectorLA operator- () const
 Operator for unary minus.
VectorLA operator* (double x) const
 Operator for multiplying vector with a constant.
Vectoroperator+= (const VectorLA &vecla)
 Operator for adding vectors.
Vectoroperator-= (const VectorLA &vecla)
 Operator for subtracting vectors.
Vectoroperator*= (double x)
 Operator for multiplying vector with a constant.
Vectoroperator= (double x)
 Operator for setting all vector elements to value x.
Vectoroperator= (const Vector &vec)
 Operator for making vector a copy of another vector.
Vectoroperator= (const VectorLA &vecla)
 Operator for setting vector to the result of linear algebra.
Vectoroperator= (const struct MatrixMulVec &matvec)
 Operator for setting vector to the result of matrix multiplication.
bool operator== (const Vector &vec) const
 Operator for comparing vectors.
bool operator!= (const Vector &vec) const
 Operator for comparing vectors.
double & operator[] (int i)
 Operator for pointing to vector elements.
double & operator() (int i)
 Operator for pointing to vector elements.
double operator[] (int i) const
 Operator for pointing to vector elements.
double operator() (int i) const
 Operator for pointing to vector elements.

Friends

class HBIO
class Matrix
class CRowMatrix
class CColMatrix
class CoordMatrix
VectorLA operator* (double x, Vector &vec)
 Operator for multiplying vector with a constant.
std::ostream & operator<< (std::ostream &os, const Vector &vec)
 Operator for printing a vector.
double dot_prod (const Vector &vec1, const Vector &vec2)
 Returns dot product of vector vec1 and vector vec2.
double norm1 (const Vector &vec)
 Returns 1-norm of vector.
double norm2 (const Vector &vec)
 Returns 2-norm of vector.
double ssqr (const Vector &vec)
 Returns square of 2-norm of vector.
double min (const Vector &vec)
 Returns the minimum vector element value.
double min_abs (const Vector &vec)
 Returns the minimum vector element absolute value.
double max (const Vector &vec)
 Returns the maximum vector element value.
double max_abs (const Vector &vec)
 Returns the maximum vector element absolute value.
void swap (Vector &vec1, Vector &vec2)
 Swaps contents of vector vec1 and vector vec2.

Detailed Description

Dense math vector class.

Vector is intended to be used for mathematical vectors with large number of dimensions (n>20). Basic algebra operations are defined for these vectors, including addition, subtraction, scaling, different norms and dot product.

The Vector class does linear algebra operations using VectorLA container object to build and store a list of coefficients and vectors. VectorLA is used to construct "formulas" from the vector addition (and subtraction) and multiplication operations. These formulas are stored without calculating them until a destination of the result of the operation is known. This is is done to avoid excess copying and use of temporary variables during calculation.


Constructor & Destructor Documentation

Vector::Vector ( ) [inline]

Default constructor.

Returns an empty vector with 0 dimensions.

Vector::Vector ( int  n)

Constructor with set dimensionality.

Returns a zero vector with nn dimensions.

Parameters:
nNumber of dimensions.
Vector::Vector ( int  n,
const double *  val 
)

Constructor with preset dimensionality and coordinate values.

Returns a vector with n dimensions and coordinate values copied from array val.

Parameters:
nNumber of dimensions.
valArray of coordinate values.
Vector::Vector ( int  n,
double  val 
)

Constructor with preset dimensionality and a value for all coordinates.

Returns a vector with n dimensions and all coordinate values set to val.

Parameters:
nNumber of dimensions.
valNumber for coordinate values.
Vector::Vector ( const Vector vec)

Copy constructor.

Returns a copy of vector vec.

Parameters:
vecVector to copy from.
Vector::Vector ( const VectorLA vecla)

Constructor for setting vector to the result of linear algebra.

Vector::Vector ( const struct MatrixMulVec matvec)

Constructor for setting vector to the result of matrix multiplication.

Vector::~Vector ( )

Destructor for vectors.


Member Function Documentation

void Vector::clear ( void  )

Clears the vector.

Logically the same as doing

 X = 0 

but clear() is probably faster.

double* Vector::get_data ( void  ) [inline]

Returns a pointer to the coordinate value data of the vector.

The data is stored in a linear double array, which starts from the first coordinate and ends to the last one. A non-const pointer to the first element of the array is returned.

const double* Vector::get_data ( void  ) const [inline]

Returns a const pointer to the coordinate value data of the vector.

void Vector::merge ( Vector vec)

Merges vector vec into the vector leaving vec empty.

Copies contents of vector vec into the vector and sets contents of vector vec to n = 0 and val = NULL.

Parameters:
vecVector to copy from.
bool Vector::operator!= ( const Vector vec) const

Operator for comparing vectors.

This operator should not be used for general comparison in applications because of the nature of floating point numbers. For testing the inequality of vectors A and B you should do

 max_abs(A - B) > eps 

where eps is a small number.

double & Vector::operator() ( int  i) [inline]

Operator for pointing to vector elements.

Range checking is done for i if SPM_RANGE_CHECK is defined. Throws ErrorRange exception on range checking errors.

double Vector::operator() ( int  i) const [inline]

Operator for pointing to vector elements.

Range checking is done for i if SPM_RANGE_CHECK is defined. Throws ErrorRange exception on range checking errors.

VectorLA Vector::operator* ( double  x) const

Operator for multiplying vector with a constant.

Vector& Vector::operator*= ( double  x)

Operator for multiplying vector with a constant.

VectorLA Vector::operator+ ( const VectorLA vecla) const

Operator for adding vectors.

Vector& Vector::operator+= ( const VectorLA vecla)

Operator for adding vectors.

VectorLA Vector::operator- ( const VectorLA vecla) const

Operator for subtracting vectors.

VectorLA Vector::operator- ( ) const

Operator for unary minus.

Vector& Vector::operator-= ( const VectorLA vecla)

Operator for subtracting vectors.

Vector& Vector::operator= ( const VectorLA vecla)

Operator for setting vector to the result of linear algebra.

Vector& Vector::operator= ( const struct MatrixMulVec matvec)

Operator for setting vector to the result of matrix multiplication.

Vector& Vector::operator= ( const Vector vec)

Operator for making vector a copy of another vector.

Vector& Vector::operator= ( double  x)

Operator for setting all vector elements to value x.

bool Vector::operator== ( const Vector vec) const

Operator for comparing vectors.

This operator should not be used for general comparison in applications because of the nature of floating point numbers. For testing the equality of vectors A and B you should do

 max_abs(A - B) < eps 

where eps is a small number.

double Vector::operator[] ( int  i) const [inline]

Operator for pointing to vector elements.

Range checking is done for i if SPM_RANGE_CHECK is defined. Throws ErrorRange exception on range checking errors.

double & Vector::operator[] ( int  i) [inline]

Operator for pointing to vector elements.

Range checking is done for i if SPM_RANGE_CHECK is defined. Throws ErrorRange exception on range checking errors.

void Vector::resize ( int  n)

Resizes a vector.

Resizes a vector to n dimensions. Contents of vector data are preserved for where ever it is possible. Newly allocated areas have uninitialized content.

Parameters:
nNumber of dimensions for resized vector.
int Vector::size ( void  ) const [inline]

Returns the size of vector.


Friends And Related Function Documentation

friend class CColMatrix [friend]
friend class CoordMatrix [friend]
friend class CRowMatrix [friend]
double dot_prod ( const Vector vec1,
const Vector vec2 
) [friend]

Returns dot product of vector vec1 and vector vec2.

friend class HBIO [friend]
friend class Matrix [friend]
double max ( const Vector vec) [friend]

Returns the maximum vector element value.

double max_abs ( const Vector vec) [friend]

Returns the maximum vector element absolute value.

double min ( const Vector vec) [friend]

Returns the minimum vector element value.

double min_abs ( const Vector vec) [friend]

Returns the minimum vector element absolute value.

double norm1 ( const Vector vec) [friend]

Returns 1-norm of vector.

$ ||x||_1 = \Sigma_{i=1}^n |x_i| $

double norm2 ( const Vector vec) [friend]

Returns 2-norm of vector.

$ ||x||_2 = \sqrt{ \Sigma_{i=1}^n x_i^2 } $

VectorLA operator* ( double  x,
Vector vec 
) [friend]

Operator for multiplying vector with a constant.

std::ostream& operator<< ( std::ostream &  os,
const Vector vec 
) [friend]

Operator for printing a vector.

double ssqr ( const Vector vec) [friend]

Returns square of 2-norm of vector.

$ (||x||_2)^2 = \Sigma_{i=1}^n x_i^2 $

void swap ( Vector vec1,
Vector vec2 
) [friend]

Swaps contents of vector vec1 and vector vec2.


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