Stores a dense vector. More...
#include <Morpheus_Vector.h>
Public Member Functions | |
Constructors and destructors | |
Vector (const int numElements) | |
Constructor. | |
~Vector () | |
Destructor. | |
Accessor functions | |
double & | operator[] (const int subscript) |
Subscript operator. | |
const double & | operator[] (const int subscript) const |
Const subscript operator. | |
int | getNumElements () const |
Returns the total number of entries. | |
Linear algebra functions | |
void | setValue (const double alpha=0) |
Initializes all entries to alpha. | |
void | scale (const double alpha) |
Scales the vector. | |
void | add (const Vector &b, Vector &sum) const |
Vector addition | |
double | dot (const Vector &b) const |
Dot product. | |
Norms | |
double | norm1 () const |
Sum of all entries. | |
double | normInf () const |
Maximum magnitude entry. | |
double | norm2 () const |
Length of vector. | |
I/O functions | |
void | print () const |
Prints vector to console. | |
Private Attributes | |
int | numElements_ |
Number of elements in the vector. | |
double * | data_ |
Pointer to raw data. |
Stores a dense vector.
Morpheus_Vector_addScaleTest.cpp, and Morpheus_Vector_normTest.cpp.
Definition at line 30 of file Morpheus_Vector.h.
Morpheus::Vector::Vector | ( | const int | numElements | ) |
Constructor.
Allocates memory for a Vector. If numElements is not positive, the program terminates.
[in] | numElements | The number of entries in the vector |
Definition at line 15 of file Morpheus_Vector.cpp.
Morpheus::Vector::~Vector | ( | ) |
double & Morpheus::Vector::operator[] | ( | const int | subscript | ) |
Subscript operator.
Returns a reference to the entry at the location denoted by subscript. Example usage:
Vector v(3); v[0] = 1; v[1] = 0; v[2] = 0;
[in] | subscript | The subscript of interest |
Definition at line 33 of file Morpheus_Vector.cpp.
const double & Morpheus::Vector::operator[] | ( | const int | subscript | ) | const |
Const subscript operator.
Returns a const reference to the entry at the location denoted by subscript. Example usage:
Vector v(3); v.setValue(); double entry = v[0];
[in] | subscript | The subscript of interest |
Definition at line 43 of file Morpheus_Vector.cpp.
int Morpheus::Vector::getNumElements | ( | ) | const |
Returns the total number of entries.
Definition at line 53 of file Morpheus_Vector.cpp.
void Morpheus::Vector::setValue | ( | const double | alpha = 0 |
) |
Initializes all entries to alpha.
[in] | alpha | The number all entries are set equal to. Default: 0 |
Definition at line 59 of file Morpheus_Vector.cpp.
void Morpheus::Vector::scale | ( | const double | alpha | ) |
Scales the vector.
Every entry in the vector is multiplied by alpha
[in] | alpha | The number to scale by |
Definition at line 68 of file Morpheus_Vector.cpp.
Vector addition
Replaces sum by this + b.
[in] | b | Vector to add |
[out] | sum | Sum vector |
Definition at line 77 of file Morpheus_Vector.cpp.
double Morpheus::Vector::dot | ( | const Vector & | b | ) | const |
Dot product.
If this and b are not the same size, this function will abort
[in] | b | Vector to use in dot-product |
Definition at line 91 of file Morpheus_Vector.cpp.
double Morpheus::Vector::norm1 | ( | ) | const |
Sum of all entries.
Definition at line 108 of file Morpheus_Vector.cpp.
double Morpheus::Vector::normInf | ( | ) | const |
Maximum magnitude entry.
Definition at line 122 of file Morpheus_Vector.cpp.
double Morpheus::Vector::norm2 | ( | ) | const |
Length of vector.
Definition at line 140 of file Morpheus_Vector.cpp.
void Morpheus::Vector::print | ( | ) | const |
Prints vector to console.
Example:
Vector with 3 entries
data[0] = 0
data[1] = 0
data[2] = 7
Definition at line 154 of file Morpheus_Vector.cpp.
int Morpheus::Vector::numElements_ [private] |
Number of elements in the vector.
Cannot be changed after construction
Definition at line 158 of file Morpheus_Vector.h.
double* Morpheus::Vector::data_ [private] |
Pointer to raw data.
Allocated in the constructor and deallocated in the destructor.
Definition at line 163 of file Morpheus_Vector.h.