TooN
Classes | Functions
Linear Algebra

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

Classes

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

Functions

template<int R, int C, typename Precision , typename Base >
Precision TooN::determinant_gaussian_elimination (const Matrix< R, C, Precision, Base > &A_)
 Compute the determinant using Gaussian elimination. More...
 
template<int R, int C, class P , class B >
TooN::determinant (const Matrix< R, C, P, B > &A)
 Compute the determinant of a matrix using an appropriate method. More...
 
template<int Size, class Precision , class Base >
void TooN::Fill (Vector< Size, Precision, Base > &v, const Precision &p)
 
template<int Rows, int Cols, class Precision , class Base >
void TooN::Fill (Matrix< Rows, Cols, Precision, Base > &m, const Precision &p)
 
template<int Size, class Precision , class Base >
Precision TooN::norm (const Vector< Size, Precision, Base > &v)
 Compute the \(L_2\) norm of v. More...
 
template<int Size, class Precision , class Base >
Precision TooN::norm_sq (const Vector< Size, Precision, Base > &v)
 Compute the \(L_2^2\) norm of v. More...
 
template<int Size, class Precision , class Base >
Precision TooN::norm_1 (const Vector< Size, Precision, Base > &v)
 Compute the \(L_1\) norm of v. More...
 
template<int Size, class Precision , class Base >
Precision TooN::norm_inf (const Vector< Size, Precision, Base > &v)
 Compute the \(L_\infty\) norm of v. More...
 
template<int Size, class Precision , class Base >
Precision TooN::norm_2 (const Vector< Size, Precision, Base > &v)
 Compute the \(L_2\) norm of v. More...
 
template<int Size, class Precision , class Base >
Vector< Size, Precision > TooN::unit (const Vector< Size, Precision, Base > &v)
 Compute a the unit vector \(\hat{v}\). More...
 
template<int Size, class Precision , class Base >
void TooN::normalize (Vector< Size, Precision, Base > &&v)
 Normalize a vector in place. More...
 
template<int Size, typename Precision , typename Base >
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 \). More...
 
template<int Size, typename Precision , typename Base >
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]\). More...
 
template<int R, int C, typename P , typename B >
TooN::norm_fro (const Matrix< R, C, P, B > &m)
 Frobenius (root of sum of squares) norm of input matrix m. More...
 
template<int R, int C, typename P , typename B >
TooN::norm_inf (const Matrix< R, C, P, B > &m)
 L&#8734; (row sum) norm of input matrix m computes the maximum of the sums of absolute values over rows
 
template<int R, int C, typename P , typename B >
TooN::norm_1 (const Matrix< R, C, P, B > &m)
 L1 (col sum) norm of input matrix m computes the maximum of the sums of absolute values over columns
 
template<int R, int C, typename P , typename B >
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. More...
 
template<int R, int C, typename P , typename B >
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. More...
 
template<int R, int C, typename P , typename B >
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. More...
 
template<int S, class P , class B >
bool TooN::isfinite (const Vector< S, P, B > &v)
 Returns true if every element is finite.
 
template<int S, class P , class B >
bool TooN::isnan (const Vector< S, P, B > &v)
 Returns true if any element is NaN.
 
template<int Rows, int Cols, typename Precision , typename Base >
void TooN::Symmetrize (Matrix< Rows, Cols, Precision, Base > &m)
 Symmetrize a matrix. More...
 
template<int Rows, int Cols, typename Precision , typename Base >
Precision TooN::trace (const Matrix< Rows, Cols, Precision, Base > &m)
 computes the trace of a square matrix
 
template<int Size, class P , class B >
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 More...
 
template<int R, int C, class Precision , class Base >
Internal::MatrixStartFill< R, C, Precision, Base > TooN::Fill (Matrix< R, C, Precision, Base > &m)
 Set up a matrix for filling. More...
 
template<int Size, class Precision , class Base >
Internal::VectorStartFill< Size, Precision, Base > TooN::Fill (Vector< Size, Precision, Base > &v)
 Set up a vector for filling. More...
 
template<int Rows, int Cols>
Matrix< Rows, Cols, double, Reference::RowMajorTooN::wrapMatrix (double *data)
 Wrap external data as a Matrix As usual, if template sizes are provided, then the run-time size is only used if the template size is not Dynamic.
 
template<int Rows, int Cols>
const Matrix< Rows, Cols, const double, Reference::RowMajorTooN::wrapMatrix (const double *data)
 
