#include <nvectorunit.h>
Inheritance diagram for regina::NVectorUnit< T >:
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.
|
Creates a new unit vector with 1 in the given coordinate position. All other positions will contain 0.
|
|
Adds the given multiple of the given vector to this vector.
Implements regina::NVector< T >. |
|
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 >. |
|
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 >. |
|
Negates every element of this vector.
Implements regina::NVector< T >. |
|
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 >. |
|
Calculates the dot product of this vector and the given vector. The default implementation simply runs through the two vectors multiplying elements in pairs.
Reimplemented from regina::NVector< T >. |
|
Multiplies this vector by the given scalar.
Implements regina::NVector< T >. |
|
Adds the given vector to this vector.
Implements regina::NVector< T >. |
|
Subtracts the given vector from this vector.
Implements regina::NVector< T >. |
|
Sets this vector equal to the given vector.
Implements regina::NVector< T >. |
|
Returns the element at the given index in the vector. A constant reference to the element is returned; the element may not be altered.
Implements regina::NVector< T >. |
|
Sets the element at the given index in the vector to the given value.
Implements regina::NVector< T >. |
|
Returns the number of elements in the vector.
Implements regina::NVector< T >. |
|
Subtracts the given multiple of the given vector to this vector.
Implements regina::NVector< T >. |
|
The coordinate that is 1 instead of 0.
|
|
The size of the vector, possibly including zero elements.
|