VectorX Class Template Reference
[Dynamic-size classesVectors]

Dynamic-size vector. More...

#include <vector.h>

Inheritance diagram for VectorX:

VectorBase

List of all members.

Public Types

typedef T ScalType

Public Member Functions

T * array ()
const T * array () const
void cross (const Derived &other, Derived *res) const
Derived cross (const Derived &other) const
dot (const Derived &other) const
bool hasDynamicSize () const
bool isApprox (const Derived &other, const T &precision=Util::epsilon< T >()) const
bool isNegligible (const Derived &other, const T &precision=Util::epsilon< T >()) const
bool isNegligible (const T &other, const T &precision=Util::epsilon< T >()) const
bool isZero (const T &precision=Util::epsilon< T >()) const
Derived & loadOrtho (const Derived &other)
Derived & loadRandom ()
Derived & loadRandomUnit ()
Derived & loadZero ()
Derived & makeOrthoVector (Derived *res) const
norm () const
norm2 () const
Derived & normalize ()
Derived normalized ()
bool operator!= (const Derived &other) const
T & operator() (int i)
const T & operator() (int i) const
Derived operator* (const T &factor) const
VectorXoperator*= (const T &factor)
Derived operator+ (const Derived &other) const
Derived & operator+= (const Derived &other)
VectorXoperator+= (const VectorX &other)
Derived operator- () const
Derived operator- (const Derived &other) const
Derived & operator-= (const Derived &other)
VectorXoperator-= (const VectorX &other)
Derived operator/ (const T &factor) const
VectorXoperator/= (const T &factor)
VectorXoperator= (const VectorX &other)
bool operator== (const Derived &other) const
T & operator[] (int i)
const T & operator[] (int i) const
Derived ortho () const
void readArray (const T *src)
void replaceWithOpposite ()
void resize (int newsize)
int size () const
 VectorX (int size, const T *array)
 VectorX (int size=1)
 VectorX (const VectorX &other)
const T & w () const
T & w ()
const T & x () const
T & x ()
const T & y () const
T & y ()
const T & z () const
T & z ()
 ~VectorX ()

Protected Attributes

T * m_array
int m_size


Detailed Description

template<typename T>
class Eigen::VectorX< T >

Dynamic-size vector.

A class for dynamic-size vectors (for linear algebra).

The template parameter T is the type of the coords of the vector. It can be any type representing either real or complex numbers. The following typedefs are provided to cover the usual cases:

    typedef VectorX<double>                 VectorXd;
    typedef VectorX<float>                  VectorXf;
    typedef VectorX< std::complex<double> > VectorXcd;
    typedef VectorX< std::complex<float> >  VectorXcf;

If you prefer fixed-size vectors (they are faster), see the Vector class template, which provides exactly the same functionality and API in fixed-size version.

The VectorX class template provides all the usual operators and methods to manipulate vectors.

Here are some examples of usage of VectorX:

    using namespace Eigen;
    using namespace std; // we'll use cout for outputting vectors

    double array1[3] = { -1.1, 2.9, 4.3 };
    VectorXd vec1( 3, array1 ); // construct vector vec1 from array array1

    VectorXd vec2( 3 ); // construct a new uninitialized vector of size 3
    double array2[3] = { 2.4, 3.1, -0.7 };
    vec2.readArray( array2); // reads the coords of vec2 from array2

    vec1 += vec2; // computes the coord-wise sum vec1 + vec2, stores it in vec1
    vec1 = vec1 - vec2; // there are also non-assignment operators
    vec1 = 0.9 * vec1 + vec2 / 2.6; // you can also multiply/divide by numbers

    VectorXd vec3(5); // construct a new uninitialized vector of size 5
    vec3 = vec1; // Resizes vec3 to size 3, copies vec1 into vec3

    vec1(2) = -1.4; // Stores the value -1.4 in coord 2 of vec1.
    cout << vec1 << endl;
    cout << "norm of vec1: " << vec1.norm() << endl;

Member Typedef Documentation

typedef T ScalType [inherited]


Constructor & Destructor Documentation

VectorX ( const VectorX< T > &  other  )  [inline]

Copy constructor

VectorX ( int  size = 1  )  [inline, explicit]

Constructs a vector with given size and uninitialized coords. The default value sor size is 1.

VectorX ( int  size,
const T *  array 
) [inline]

Constructs a vector with given size and reads its coord from the array.

~VectorX (  )  [inline]


Member Function Documentation

T* array (  )  [inline, inherited]

Returns:
the array of the vector, as non-constant.
See also:
array() const, operator()(int), operator[](int)

const T* array (  )  const [inline, inherited]

Returns the array of the vector, as constant.

See also:
array(), operator()(int) const, operator[](int) const

void cross ( const Derived &  other,
Derived *  res 
) const [inline, inherited]

Sets *res to be the cross product of *this by other. *this and other must have size exactly 3.

In fixed-size, *res must also have size 3. In dynamic-size, *res gets resized to size 3 if necessary.

See also:
cross(const Derived &) const

