TooN 2.1
Classes | Functions | Variables
Linear Algebra

Vector and Matrix classes, and helpers. More...

Classes

struct  Matrix< Rows, Cols, Precision, Layout >
 A matrix. More...
class  DiagonalMatrix< Size, Precision, Base >
 A diagonal matrix. More...
class  Vector< Size, Precision, Base >
 A vector. More...

Functions

template<int R, int C, typename Precision , typename Base >
Precision determinant_gaussian_elimination (const Matrix< R, C, Precision, Base > &A_)
template<int R, int C, class P , class B >
determinant (const Matrix< R, C, P, B > &A)
template<int Size, class Precision , class Base >
TOON_DEPRECATED void Fill (Vector< Size, Precision, Base > &v, const Precision &p)
template<int Rows, int Cols, class Precision , class Base >
TOON_DEPRECATED void Fill (Matrix< Rows, Cols, Precision, Base > &m, const Precision &p)
template<int Size, class Precision , class Base >
Precision norm (const Vector< Size, Precision, Base > &v)
template<int Size, class Precision , class Base >
Precision norm_sq (const Vector< Size, Precision, Base > &v)
template<int Size, class Precision , class Base >
Precision norm_1 (const Vector< Size, Precision, Base > &v)
template<int Size, class Precision , class Base >
Precision norm_inf (const Vector< Size, Precision, Base > &v)
template<int Size, class Precision , class Base >
Precision norm_2 (const Vector< Size, Precision, Base > &v)
template<int Size, class Precision , class Base >
Vector< Size, Precision > unit (const Vector< Size, Precision, Base > &v)
template<int Size, class Precision , class Base >
void normalize (Vector< Size, Precision, Base > v)
template<int Size, typename Precision , typename Base >
Vector<(Size==Dynamic?Dynamic:Size-1)+0,
Precision > 
project (const Vector< Size, Precision, Base > &v)
template<int Size, typename Precision , typename Base >
Vector<(Size==Dynamic?Dynamic:Size+1)+0,
Precision > 
unproject (const Vector< Size, Precision, Base > &v)
template<int R, int C, typename P , typename B >
norm_fro (const Matrix< R, C, P, B > &m)
template<int R, int C, typename P , typename B >
norm_inf (const Matrix< R, C, P, B > &m)
template<int R, int C, typename P , typename B >
norm_1 (const Matrix< R, C, P, B > &m)
template<int R, int C, typename P , typename B >
Matrix< R, C, P > exp (const Matrix< R, C, P, B > &m)
template<int R, int C, typename P , typename B >
Matrix< R, C, P > sqrt (const Matrix< R, C, P, B > &m)
template<int R, int C, typename P , typename B >
Matrix< R, C, P > log (const Matrix< R, C, P, B > &m)
template<int S, class P , class B >
bool isfinite (const Vector< S, P, B > &v)
template<int S, class P , class B >
bool isnan (const Vector< S, P, B > &v)
template<int Rows, int Cols, typename Precision , typename Base >
void Symmetrize (Matrix< Rows, Cols, Precision, Base > &m)
template<int Rows, int Cols, typename Precision , typename Base >
Precision trace (const Matrix< Rows, Cols, Precision, Base > &m)
template<int Size, class P , class B >
TooN::Matrix< 3, 3, P > cross_product_matrix (const Vector< Size, P, B > &vec)
template<int R, int C, class Precision , class Base >
Internal::MatrixStartFill< R,
C, Precision, Base > 
Fill (Matrix< R, C, Precision, Base > &m)
template<int Size, class Precision , class Base >
Internal::VectorStartFill
< Size, Precision, Base > 
Fill (Vector< Size, Precision, Base > &v)
Operator< Internal::Data< N,
double > > 
Data (double a,...)
template<typename Precision >
Operator< Internal::Data< N,
Precision > > 
Data (const Precision &a,...)

Variables

