Regina Calculation Engine
|
An optimised vector class of elements from a given ring T. More...
#include <maths/nvector.h>
Public Member Functions | |
NVector (size_t newVectorSize) | |
Creates a new vector. More... | |
NVector (size_t newVectorSize, const T &initValue) | |
Creates a new vector and initialises every element to the given value. More... | |
NVector (const NVector< T > &cloneMe) | |
Creates a new vector that is a clone of the given vector. More... | |
~NVector () | |
Destroys this vector. More... | |
size_t | size () const |
Returns the number of elements in the vector. More... | |
const T & | operator[] (size_t index) const |
Returns the element at the given index in the vector. More... | |
void | setElement (size_t index, const T &value) |
Sets the element at the given index in the vector to the given value. More... | |
bool | operator== (const NVector< T > &compare) const |
Determines if this vector is equal to the given vector. More... | |
NVector< T > & | operator= (const NVector< T > &cloneMe) |
Sets this vector equal to the given vector. More... | |
void | operator+= (const NVector< T > &other) |
Adds the given vector to this vector. More... | |
void | operator-= (const NVector< T > &other) |
Subtracts the given vector from this vector. More... | |
void | operator*= (const T &factor) |
Multiplies this vector by the given scalar. More... | |
T | operator* (const NVector< T > &other) const |
Calculates the dot product of this vector and the given vector. More... | |
void | negate () |
Negates every element of this vector. More... | |
T | norm () const |
Returns the norm of this vector. More... | |
T | elementSum () const |
Returns the sum of all elements of this vector. More... | |
void | addCopies (const NVector< T > &other, const T &multiple) |
Adds the given multiple of the given vector to this vector. More... | |
void | subtractCopies (const NVector< T > &other, const T &multiple) |
Subtracts the given multiple of the given vector to this vector. More... | |
Static Public Attributes | |
static T | zero |
Zero in the underlying number system. More... | |
static T | one |
One in the underlying number system. More... | |
static T | minusOne |
Negative one in the underlying number system. More... | |
Protected Attributes | |
T * | elements |
The internal array containing all vector elements. More... | |
T * | end |
A pointer just beyond the end of the internal array. More... | |
An optimised vector class of elements from a given ring T.
Various mathematical vector operations are available.
This class is intended for serious computation, and as a result it has a streamlined implementation with no virtual methods. It can be subclassed, but since there are no virtual methods, type information must generally be known at compile time. Nevertheless, in many respects, different subclasses of NVector<T> can happily interact with one another.
This class is written with bulky types in mind (such as arbitrary precision integers), and so creations and operations are kept to a minimum.
a
and b
are of type T, then a
can be initialised to the value of b
using a(b)
. =
, ==
, +=
, -=
and *=
. a
is of type T, then a
can be initialised to a long integer l
using a(l)
. t
of type T can be written to an output stream out
using the standard expression out << t
.
|
inline |
Creates a new vector.
Its elements will not be initialised.
newVectorSize | the number of elements in the new vector; this must be strictly positive. |
|
inline |
Creates a new vector and initialises every element to the given value.
newVectorSize | the number of elements in the new vector; this must be strictly positive. |
initValue | the value to assign to every element of the vector. |
|
inline |
Creates a new vector that is a clone of the given vector.
cloneMe | the vector to clone. |
|
inline |
Destroys this vector.
|
inline |
Adds the given multiple of the given vector to this vector.
other | the vector a multiple of which will be added to this vector. |
multiple | the multiple of other to be added to this vector. |
|
inline |
Returns the sum of all elements of this vector.
|
inline |
Negates every element of this vector.
|
inline |
Returns the norm of this vector.
This is the dot product of the vector with itself.
|
inline |
Calculates the dot product of this vector and the given vector.
other | the vector with which this will be multiplied. |
|
inline |
Multiplies this vector by the given scalar.
factor | the scalar with which this will be multiplied. |
|
inline |
Adds the given vector to this vector.
other | the vector to add to this vector. |
|
inline |
Subtracts the given vector from this vector.
other | the vector to subtract from this vector. |
|
inline |
Sets this vector equal to the given vector.
cloneMe | the vector whose value shall be assigned to this vector. |
|
inline |
Determines if this vector is equal to the given vector.
compare | the vector with which this will be compared. |
true
if and only if the this and the given vector are equal.
|
inline |
|
inline |
Sets the element at the given index in the vector to the given value.
index
is between 0 and size()-1 inclusive.index | the vector index to examine. |
value | the new value to assign to the element. |
|
inline |
Returns the number of elements in the vector.
|
inline |
Subtracts the given multiple of the given vector to this vector.
other | the vector a multiple of which will be subtracted from this vector. |
multiple | the multiple of other to be subtracted from this vector. |
|
protected |
The internal array containing all vector elements.
|
protected |
A pointer just beyond the end of the internal array.
The size of the vector can be computed as (end - elements).