Morpheus::Vector Class Reference

Stores a dense vector. More...

#include <Morpheus_Vector.h>

List of all members.

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.

Detailed Description

Stores a dense vector.

Todo:
Consider whether Vector should be a subclass of Matrix
Examples:

Morpheus_Vector_addScaleTest.cpp, and Morpheus_Vector_normTest.cpp.

Definition at line 30 of file Morpheus_Vector.h.


Constructor & Destructor Documentation

Morpheus::Vector::Vector ( const int  numElements  ) 

Constructor.

Allocates memory for a Vector. If numElements is not positive, the program terminates.

Parameters:
[in] numElements The number of entries in the vector
Warning:
This function only allocates the memory; it does not initialize the memory.

Definition at line 15 of file Morpheus_Vector.cpp.

Morpheus::Vector::~Vector (  ) 

Destructor.

Deallocates memory for a Vector

Definition at line 26 of file Morpheus_Vector.cpp.


Member Function Documentation

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;
Parameters:
[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];
Parameters:
[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.

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

Parameters:
[in] alpha The number to scale by
Examples:
Morpheus_Vector_addScaleTest.cpp.

Definition at line 68 of file Morpheus_Vector.cpp.

void Morpheus::Vector::add ( const Vector b,
Vector sum 
) const

Vector addition

Replaces sum by this + b.

Parameters:
[in] b Vector to add
[out] sum Sum vector
Note:
This function does not allocate memory; it fills in the existing values of sum. If this, b, and sum are not the same size, the function will abort.
Examples:
Morpheus_Vector_addScaleTest.cpp.

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

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

Examples:
Morpheus_Vector_addScaleTest.cpp.

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.


Member Data Documentation

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.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables

Generated on 2 Aug 2016 for Morpheus by  doxygen 1.6.1