static const Operator
< Internal::Scalars
< Internal::One > > 
Ones
static Operator< Internal::Zero > Zeros
static Operator
< Internal::Identity
< Internal::One > > 
Identity
template<int Rows, int Cols>
Matrix< Rows, Cols, double,
Reference::RowMajor > 
wrapMatrix (double *data)
template<int Rows, int Cols>
const Matrix< Rows, Cols,
const double,
Reference::RowMajor > 
wrapMatrix (const double *data)
template<int Rows, int Cols, class Precision >
Matrix< Rows, Cols, Precision,
Reference::RowMajor > 
wrapMatrix (Precision *data)
template<int Rows, int Cols, class Precision >
const Matrix< Rows, Cols,
const Precision,
Reference::RowMajor > 
wrapMatrix (const Precision *data)
template<int Rows, int Cols>
Matrix< Rows, Cols, double,
Reference::RowMajor > 
wrapMatrix (double *data, int rows, int cols)
template<int Rows, int Cols>
const Matrix< Rows, Cols,
const double,
Reference::RowMajor > 
wrapMatrix (const double *data, int rows, int cols)
template<int Rows, int Cols, class Precision >
Matrix< Rows, Cols, Precision,
Reference::RowMajor > 
wrapMatrix (Precision *data, int rows, int cols)
template<int Rows, int Cols, class Precision >
const Matrix< Rows, Cols,
const Precision,
Reference::RowMajor > 
wrapMatrix (const Precision *data, int rows, int cols)

Detailed Description

Vector and Matrix classes, and helpers.


Function Documentation

Precision TooN::determinant_gaussian_elimination ( const Matrix< R, C, Precision, Base > &  A_)

Compute the determinant using Gaussian elimination.

Parameters:
A_The matrix to find the determinant of.
Returns:
determinant.

References TooN::determinant(), Matrix< Rows, Cols, Precision, Layout >::num_cols(), and Matrix< Rows, Cols, Precision, Layout >::num_rows().

Referenced by TooN::determinant().

P TooN::determinant ( const Matrix< R, C, P, B > &  A)

Compute the determinant of a matrix using an appropriate method.

The obvious method is used for 2x2, otherwise determinant_gaussian_elimination() or determinant_LU() is used depending on the value of TOON_DETERMINANT_LAPACK. See also Functions using LAPACK.

Parameters:
AThe matrix to find the determinant of.
Returns:
determinant.

References TooN::determinant_gaussian_elimination(), Matrix< Rows, Cols, Precision, Layout >::num_cols(), and Matrix< Rows, Cols, Precision, Layout >::num_rows().

Referenced by TooN::determinant_gaussian_elimination().

TOON_DEPRECATED void TooN::Fill ( Vector< Size, Precision, Base > &  v,
const Precision &  p 
)
TOON_DEPRECATED void TooN::Fill ( Matrix< Rows, Cols, Precision, Base > &  m,
const Precision &  p 
)
Precision TooN::norm ( const Vector< Size, Precision, Base > &  v)

Compute the $L_2$ norm of v.

Parameters:
vv

References TooN::sqrt().

Referenced by DownhillSimplex< N, Precision >::finished(), and TooN::norm_2().

Precision TooN::norm_sq ( const Vector< Size, Precision, Base > &  v)

Compute the $L_2^2$ norm of v.

Parameters:
vv

Referenced by SO3< P >::SO3().

Precision TooN::norm_1 ( const Vector< Size, Precision, Base > &  v)

Compute the $L_1$ norm of v.

Parameters:
vv

References Vector< Size, Precision, Base >::size().

Referenced by ComputeSymEigen< 3 >::compute().

Precision TooN::norm_inf ( const Vector< Size, Precision, Base > &  v)

Compute the $L_\infty$ norm of v.

Parameters:
vv

References Vector< Size, Precision, Base >::size().

Referenced by TooN::exp(), TooN::log(), and TooN::sqrt().

Precision TooN::norm_2 ( const Vector< Size, Precision, Base > &  v)

Compute the $L_2$ norm of v.

Synonym for norm()

Parameters:
vv

References TooN::norm().

Vector<Size, Precision> TooN::unit ( const Vector< Size, Precision, Base > &  v)

Compute a the unit vector $\hat{v}$.

Parameters:
vv

References TooN::sqrt().

Referenced by SO3< P >::coerce(), SO2< P >::coerce(), ComputeSymEigen< 3 >::compute(), SO3< Precision >::ln(), and SO3< P >::SO3().

