#include <nvectorunit.h>
Public Member Functions | |
NVectorUnit (unsigned newVectorSize, unsigned coordinate) | |
Creates a new unit vector with 1 in the given coordinate position. | |
virtual NVector< T > * | clone () const |
Makes a newly allocated clone of this vector. | |
virtual unsigned | size () const |
Returns the number of elements in the vector. | |
virtual const T & | operator[] (unsigned index) const |
Returns the element at the given index in the vector. | |
virtual void | setElement (unsigned, const T &) |
Sets the element at the given index in the vector to the given value. | |
virtual void | operator= (const NVector< T > &) |
Sets this vector equal to the given vector. | |
virtual void | operator+= (const NVector< T > &) |
Adds the given vector to this vector. | |
virtual void | operator-= (const NVector< T > &) |
Subtracts the given vector from this vector. | |
virtual void | operator*= (const T &) |
Multiplies this vector by the given scalar. | |
virtual T | operator* (const NVector< T > &other) const |
Calculates the dot product of this vector and the given vector. | |
virtual void | negate () |
Negates every element of this vector. | |
virtual T | norm () const |
Returns the norm of this vector. | |
virtual T | elementSum () const |
Returns the sum of all elements of this vector. | |
virtual void | addCopies (const NVector< T > &, const T &) |
Adds the given multiple of the given vector to this vector. | |
virtual void | subtractCopies (const NVector< T > &, const T &) |
Subtracts the given multiple of the given vector to this vector. | |
Protected Attributes | |
unsigned | vectorSize |
The size of the vector, possibly including zero elements. | |
unsigned | direction |
The coordinate that is 1 instead of 0. |
A unit vector has every coordinate set to 0 except for a single coordinate which is 1.
A unit vector takes almost no storage space and provides very fast operations. It should never be modified! The modification routines (such as =
, +=
and so on) throw exceptions, since a modified unit vector will probably no longer be a unit vector. It is recommended to declare any unit vector as const
for a safeguard.
Since a cloned vector might be modified, clone() will return a new NVectorDense instead of a new NVectorUnit.
The primary reason for having this class is for its dot product, which is exceptionally fast since all it need do is look up the corresponding coordinate of the other vector.
regina::NVectorUnit< T >::NVectorUnit | ( | unsigned | newVectorSize, | |
unsigned | coordinate | |||
) | [inline] |
Creates a new unit vector with 1 in the given coordinate position.
All other positions will contain 0.
newVectorSize | the number of elements in the new vector. | |
coordinate | the coordinate in which the 1 will appear. |
virtual NVector<T>* regina::NVectorUnit< T >::clone | ( | ) | const [inline, virtual] |
Makes a newly allocated clone of this vector.
The clone will be of the same subclass of NVector as this vector.
Implements regina::NVector< T >.
virtual unsigned regina::NVectorUnit< T >::size | ( | ) | const [inline, virtual] |
Returns the number of elements in the vector.
Implements regina::NVector< T >.
virtual const T& regina::NVectorUnit< T >::operator[] | ( | unsigned | index | ) | const [inline, virtual] |
Returns the element at the given index in the vector.
A constant reference to the element is returned; the element may not be altered.
index
is between 0 and size()-1 inclusive.index | the vector index to examine. |
Implements regina::NVector< T >.
virtual void regina::NVectorUnit< T >::setElement | ( | unsigned | index, | |
const T & | value | |||
) | [inline, virtual] |
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. |
Implements regina::NVector< T >.
virtual void regina::NVectorUnit< T >::operator= | ( | const NVector< T > & | cloneMe | ) | [inline, virtual] |
Sets this vector equal to the given vector.
cloneMe | the vector whose value shall be assigned to this vector. |
Implements regina::NVector< T >.
virtual void regina::NVectorUnit< T >::operator+= | ( | const NVector< T > & | other | ) | [inline, virtual] |
Adds the given vector to this vector.
other | the vector to add to this vector. |
Implements regina::NVector< T >.
virtual void regina::NVectorUnit< T >::operator-= | ( | const NVector< T > & | other | ) | [inline, virtual] |
Subtracts the given vector from this vector.
other | the vector to subtract from this vector. |
Implements regina::NVector< T >.
virtual void regina::NVectorUnit< T >::operator*= | ( | const T & | factor | ) | [inline, virtual] |
Multiplies this vector by the given scalar.
factor | the scalar with which this will be multiplied. |
Implements regina::NVector< T >.
virtual T regina::NVectorUnit< T >::operator* | ( | const NVector< T > & | other | ) | const [inline, virtual] |
Calculates the dot product of this vector and the given vector.
The default implementation simply runs through the two vectors multiplying elements in pairs.
other | the vector with which this will be multiplied. |
Reimplemented from regina::NVector< T >.
virtual void regina::NVectorUnit< T >::negate | ( | ) | [inline, virtual] |
virtual T regina::NVectorUnit< T >::norm | ( | ) | const [inline, virtual] |
Returns the norm of this vector.
This is the dot product of the vector with itself. The default implementation simply runs through the elements squaring each one in turn.
Reimplemented from regina::NVector< T >.
virtual T regina::NVectorUnit< T >::elementSum | ( | ) | const [inline, virtual] |
Returns the sum of all elements of this vector.
The default implementation simply runs through the elements adding each one in turn.
Reimplemented from regina::NVector< T >.
virtual void regina::NVectorUnit< T >::addCopies | ( | const NVector< T > & | other, | |
const T & | multiple | |||
) | [inline, virtual] |
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. |
Implements regina::NVector< T >.
virtual void regina::NVectorUnit< T >::subtractCopies | ( | const NVector< T > & | other, | |
const T & | multiple | |||
) | [inline, virtual] |
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. |
Implements regina::NVector< T >.
unsigned regina::NVectorUnit< T >::vectorSize [protected] |
The size of the vector, possibly including zero elements.
unsigned regina::NVectorUnit< T >::direction [protected] |
The coordinate that is 1 instead of 0.