template<int Rows, int Cols, class Precision >
Matrix< Rows, Cols, Precision, Reference::RowMajorTooN::wrapMatrix (Precision *data)
 
template<int Rows, int Cols, class Precision >
const Matrix< Rows, Cols, const Precision, Reference::RowMajorTooN::wrapMatrix (const Precision *data)
 
template<int Rows, int Cols>
Matrix< Rows, Cols, double, Reference::RowMajorTooN::wrapMatrix (double *data, int rows, int cols)
 
template<int Rows, int Cols>
const Matrix< Rows, Cols, const double, Reference::RowMajorTooN::wrapMatrix (const double *data, int rows, int cols)
 
template<int Rows, int Cols, class Precision >
Matrix< Rows, Cols, Precision, Reference::RowMajorTooN::wrapMatrix (Precision *data, int rows, int cols)
 
template<int Rows, int Cols, class Precision >
const Matrix< Rows, Cols, const Precision, Reference::RowMajorTooN::wrapMatrix (const Precision *data, int rows, int cols)
 
template<class Precision >
Matrix< Dynamic, Dynamic, Precision, Reference::RowMajorTooN::wrapMatrix (Precision *data, int rows, int cols)
 
template<class Precision >
const Matrix< Dynamic, Dynamic, const Precision, Reference::RowMajorTooN::wrapMatrix (const Precision *data, int rows, int cols)
 

Detailed Description

Vector and Matrix classes, and helpers.

Function Documentation

◆ cross_product_matrix()

template<int Size, class P , class B >
TooN::Matrix<3, 3, P> TooN::cross_product_matrix ( const Vector< Size, P, B > &  vec)
inline

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

◆ determinant()

template<int R, int C, class P , class B >
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.

◆ determinant_gaussian_elimination()

template<int R, int C, typename Precision , typename Base >
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.

◆ exp()

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

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

◆ Fill() [1/4]

template<int Size, class Precision , class Base >
void TooN::Fill ( Vector< Size, Precision, Base > &  v,
const Precision &  p 
)

◆ Fill() [2/4]

template<int Rows, int Cols, class Precision , class Base >
void TooN::Fill ( Matrix< Rows, Cols, Precision, Base > &  m,
const Precision &  p 
)

◆ Fill() [3/4]

template<int R, int C, class Precision , class Base >
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

◆ Fill() [4/4]

template<int Size, class Precision , class Base >
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

◆ log()

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

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

◆ norm()

template<int Size, class Precision , class Base >
Precision TooN::norm ( const Vector< Size, Precision, Base > &  v)
inline

Compute the \(L_2\) norm of v.

Parameters
vv

◆ norm_1()

template<int Size, class Precision , class Base >
Precision TooN::norm_1 ( const Vector< Size, Precision, Base > &  v)
inline

Compute the \(L_1\) norm of v.

Parameters
vv

◆ norm_2()

template<int Size, class Precision , class Base >
Precision TooN::norm_2 ( const Vector< Size, Precision, Base > &  v)
inline

Compute the \(L_2\) norm of v.

Synonym for norm()

Parameters
vv

◆ norm_fro()

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

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

Parameters
mm

◆ norm_inf()

template<int Size, class Precision , class Base >
Precision TooN::norm_inf ( const Vector< Size, Precision, Base > &  v)
inline

Compute the \(L_\infty\) norm of v.

Parameters
vv

◆ norm_sq()

template<int Size, class Precision , class Base >
Precision TooN::norm_sq ( const Vector< Size, Precision, Base > &  v)
inline

Compute the \(L_2^2\) norm of v.

Parameters
vv

◆ normalize()

template<int Size, class Precision , class Base >
void TooN::normalize ( Vector< Size, Precision, Base > &&  v)
inline

Normalize a vector in place.

Parameters
vVector to normalize

◆ project()

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

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

Parameters
vv

◆ sqrt()

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

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

◆ Symmetrize()

template<int Rows, int Cols, typename Precision , typename Base >
void TooN::Symmetrize ( Matrix< Rows, Cols, Precision, Base > &  m)

Symmetrize a matrix.

Parameters
mm
Returns
\( \frac{m + m^{\mathsf T}}{2} \)

◆ unit()

template<int Size, class Precision , class Base >
Vector<Size, Precision> TooN::unit ( const Vector< Size, Precision, Base > &  v)
inline

Compute a the unit vector \(\hat{v}\).

Parameters
vv

◆ unproject()

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

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

Parameters
vv