void TooN::normalize ( Vector< Size, Precision, Base >  v)

Normalize a vector in place.

Parameters:
vVector to normalize

References TooN::sqrt().

Referenced by ComputeSymEigen< 3 >::compute(), and TooN::normalize().

Vector<(Size==Dynamic?Dynamic:Size-1)+0, Precision> TooN::project ( const Vector< Size, Precision, Base > &  v)

For a vector v of length i, return $[v_1, v_2, \cdots, v_{i-1}] / v_i $.

Parameters:
vv

References TooN::Dynamic, and Vector< Size, Precision, Base >::size().

Vector<(Size==Dynamic?Dynamic:Size+1)+0, Precision> TooN::unproject ( const Vector< Size, Precision, Base > &  v)

For a vector v of length i, return $[v_1, v_2, \cdots, v_{i}, 1]$.

Parameters:
vv

References TooN::Dynamic, and Vector< Size, Precision, Base >::size().

P TooN::norm_fro ( const Matrix< R, C, P, B > &  m)

Frobenius (root of sum of squares) norm of input matrix m.

Parameters:
mm

References Matrix< Rows, Cols, Precision, Layout >::num_cols(), Matrix< Rows, Cols, Precision, Layout >::num_rows(), and TooN::sqrt().

Matrix<R, C, P> TooN::exp ( const Matrix< R, C, P, B > &  m)

computes the matrix exponential of a matrix m by scaling m by 1/(powers of 2), using Taylor series and squaring again.

Parameters:
minput matrix, must be square
Returns:
result matrix of the same size/type as input

References TooN::norm_inf(), Matrix< Rows, Cols, Precision, Layout >::num_cols(), and Matrix< Rows, Cols, Precision, Layout >::num_rows().

Referenced by SL< N, Precision >::exp().

Matrix<R, C, P> TooN::sqrt ( const Matrix< R, C, P, B > &  m)

computes a matrix square root of a matrix m by the product form of the Denman and Beavers iteration as given in Chen et al.

'Approximating the logarithm of a matrix to specified accuracy', J. Matrix Anal Appl, 2001. This is used for the matrix logarithm function, but is useable by on its own.

Parameters:
minput matrix, must be square
Returns:
a square root of m of the same size/type as input

References TooN::gaussian_elimination(), TooN::Identity, TooN::norm_inf(), Matrix< Rows, Cols, Precision, Layout >::num_cols(), and Matrix< Rows, Cols, Precision, Layout >::num_rows().

Referenced by TooN::brent_line_search(), ComputeSymEigen< 3 >::compute(), DownhillSimplex< N, Precision >::DownhillSimplex(), SO3< Precision >::exp(), SymEigen< Size, Precision >::get_isqrtm(), SymEigen< Size, Precision >::get_sqrtm(), TooN::golden_section_search(), ConjugateGradient< Size, Precision >::init(), SO3< Precision >::ln(), TooN::log(), TooN::norm(), TooN::norm_fro(), TooN::normalize(), and TooN::unit().

Matrix<R, C, P> TooN::log ( const Matrix< R, C, P, B > &  m)

computes the matrix logarithm of a matrix m using the inverse scaling and squaring method.

The overall approach is described in Chen et al. 'Approximating the logarithm of a matrix to specified accuracy', J. Matrix Anal Appl, 2001, but this implementation only uses a simple taylor series after the repeated square root operation.

Parameters:
minput matrix, must be square
Returns:
the log of m of the same size/type as input

References TooN::Identity, TooN::norm_inf(), and TooN::sqrt().

Referenced by RobustII< Precision >::objective(), and RobustI< Precision >::objective().

void TooN::Symmetrize ( Matrix< Rows, Cols, Precision, Base > &  m)
TooN::Matrix<3, 3, P> TooN::cross_product_matrix ( const Vector< Size, P, B > &  vec)

creates an returns a cross product matrix M from a 3 vector v, such that for all vectors w, the following holds: v ^ w = M * w

Parameters:
vecthe 3 vector input
Returns:
the 3x3 matrix to set to the cross product matrix

