Public Member Functions | Protected Attributes

regina::NVectorUnit< T > Class Template Reference
[Mathematical Support]

A unit vector of type T. More...

#include <nvectorunit.h>

Inheritance diagram for regina::NVectorUnit< T >:
regina::NVector< T >

List of all members.

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.

Detailed Description

template<class T>
class regina::NVectorUnit< T >

A unit vector of type T.

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.

Precondition:
See the preconditions for NVector<T>.
Python:
Not present.

Constructor & Destructor Documentation

template<class T >
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.

Precondition:
The given coordinate is between 0 and size()-1 inclusive.
Parameters:
newVectorSizethe number of elements in the new vector.
coordinatethe coordinate in which the 1 will appear.

Member Function Documentation

template<class 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.

Precondition:
This and the given vector have the same size.
Parameters:
otherthe vector a multiple of which will be added to this vector.
multiplethe multiple of other to be added to this vector.

Implements regina::NVector< T >.

template<class T >
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.

Returns:
a clone of this vector.

Implements regina::NVector< T >.

template<class 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.

Returns:
the sum of the elements of this vector.

Reimplemented from regina::NVector< T >.

template<class T >
virtual void regina::NVectorUnit< T >::negate (  ) [inline, virtual]

Negates every element of this vector.

Implements regina::NVector< T >.

template<class T >
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.

Returns:
the norm of this vector.

Reimplemented from regina::NVector< T >.

template<class 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.

Precondition:
This and the given vector have the same size.
Parameters:
otherthe vector with which this will be multiplied.
Returns:
the dot product of this and the given vector.

Reimplemented from regina::NVector< T >.

template<class T >
virtual void regina::NVectorUnit< T >::operator*= ( const T &  factor ) [inline, virtual]

Multiplies this vector by the given scalar.

Parameters:
factorthe scalar with which this will be multiplied.

Implements regina::NVector< T >.

template<class T >
virtual void regina::NVectorUnit< T >::operator+= ( const NVector< T > &  other ) [inline, virtual]

Adds the given vector to this vector.

Precondition:
This and the given vector have the same size.
Parameters:
otherthe vector to add to this vector.

Implements regina::NVector< T >.

template<class T >
virtual void regina::NVectorUnit< T >::operator-= ( const NVector< T > &  other ) [inline, virtual]

Subtracts the given vector from this vector.

Precondition:
This and the given vector have the same size.
Parameters:
otherthe vector to subtract from this vector.

Implements regina::NVector< T >.

template<class T >
virtual void regina::NVectorUnit< T >::operator= ( const NVector< T > &  cloneMe ) [inline, virtual]

Sets this vector equal to the given vector.

Precondition:
This and the given vector have the same size.
Parameters:
cloneMethe vector whose value shall be assigned to this vector.

Implements regina::NVector< T >.

template<class 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.

Precondition:
index is between 0 and size()-1 inclusive.
Parameters:
indexthe vector index to examine.
Returns:
the vector element at the given index.

Implements regina::NVector< T >.

template<class 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.

Precondition:
index is between 0 and size()-1 inclusive.
Parameters:
indexthe vector index to examine.
valuethe new value to assign to the element.
Returns:
the vector element at the given index.

Implements regina::NVector< T >.

template<class T >
virtual unsigned regina::NVectorUnit< T >::size (  ) const [inline, virtual]

Returns the number of elements in the vector.

Returns:
the vector size.

Implements regina::NVector< T >.

template<class 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.

Precondition:
This and the given vector have the same size.
Parameters:
otherthe vector a multiple of which will be subtracted from this vector.
multiplethe multiple of other to be subtracted from this vector.

Implements regina::NVector< T >.


Member Data Documentation

template<class T >
unsigned regina::NVectorUnit< T >::direction [protected]

The coordinate that is 1 instead of 0.

template<class T >
unsigned regina::NVectorUnit< T >::vectorSize [protected]

The size of the vector, possibly including zero elements.


The documentation for this class was generated from the following file:

Copyright © 1999-2009, Ben Burton
This software is released under the GNU General Public License.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).