Derived cross ( const Derived &  other  )  const [inline, inherited]

Returns the cross product of *this by other. *this and other must have size exactly 3.

This method returns an object by value, which is inefficient. For better performance, use cross(const Derived &, Derived *) const

See also:
cross(const Derived &, Derived *) const

T dot ( const Derived &  other  )  const [inline, inherited]

Returns the dot product of *this by other.

*this and other must have the same size (the compiler will check that for fixed-size vectors, but not for dynamic-size vectors).

If T is std::complex, the dot product is hermitian, i.e. the coords of *this get complex-conjugated in the formula.

See also:
norm(), norm2()

bool hasDynamicSize (  )  const [inline, inherited]

Returns:
true if the vector has dynamic size (i.e. is an object of class VectorX), false if the vector has fixed size (i.e. is an object of class Vector).
See also:
size(), resize()

bool isApprox ( const Derived &  other,
const T &  precision = Util::epsilon<T>() 
) const [inline, inherited]

Returns true if *this and other are approximately equal.

The optional parameter precision allows to control the number of significant digits of precision. For instance, setting precision to 1e-5 results in a precision of 5 decimal digits.

This test is for nonzero vectors. If either of the two vectors being compared is zero, then it returns true if, and only if the other one is also zero -- which is not what one typically wants.

To compare a vector with the zero vector, i.e. to check whether a vector is approximately zero, use isZero() instead.

See also:
operator==(), operator!=(), isZero()

bool isNegligible ( const Derived &  other,
const T &  precision = Util::epsilon<T>() 
) const [inline, inherited]

Checks whether the vector *this is much smaller than other.

Equivalent to isNegligible( other.norm(), precision ).

See also:
isNegligible( const T &, const T & ) const

bool isNegligible ( const T &  other,
const T &  precision = Util::epsilon<T>() 
) const [inline, inherited]

Returns true if all coeffs of *this are smaller (in absolute value) than other*precision. In other words, returns true if all coeffs are much smaller than other. For the meaning of precision, see isApprox().

See also:
isNegligible( const Derived &, const T & ) const, isApprox(), isZero()

bool isZero ( const T &  precision = Util::epsilon<T>()  )  const [inline, inherited]

Tests whether *this is approximately equal to the zero matrix.

Equivalent to isNegligible(1). In other words, returns true if all entries of *this are approximately zero, in the sense that they have absolute value smaller than epsilon.

See also:
isNegligible( const T &, const T & ) const, isApprox()

Derived & loadOrtho ( const Derived &  other  )  [inline, inherited]

Loads into *this a unit vector that is orthogonal to other.

The size of other must be at least 2. *this gets resized to have the same size, if it has dynamic size.

If the size is exactly 2, then other points toward the left, other.x() = -y() and other.y() = x(). For dimensions at least 3, it is of course impossible to speak of "pointing toward the left".

Returns:
a reference to *this.
See also:
ortho(), MatrixBase::loadOrthoBasis()

Derived & loadRandom (  )  [inline, inherited]

