Dense math vector class. More...
#include <mvector.hpp>
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. | |
Vector & | operator+= (const VectorLA &vecla) |
Operator for adding vectors. | |
Vector & | operator-= (const VectorLA &vecla) |
Operator for subtracting vectors. | |
Vector & | operator*= (double x) |
Operator for multiplying vector with a constant. | |
Vector & | operator= (double x) |
Operator for setting all vector elements to value x. | |
Vector & | operator= (const Vector &vec) |
Operator for making vector a copy of another vector. | |
Vector & | operator= (const VectorLA &vecla) |
Operator for setting vector to the result of linear algebra. | |
Vector & | operator= (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. |
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.
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.
n | Number 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.
n | Number of dimensions. |
val | Array 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.
n | Number of dimensions. |
val | Number for coordinate values. |
Vector::Vector | ( | const Vector & | vec | ) |
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.
void Vector::clear | ( | void | ) |
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.
vec | Vector 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 |
Operator for unary minus.
Vector& Vector::operator= | ( | double | x | ) |
Operator for setting all vector elements to value x.
Operator for making vector a copy of another vector.
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.
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 | ) | [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.
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.
n | Number of dimensions for resized vector. |
int Vector::size | ( | void | ) | const [inline] |
Returns the size of vector.
friend class CColMatrix [friend] |
friend class CoordMatrix [friend] |
friend class CRowMatrix [friend] |
Returns dot product of vector vec1 and vector vec2.
friend class HBIO [friend] |
friend class Matrix [friend] |
Operator for multiplying vector with a constant.
std::ostream& operator<< | ( | std::ostream & | os, |
const Vector & | vec | ||
) | [friend] |
Operator for printing a vector.