RigidVector.h

Classes

RigidVector -- Fast Vector classes with fixed (templated) length (full description)
Global Functions -- Mathematical operations involving RigidVectors (full description)

template <class T, Int n> class RigidVector

Interface

friend RigidVector<T,n> operator+(const RigidVector<T,n>& l, const RigidVector<T,n>& r)
friend RigidVector<T,n> operator-(const RigidVector<T,n>& l, const RigidVector<T,n>& r)
friend T operator*(const RigidVector<T,n>& l, const RigidVector<T,n>& r)
friend RigidVector<T,n> operator*(const T& f, const RigidVector<T,n>& v)
friend RigidVector<T,n> operator*(const RigidVector<T,n>& v, const T& f)
friend ostream& operator<<(ostream& os, const RigidVector<T,n>& v)
friend RigidVector<Complex,4> operator*(const SquareMatrix<Complex,4>& m, const RigidVector<Float,4>& v)
Public Members
RigidVector()
RigidVector(const T& c)
RigidVector(const T& v0, const T& v1)
RigidVector(const T& v0, const T& v1, const T& v2)
RigidVector(const T& v0, const T& v1, const T& v2, const T& v3)
RigidVector(const T v[n])
RigidVector(const Vector<T> & v)
RigidVector(const RigidVector<T,n>& v)
RigidVector<T,n>& operator=(const RigidVector<T,n>& v)
RigidVector<T,n>& operator=(const n<T>& v)
RigidVector<T,n>& operator=(const T& c)
RigidVector<T,n>& operator-()
RigidVector<T,n>& operator+=(const RigidVector<T,n>& v)
RigidVector<T,n>& operator*=(const RigidVector<T,n>& v)
RigidVector<T,n>& operator-=(const RigidVector<T,n>& v)
RigidVector<T,n>& operator*=(const T& val)
RigidVector<T,n>& operator*=(const n<T,n>& m)
T& operator()(Int i)
const T& operator()(Int i) const
Vector<T> vector() const
RigidVector<T,n> sqrt(const RigidVector<T,n>& v)

Description

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Etymology

RigidVector is a vector with a size fixed at compile time, i.e. Rigid as compared to the normal Vector class.

Synopsis

RigidVector is a specialized Vector class for short (<25 elements) vectors. It has a size fixed at compile time, avoids new and delete and uses copy semantics throughout. Unlike Vectors, RigidVectors have fixed zero origin and no strides, allowing fast indexing. The more common mathematical operations are defined for RigidVector, allowing element by element arithmetic, innerproduct and matrix multiplication (by a SquareMatrix). Conversion to and from normal vectors is provided.

Example

    // Create two RigidVectors
    RigidVector<Float,3> rv1(1.0,2.0,3.0),rv2(3.0,2.0,1.0);
    // Compute sum
    RigidVector<Float,3> rv3=rv1+rv2;
    // Compute innerproduct
    Float inprod=rv1*rv2;
    // Write out results
    cout << "rv1+rv2="<< rv3 <<", rv1*rv2="<< inprod<<endl;
    

Motivation

The standard Vector class is rather inefficient for short vectors, this class is designed for speed and simplicity.

Template Type Argument Requirements (T)

Thrown Exceptions

To Do

Member Description

friend RigidVector<T,n> operator+(const RigidVector<T,n>& l, const RigidVector<T,n>& r)

Add two RigidVectors.

friend RigidVector<T,n> operator-(const RigidVector<T,n>& l, const RigidVector<T,n>& r)

Subtract two RigidVectors.

friend T operator*(const RigidVector<T,n>& l, const RigidVector<T,n>& r)

The innerproduct of 2 RigidVectors.

friend RigidVector<T,n> operator*(const T& f, const RigidVector<T,n>& v)

Multiply a RigidVector by a scalar.

friend RigidVector<T,n> operator*(const RigidVector<T,n>& v, const T& f)

Multiply a RigidVector by a scalar.

friend ostream& operator<<(ostream& os, const RigidVector<T,n>& v)

Write out a RigidVector using the Vector output method.

friend RigidVector<Complex,4> operator*(const SquareMatrix<Complex,4>& m, const RigidVector<Float,4>& v)

Special matrix multiply of Complex matrix * Float vector.

RigidVector()

RigidVector(Int dummy) { for (Int i=0; iRigidVector(const T& c)

Construct from scalar, sets all elements to c

RigidVector(const T& v0, const T& v1)

Construct a 2-element vector, fails for wrong size vectors.

RigidVector(const T& v0, const T& v1, const T& v2)

Construct a 3-element vector, fails for wrong size vectors.

RigidVector(const T& v0, const T& v1, const T& v2, const T& v3)

Construct a 4-element vector, fails for wrong size vectors.

RigidVector(const T v[n])

Construct from a c-array (copy semantics)

RigidVector(const Vector<T> & v)

Construct from a Vector.

RigidVector(const RigidVector<T,n>& v)

Copy constructor, copy semantics.

RigidVector<T,n>& operator=(const RigidVector<T,n>& v)

Assign from a RigidVector.

RigidVector<T,n>& operator=(const n<T>& v)

Assign from a Vector.

RigidVector<T,n>& operator=(const T& c)

Assign a scalar, sets all elements to c.

RigidVector<T,n>& operator-()

Negation

RigidVector<T,n>& operator+=(const RigidVector<T,n>& v)

Addition

RigidVector<T,n>& operator*=(const RigidVector<T,n>& v)

RigidVector<T,n>& operator-=(const RigidVector<T,n>& v)

Subtraction

RigidVector<T,n>& operator*=(const T& val)

Multiplication by scalar.

RigidVector<T,n>& operator*=(const n<T,n>& m)

Multiply vector by matrix: v*=M is equivalent to v=M*v;

T& operator()(Int i)

Indexing by reference

const T& operator()(Int i) const

Indexing by const reference

Vector<T> vector() const

Convert to a regular Vector

RigidVector<T,n> sqrt(const RigidVector<T,n>& v)

Square Root


Mathematical operations involving RigidVectors (source)

Interface

Protected Members
inline RigidVector<Float,4> operator*(const SquareMatrix<Float,4>& m, const RigidVector<Float,4>& v)
inline RigidVector<Complex,4> operator*(const 4<Complex,4>& m, const RigidVector<Complex,4>& v)

Description

Member Description

inline RigidVector<Float,4> operator*(const SquareMatrix<Float,4>& m, const RigidVector<Float,4>& v)

Multiply vector by matrix.

inline RigidVector<Complex,4> operator*(const 4<Complex,4>& m, const RigidVector<Complex,4>& v)

Multiply vector by matrix.