References Vector< Size, Precision, Base >::size().

Internal::MatrixStartFill<R, C, Precision, Base> TooN::Fill ( Matrix< R, C, Precision, Base > &  m)

Set up a matrix for filling.

Uses the following syntax:

    Matrix<2,2> m;
    Fill(m) = 1, 2,
              3, 4;

Overfill is detected at compile time if possible, underfill is detected at run-time. The checks can not be optimized out for dynamic matrices, so define TOON_NDEBUG_FILL to prevent the checks from being used.

Parameters:
mMatrix to fill
Internal::VectorStartFill<Size, Precision, Base> TooN::Fill ( Vector< Size, Precision, Base > &  v)

Set up a vector for filling.

Uses the following syntax:

    Vector<2> v;
    Fill(v) = 1, 2;

Overfill is detected at compile time if possible, underfill is detected at run-time. The checks can not be optimized out for dynamic vectors, so define TOON_NDEBUG_FILL to prevent the checks from being used.

Parameters:
vVector to fill
Operator<Internal::Data<N, double> > TooN::Data ( double  a,
  ... 
)

Package up the function arguments as some data for filling matrices.

Matrices are filled in row major order. For example:

              double theta = 2;
              Matrix<2> rotation = data( cos(theta), sin(theta)
                                        -sin(theta), cos(theta));

See also TooN::wrapMatrix().

Parameters:
aThe first data element.

Referenced by TooN::inv().

Operator<Internal::Data<N, Precision> > TooN::Data ( const Precision &  a,
  ... 
)

Package up the function arguments as some data for filling matrices.

Any type can be uses. Matrices are filled in row-major order.

              Matrix<2,2,float> rotation = data(1f, 2f, 3f, 4f);

See also TooN::wrapMatrix().

Parameters:
aThe first data element.

Variable Documentation

const Operator<Internal::Scalars<Internal::One> > Ones [static]

This function is used to add a scalar to every element of a vector or matrix.

For example:

   Vector<3> v;
   ...
   ...
   v += Ones * 3; //Add 3 to every element of v;

Both + and += are supported on vectors,matrices and slices.

For construction of dynamic vectors and matrices, a size needs to be given:

       Vector<3> v_static = Ones;    
       Vector<>  v_dynamic = Ones(3); //Construct a 3x1 vector full one 1s
       Matrix<3> m_static = Ones;     
       Matrix<>  m_dynamic = Ones(3,4); //Construct a 3x4 matrix

Referenced by ComputeSymEigen< 3 >::compute(), and TooN::unproject().

Operator<Internal::Zero> Zeros [static]

This function is used to initialize vectors and matrices to zero.

For construction of dynamic vectors and matrices, a size needs to be given. For example:

       Vector<3> v_static = Zeros;
       Vector<>  v_dynamic = Zeros(3); //Construct a 3x1 vector
       Matrix<3> m_static = Zeros;
       Matrix<>  m_dynamic = Zeros(3,4); //Construct a 3x4 matrix

Referenced by TooN::Internal::bracket_minimum_forward(), WLS< Size, Precision >::clear(), IRLS< Size, Precision, Reweight >::clear(), SL< N, Precision >::exp(), DownhillSimplex< N, Precision >::find_next_point(), SO3< P >::generator(), SL< N, Precision >::generator(), SIM2< P >::generator(), SE2< P >::generator(), SIM3< P >::generator_field(), and SE3< P >::generator_field().

Operator<Internal::Identity<Internal::One> > Identity [static]

This function is used to add a scalar to the diagonal of a matrix, or to construct matrices.

For example:

   Matrix<3> v;
   ...
   ...
   Matrix<3> u = v  + Identity * 4;

Both + and += are supported. For assignment, if the matrix is non-square, then all elements off the leading diagonal are set to zero. For construction of dynamic matrices, a size needs to be given:

       Matrix<3> m_static = Identity;     
       Matrix<>  m_dynamic = Identity(3); //Construct a 3x3 matrix

Referenced by ComputeSymEigen< 3 >::compute(), Cholesky< Size, Precision >::get_inverse(), TooN::log(), SO3< P >::SO3(), and TooN::sqrt().