Sets all coords to random values between -1.0 and 1.0. For complex numbers, both the real and imaginary parts can range from -1.0 to 1.0. The resulting vector can be zero (though that's not going to happen often!)

See also:
loadRandomUnit(), loadZero()

Derived& loadRandomUnit (  )  [inline, inherited]

Loads into *this a random unit vector.

See also:
loadRandom(), normalize()

Derived & loadZero (  )  [inline, inherited]

Sets all coords of *this to zero.

See also:
loadRandom()

Derived& makeOrthoVector ( Derived *  res  )  const [inline, inherited]

Constructs a unit vector that is orthogonal to *this, and stores it into *res.

*res and *this must have the same size, and that size must be at least 2.

Returns:
a reference to *res.
Deprecated:
use loadOrtho() or ortho() instead.
See also:
loadOrtho(), ortho(), MatrixBase::loadOrthoBasis()

T norm (  )  const [inline, inherited]

Returns the norm of *this, obtained as the square root of norm2().

See also:
norm2(), dot(), normalize()

T norm2 (  )  const [inline, inherited]

Returns the squared norm of *this, that is, the dot product of *this with itself.

See also:
norm(), dot()

Derived& normalize (  )  [inline, inherited]

Normalizes *this, that is, divides *this by norm().

See also:
norm(), normalized()

Derived normalized (  )  [inline, inherited]

Returns a normalized copy of *this. In other words, returns (*this) / norm().

This method returns an object by value, which is inefficient.

See also:
normalize()

bool operator!= ( const Derived &  other  )  const [inline, inherited]

Equivalent to !isApprox() with the default precision.

Note:
Despite the name, this operator does a fuzzy compare! It is not equivalent to operator!= on each entry.
See also:
isApprox(),operator==(),isZero()

T& operator() ( int  i  )  [inline, inherited]

Returns:
a non-constant reference to the i-th coord of the vector.
Same as operator[].

See also:
operator()(int) const, operator[](int)

const T& operator() ( int  i  )  const [inline, inherited]

Returns:
a constant reference to the i-th coord of the vector.
Same as operator[].

See also:
operator()(int), operator[](int) const

Derived operator* ( const T &  factor  )  const [inline, inherited]

Returns *this * factor (multiplication of each coord).

This method returns an object by value, which is inefficient.

See also:
operator*=(const T&)

VectorX& operator*= ( const T &  factor  )  [inline]

Stores *this * factor into *this (multiplication of each coord).

See also:
operator*(const T&) const

Reimplemented from VectorBase.

Derived operator+ ( const Derived &  other  )  const [inline, inherited]

Returns *this + other (coordinate-wise addition). The vectors *this and other must have the same size.

This method returns an object by value, which is inefficient.

See also:
operator+=()

Derived& operator+= ( const Derived &  other  )  [inline, inherited]

Stores *this + other into *this (coordinate-wise addition).

*this and other must have the same size.

See also:
operator+()

VectorX& operator+= ( const VectorX< T > &  other  )  [inline]

Derived operator- ( void   )  const [inline, inherited]

Returns (-(*this)).

This method returns an object by value, which is inefficient.

See also:
replaceWithOpposite(), operator-(const Derived &) const

Derived operator- ( const Derived &  other  )  const [inline, inherited]

Returns *this - other (coordinate-wise substraction). The vectors *this and other must have the same size.

This method returns an object by value, which is inefficient.

See also:
operator-=(const Derived &), operator-(void) const

Derived& operator-= ( const Derived &  other  )  [inline, inherited]

Stores *this - other into *this (coordinate-wise substraction).

*this and other must have the same size.

See also:
operator-(const Derived &) const

VectorX& operator-= ( const VectorX< T > &  other  )  [inline]

Derived operator/ ( const T &  factor  )  const [inline, inherited]

Returns *this / factor (division of each coord).

This method returns an object by value, which is inefficient.

See also:
operator/=(const T&), operator*(const T&) const

VectorX& operator/= ( const T &  factor  )  [inline]

Stores *this / factor into *this (division of each coord).

See also:
operator*=(const T&), operator/(const T&) const

Reimplemented from VectorBase.

VectorX& operator= ( const VectorX< T > &  other  )  [inline]

bool operator== ( const Derived &  other  )  const [inline, inherited]

Equivalent to isApprox() with the default precision.

Note:
Despite the name, this operator does a fuzzy compare! It is not equivalent to operator== on each entry.
See also:
isApprox(),operator!=(),isZero()

T& operator[] ( int  i  )  [inline, inherited]

Returns:
a non-constant reference to the i-th coord of the vector.
Same as operator().

See also:
operator[](int) const, operator()(int)

const T& operator[] ( int  i  )  const [inline, inherited]

Returns:
a constant reference to the i-th coord of the vector.
Same as operator().

See also:
operator[](int), operator()(int) const

Derived ortho (  )  const [inline, inherited]

Returns a unit vector that is orthogonal to *this.

This method returns an object by value, which is inefficient. For better performance, use loadOrtho() instead.

See also:
loadOrtho(), makeOrthoVectorMatrixBase::loadOrthoBasis()

void readArray ( const T *  src  )  [inline, inherited]

Reads the coords of *this from an array. The number of entries read from the array is equal to size().

See also:
operator=()

void replaceWithOpposite (  )  [inline, inherited]

Replaces *this with (-(*this)).

See also:
operator-(void) const

void resize ( int  newsize  )  [inline, inherited]

Tries to resize the vector. That is only possible if the vector has dynamic size, i.e. is an object of class VectorX. Otherwise, nothing is done.

The vector coords are not kept, they are left with undefined values after resizing.

See also:
size(), hasDynamicSize()

int size (  )  const [inline, inherited]

Returns the size (dimension) of the vector.

See also:
hasDynamicSize(), resize()

const T& w (  )  const [inline, inherited]

Returns a constant reference to the fourth coord of *this.

The size of *this must be at least 4.

See also:
w()

T& w (  )  [inline, inherited]

Returns a reference to the fourth coord of *this.

The size of *this must be at least 4.

See also:
w() const

const T& x (  )  const [inline, inherited]

Returns a constant reference to the first coord of *this.

See also:
x()

T& x (  )  [inline, inherited]

Returns a reference to the first coord of *this.

See also:
x() const

const T& y (  )  const [inline, inherited]

Returns a constant reference to the second coord of *this.

The size of *this must be at least 2.

See also:
y()

T& y (  )  [inline, inherited]

Returns a reference to the second coord of *this.

The size of *this must be at least 2.

See also:
y() const

const T& z (  )  const [inline, inherited]

Returns a constant reference to the third coord of *this.

The size of *this must be at least 3.

See also:
z()

T& z (  )  [inline, inherited]

Returns a reference to the third coord of *this.

The size of *this must be at least 3.

See also:
z() const


Member Data Documentation

T* m_array [protected]

The vector's array of coordinates.

int m_size [protected]

The size (dimension) of the vector


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

Generated on Tue Mar 18 15:31:22 2008 for Eigen by  doxygen 1.5.5