MTL 4: mtl::matrix Namespace Reference
Functions | |
template<typename Value , typename Parameters , typename VectorX , typename VectorB > | |
int | umfpack_solve (const compressed2D< Value, Parameters > &A, VectorX &x, const VectorB &b) |
Solve A*x == b with umfpack. | |
template<typename Matrix , typename Value > | |
void | diagonal_setup (Matrix &matrix, const Value &value) |
Setup a matrix to a multiple of the unity matrix. | |
template<typename Matrix , typename Value > | |
void | hessian_setup (Matrix &A, Value factor) |
Fills a matrix A with A[i][j] = factor * (i + j). | |
template<typename Matrix > | |
void | check_hessian_matrix_product (Matrix const &C, typename Matrix::size_type reduced_dim, double factor=1.0) |
Check if matrix C is A * B with A and B set by hessian_setup. | |
template<typename Matrix > | |
void | laplacian_setup (Matrix &matrix, unsigned m, unsigned n) |
Setup a matrix according to a Laplacian equation on a 2D-grid using a five-point-stencil. | |
template<typename Matrix > | |
traits::lower< Matrix >::type | lower (const Matrix &A) |
Lower triangular matrix. | |
template<typename Value , typename PermutationVector > | |
traits::permutation< Value >::type | permutation (const PermutationVector &v) |
Computes permutation matrix from corresponding vector. | |
template<typename Value , typename ReorderVector > | |
traits::reorder< Value >::type | reorder (const ReorderVector &v, std::size_t cols=0) |
Computes reordering matrix from corresponding vector. | |
template<typename ReorderVector , typename Matrix > | |
Matrix | reorder_matrix_rows (const ReorderVector &v, const Matrix &A) |
Reorder the rows of a matrix without creating a reorder matrix. | |
template<typename Matrix > | |
traits::strict_lower< Matrix > ::type | strict_lower (const Matrix &A) |
Strict lower triangular matrix. | |
template<typename Matrix > | |
traits::strict_lower< Matrix > ::type | tril (const Matrix &A, long d=0) |
Triangle-lower starting at off-diagonoal d (for compatibility with matlib). | |
template<typename Matrix > | |
traits::strict_upper< Matrix > ::type | strict_upper (const Matrix &A) |
Strict upper triangle matrix. | |
template<typename Matrix > | |
traits::strict_upper< Matrix > ::type | triu (const Matrix &A, long d=0) |
Triangle-upper starting at off-diagonoal d (for compatibility with matlib). | |
template<typename Matrix > | |
traits::upper< Matrix >::type | upper (const Matrix &A) |
Upper triangular matrix. | |
template<typename LinOp > | |
traits::adjoint< LinOp >::type | adjoint (const LinOp &A) |
Adjoint linear operator, typically Hermitian transposed. | |
template<typename Matrix , typename Functor > | |
void | assign_each_nonzero (Matrix &m, const Functor &f) |
Assign the result of f(i) to each non-zero i in non-constant matrix A . | |
template<typename Matrix > | |
mtl::traits::enable_if_matrix < Matrix, conj_view< Matrix > >::type | conj (const Matrix &v) |
Conjugate of a matrix. | |
template<typename T > | |
mtl::traits::enable_if_matrix < T, T & >::type | crop (T &x) |
Remove all zero entries from a collection. | |
template<typename Matrix > | |
dense_vector< typename Collection< Matrix > ::value_type > | diagonal (const Matrix &A) |
Return the vector with the diagonal of the matrix. | |
template<typename Matrix > | |
dense_vector< typename Collection< Matrix > ::value_type > | qr_sym_imp (const Matrix &A) |
Eigenvalues of symmetric matrix A with implicit QR algorithm. | |
template<typename Matrix > | |
dense_vector< typename Collection< Matrix > ::value_type > | qr_algo (const Matrix &A, typename Collection< Matrix >::size_type itMax) |
Evaluation of eigenvalues with QR-Algorithm of matrix A. | |
template<typename Matrix > | |
dense_vector< typename Collection< Matrix > ::value_type > | eigenvalue_symmetric (const Matrix &A, typename Collection< Matrix >::size_type itMax=0) |
Calculation of eigenvalues of symmetric matrix A. | |
template<typename Matrix , typename Value > | |
bool | entry_similar (const Matrix &A, typename Collection< Matrix >::size_type i, typename Collection< Matrix >::size_type j, const Value &v, const Value &eps) |
Compares A[i][j] with v returns false if larger than eps. | |
template<typename Matrix > | |
RealMagnitude< typename Collection< Matrix > ::value_type >::type | frobenius_norm (const Matrix &matrix) |
Frobenius norm, i.e. square root of sum of squares of all entries sqrt(sum_i sum_j(|a[i][j]|^2)). | |
template<typename Matrix > | |
mtl::traits::enable_if_matrix < Matrix, hermitian_view < Matrix > >::type | hermitian (const Matrix &matrix) |
Returns hermitian view of matrix A. | |
template<typename Matrix > | |
Matrix | hessenberg_factors (const Matrix &A) |
Hessenberg-Factorization of matrix A with householder-vectors. | |
template<typename Matrix > | |
Matrix | extract_householder_hessenberg (const Matrix &H) |
Extract Householder vectors from Hessenberg factorization H of some A. | |
template<typename Matrix > | |
Matrix | householder_hessenberg (const Matrix &A) |
Compute Householder vectors from Hessenberg factorization of A. | |
template<typename Matrix > | |
Matrix | extract_hessenberg (const Matrix &H) |
Extract Hessenberg form from factorization H of some A. | |
template<typename Matrix > | |
Matrix | hessenberg (const Matrix &A) |
Hessenberg form of A. | |
template<typename Matrix > | |
Matrix | hessenberg_q (const Matrix &A) |
Return Q where Q'*A*Q == hessenberg(A). | |
template<unsigned long Unroll, typename Matrix > | |
mtl::traits::enable_if_matrix < Matrix, typename RealMagnitude< typename Collection< Matrix > ::value_type >::type >::type | infinity_norm (const Matrix &matrix) |
template<typename Matrix > | |
traits::inv< Matrix >::type | inv_upper (Matrix const &A) |
Invert upper triangular matrix. | |
template<typename Matrix > | |
traits::inv< Matrix >::type | inv_lower (Matrix const &A) |
Invert lower triangular matrix. | |
template<typename Matrix > | |
traits::inv< Matrix >::type | inv (Matrix const &A) |
Invert matrix. | |
template<typename Matrix > | |
void | invert_diagonal (Matrix &matrix) |
Returns matrix with invert diagonal. | |
template<typename Factor , typename Matrix > | |
mtl::traits::enable_if_matrix < Matrix, Matrix & >::type | left_scale_inplace (const Factor &alpha, Matrix &A) |
Scale matrix c from left with scalar or matrix factor alpha ; c is altered. | |
template<typename Matrix , typename Functor > | |
void | look_at_each_nonzero (const Matrix &A, Functor &f) |
Perform a potentially mutating f (A[i][j]) on each non-zero entry in matrix A . | |
template<typename Matrix , typename Functor > | |
mtl::traits::enable_if_matrix < Matrix >::type | look_at_each_nonzero_pos (const Matrix &A, Functor &f) |
Perform a potentially mutating f (A[i][j], make_pair(i, j)) on each non-zero entry in matrix A . | |
template<typename Matrix , typename Vector > | |
Vector | lower_trisolve (const Matrix &A, const Vector &v) |
Solves the lower triangular matrix A with the rhs v and returns the solution vector. | |
template<typename Matrix , typename Vector > | |
Vector | unit_lower_trisolve (const Matrix &A, const Vector &v) |
Solves the lower triangular matrix A (only one's in the diagonal) with the rhs v and returns the solution vector. | |
template<typename Matrix , typename Vector > | |
Vector | inverse_lower_trisolve (const Matrix &A, const Vector &v) |
Solves the lower triangular matrix A (inverse the diagonal) with the rhs v and returns the solution vector. | |
template<typename Matrix > | |
void | lu (Matrix &LU) |
LU factorization in place (without pivoting and optimization so far). | |
template<typename Matrix , typename PermuationVector > | |
void | lu (Matrix &A, PermuationVector &P) |
LU factorization in place (with pivoting and without optimization so far). | |
template<typename Matrix > | |
Matrix | lu_f (const Matrix &A) |
LU factorization without factorization that returns the matrix. | |
template<typename Matrix , typename Vector > | |
Vector | lu_solve_straight (const Matrix &A, const Vector &b) |
Solve Ax = b by LU factorization without pivoting; vector x is returned. | |
template<typename Matrix , typename PermVector , typename Vector > | |
Vector | lu_apply (const Matrix &LU, const PermVector &P, const Vector &b) |
Apply the factorization L*U with permutation P on vector b to solve Ax = b. | |
template<typename Matrix , typename Vector > | |
Vector | lu_solve (const Matrix &A, const Vector &b) |
Solve Ax = b by LU factorization with column pivoting; vector x is returned. | |
template<typename Matrix , typename PermVector , typename Vector > | |
Vector | lu_adjoint_apply (const Matrix &LU, const PermVector &P, const Vector &b) |
Apply the factorization L*U with permutation P on vector b to solve adjoint(A)x = b. | |
template<typename Matrix , typename Vector > | |
Vector | lu_adjoint_solve (const Matrix &A, const Vector &b) |
Solve adjoint(A)x = b by LU factorization with column pivoting; vector x is returned. | |
template<typename Matrix > | |
mtl::traits::enable_if_matrix < Matrix, std::pair< typename Collection< Matrix > ::size_type, typename Collection< Matrix > ::size_type > >::type | max_abs_pos (const Matrix &A) |
Returns pair (row, col) from absolut maximal entry of matrix A. | |
template<typename A , typename B , typename C > | |
mtl::traits::enable_if_matrix < A >::type | mult (const A &a, const B &b, C &c) |
Multiplication: mult(a, b, c) computes c= a * b;. | |
template<typename A , typename B , typename C > | |
mtl::traits::enable_if_matrix < A >::type | mult_add (const A &a, const B &b, C &c) |
Multiplication: mult_add(a, b, c) computes c+= a * b;. | |
template<typename A , typename X , typename Y , typename Z > | |
void | mult (const A &a, const X &x, const Y &y, Z &z) |
Four term multiplication: mult(a, x, y, z) computes z= a * x + y;. | |
template<typename MatrixA , typename MatrixB , typename MatrixC , typename Assign > | |
void | mat_mat_mult (const MatrixA &a, const MatrixB &b, MatrixC &c, Assign, tag::dense, tag::dense, tag::dense) |
Dense matrix multiplication. | |
template<typename MatrixA , typename MatrixB , typename MatrixC , typename Assign > | |
void | mat_mat_mult (const MatrixA &a, const MatrixB &b, MatrixC &c, Assign, tag::sparse, tag::sparse, tag::sparse) |
Sparse matrix multiplication. | |
template<typename MatrixA , typename MatrixB , typename MatrixC , typename Assign > | |
void | mat_mat_mult (const MatrixA &a, const MatrixB &b, MatrixC &c, Assign, tag::sparse, tag::dense, tag::dense) |
Product of sparse times dense matrix. | |
template<unsigned long Unroll, typename Matrix > | |
mtl::traits::enable_if_matrix < Matrix, typename RealMagnitude< typename Collection< Matrix > ::value_type >::type >::type | one_norm (const Matrix &matrix) |
template<typename Value > | |
ones_matrix< Value > | ones (std::size_t r, std::size_t c) |
Return r by c matrix with ones of type Value in all entries. | |
template<typename Op1 , typename Op2 > | |
mtl::traits::mult_result< Op1, Op2 >::type | operator* (const Op1 &op1, const Op2 &op2) |
Multiplication for all supported types of operations. | |
template<typename Op1 , typename Op2 > | |
mtl::traits::div_result< Op1, Op2 >::type | operator/ (const Op1 &op1, const Op2 &op2) |
Division of matrices and vectors by salars. | |
template<typename Matrix , typename Generator > | |
mtl::traits::enable_if_matrix < Matrix >::type | random (Matrix &A, Generator &generator) |
Fill matrix with random values; generator must be a nullary function. | |
template<typename Matrix > | |
mtl::traits::enable_if_matrix < Matrix >::type | random (Matrix &A) |
Fill matrix with random values. | |
template<typename Matrix , typename VectorX , typename VectorY > | |
void | rank_one_update (Matrix &matrix, const VectorX &x, const VectorY &y) |
Rank-one update: rank_one_update(A, x, y) computes A+= x * conj(y)^T. | |
template<typename Matrix , typename VectorX , typename VectorY > | |
void | rank_two_update (Matrix &matrix, const VectorX &x, const VectorY &y) |
Rank-two update: rank_two_update(A, x, y) computes A+= x * conj(y)^T + y * conj(x)^T. | |
template<typename Coll > | |
mtl::traits::enable_if_matrix < Coll >::type | set_to_zero (Coll &collection) |
template<typename Matrix > | |
sub_matrix_t< Matrix > ::sub_matrix_type | sub_matrix (Matrix &matrix, typename sub_matrix_t< Matrix >::size_type begin_row, typename sub_matrix_t< Matrix >::size_type end_row, typename sub_matrix_t< Matrix >::size_type begin_col, typename sub_matrix_t< Matrix >::size_type end_col) |
Returns sub-matrix B with begin_row, end_row, begin_col, end_col from matrix A. | |
template<typename Matrix > | |
void | svd (const Matrix &A, Matrix &S, Matrix &V, Matrix &D, double tol=10e-10) |
Returns A=S*V*D' for matrix A as references. | |
template<typename Matrix > | |
boost::tuple< Matrix, Matrix, Matrix > | svd (const Matrix &A, double tol=10e-10) |
Returns A=S*V*D' for matrix A as triplet. | |
template<typename Matrix > | |
mtl::traits::enable_if_matrix < Matrix >::type | swap_row (Matrix &A, typename Collection< Matrix >::size_type i, typename Collection< Matrix >::size_type j) |
Row i and j are swapped in matrix A. | |
template<typename Matrix , typename Vector > | |
Vector | upper_trisolve (const Matrix &A, const Vector &v) |
Solves the upper triangular matrix A with the rhs v and returns the solution vector. | |
template<typename Matrix , typename Vector > | |
Vector | unit_upper_trisolve (const Matrix &A, const Vector &v) |
Solves the upper triangular matrix A (only one's in the diagonal) with the rhs v and returns the solution vector. | |
template<typename Matrix , typename Vector > | |
Vector | inverse_upper_trisolve (const Matrix &A, const Vector &v) |
Solves the upper triangular matrix A (inverse the diagonal) with the rhs v and returns the solution vector. | |
template<typename Matrix , typename Vector , typename DiaTag > | |
Vector | upper_trisolve (const Matrix &A, const Vector &v, DiaTag) |
Solves the upper triangular matrix A with the rhs v and returns the solution vector. | |
template<typename Matrix > | |
recursator< Matrix > | north_west (const recursator< Matrix > &rec) |
template<typename Matrix > | |
recursator< Matrix > | north_east (const recursator< Matrix > &rec) |
template<typename Matrix > | |
recursator< Matrix > | south_west (const recursator< Matrix > &rec) |
template<typename Matrix > | |
recursator< Matrix > | south_east (const recursator< Matrix > &rec) |
template<typename Matrix > | |
bool | is_empty (const recursator< Matrix > &rec) |
template<typename Matrix > | |
bool | is_full (const recursator< Matrix > &rec) |
template<typename Matrix > | |
recursator< Matrix >::size_type | num_rows (const recursator< Matrix > &rec) |
template<typename Matrix > | |
recursator< Matrix >::size_type | num_cols (const recursator< Matrix > &rec) |
template<typename Matrix > | |
recursator< Matrix >::size_type | size (const recursator< Matrix > &rec) |
void mtl::matrix::check_hessian_matrix_product | ( | Matrix const & | C, | |
typename Matrix::size_type | reduced_dim, | |||
double | factor = 1.0 | |||
) | [inline] |
Check if matrix C is A * B with A and B set by hessian_setup.
C has dimensions M x L and reduced_dim is N, see hessian_setup.
mtl::traits::enable_if_matrix<T, T&>::type mtl::matrix::crop | ( | T & | x | ) | [inline] |
Remove all zero entries from a collection.
Does nothing for dense collections
void mtl::matrix::diagonal_setup | ( | Matrix & | matrix, | |
const Value & | value | |||
) | [inline] |
Setup a matrix to a multiple of the unity matrix.
Intended for sparse matrices but works also with dense matrices. If the value is 0 the matrix is only zeroed out, whereby a sparse matrix will be empty after this operation, i.e. the zeros on the diagonal are not explicitly stored. The diagonal in its generalized form is the set of entries with equal row and column index (since r6843, older revision considered it erroneous to store a non-zero scalar to a non-square matrix).
bool mtl::matrix::entry_similar | ( | const Matrix & | A, | |
typename Collection< Matrix >::size_type | i, | |||
typename Collection< Matrix >::size_type | j, | |||
const Value & | v, | |||
const Value & | eps | |||
) | [inline] |
Compares A[i][j] with v
returns false if larger than eps.
Function works on distributed matrices where only one process tests and the other return true. The functions enables writing tests that work in parallel (and all other platforms).
Matrix mtl::matrix::hessenberg_factors | ( | const Matrix & | A | ) | [inline] |
void mtl::matrix::hessian_setup | ( | Matrix & | A, | |
Value | factor | |||
) | [inline] |
mtl::traits::enable_if_matrix<Matrix, typename RealMagnitude<typename Collection<Matrix>::value_type>::type>::type mtl::matrix::infinity_norm | ( | const Matrix & | matrix | ) | [inline] |
traits::inv<Matrix>::type mtl::matrix::inv | ( | Matrix const & | A | ) | [inline] |
Invert matrix.
Uses pivoting LU factorization and triangular inversion
bool mtl::matrix::is_empty | ( | const recursator< Matrix > & | rec | ) | [inline] |
Check if a recursator (i.e. its referred matrix) is empty.
bool mtl::matrix::is_full | ( | const recursator< Matrix > & | rec | ) | [inline] |
Check if a recursator (i.e. its referred matrix) fills the entire block, i.e. if the number of rows and columns are both equal to the virtual bound.
void mtl::matrix::laplacian_setup | ( | Matrix & | matrix, | |
unsigned | m, | |||
unsigned | n | |||
) | [inline] |
Vector mtl::matrix::lu_adjoint_apply | ( | const Matrix & | LU, | |
const PermVector & | P, | |||
const Vector & | b | |||
) | [inline] |
Apply the factorization L*U with permutation P on vector b to solve adjoint(A)x = b.
That is P^{-1}(LU)^H x = b --> x= P^{-1}L^{-H} U^{-H} b where P^{-1}^{-1}^H = P^{-1}
void mtl::matrix::mat_mat_mult | ( | const MatrixA & | a, | |
const MatrixB & | b, | |||
MatrixC & | c, | |||
Assign | , | |||
tag::sparse | , | |||
tag::dense | , | |||
tag::dense | ||||
) | [inline] |
Product of sparse times dense matrix.
This function (specialization of mult) is intended to multiply sparse matrices with multiple matrices gathered into a dense matrix. Likewise, the resulting dense matrix corresponds to multiple vectors. The default functor for this operation is:
void mtl::matrix::mat_mat_mult | ( | const MatrixA & | a, | |
const MatrixB & | b, | |||
MatrixC & | c, | |||
Assign | , | |||
tag::dense | , | |||
tag::dense | , | |||
tag::dense | ||||
) | [inline] |
Dense matrix multiplication.
The function for dense matrix multiplication defines a default multiplication functor. Alternatively the user can define his own functors for specific triplets of matrix types, see detail::dmat_dmat_mult_specialize. The default functor for dense matrix multiplication is:
Use user-defined functor if provided (assign mode can be arbitrary)
Finally substitute assign mode (consistently)
void mtl::matrix::mult | ( | const A & | a, | |
const X & | x, | |||
const Y & | y, | |||
Z & | z | |||
) | [inline] |
Four term multiplication: mult(a, x, y, z) computes z= a * x + y;.
The 4 types must be compatible, i.e. a*x must be assignable to z and z must be incrementable by y. Right now, it is not more efficient than z= a * x; z+= y. For compatibility with MTL2.
mtl::traits::enable_if_matrix<A>::type mtl::matrix::mult | ( | const A & | a, | |
const B & | b, | |||
C & | c | |||
) | [inline] |
Multiplication: mult(a, b, c) computes c= a * b;.
The 3 types must be compatible, e.g. all three matrices or b and c are column vectors and a is a matrix. The dimensions are checked at compile time.
mtl::traits::enable_if_matrix<A>::type mtl::matrix::mult_add | ( | const A & | a, | |
const B & | b, | |||
C & | c | |||
) | [inline] |
Multiplication: mult_add(a, b, c) computes c+= a * b;.
The 3 types must be compatible, e.g. all three matrices or b and c are column vectors and a is a matrix. The dimensions are checked at compile time.
recursator<Matrix> mtl::matrix::north_east | ( | const recursator< Matrix > & | rec | ) | [inline] |
Compute the north-east quadrant of a recursator (i.e. its referred matrix). The result is itself a recursator.
recursator<Matrix> mtl::matrix::north_west | ( | const recursator< Matrix > & | rec | ) | [inline] |
Compute the north-west quadrant of a recursator (i.e. its referred matrix). The result is itself a recursator.
recursator<Matrix>::size_type mtl::matrix::num_cols | ( | const recursator< Matrix > & | rec | ) | [inline] |
The number of columns that a sub-matrix would have if it was constructed.
recursator<Matrix>::size_type mtl::matrix::num_rows | ( | const recursator< Matrix > & | rec | ) | [inline] |
The number of rows that a sub-matrix would have if it was constructed.
mtl::traits::enable_if_matrix<Matrix, typename RealMagnitude<typename Collection<Matrix>::value_type>::type>::type mtl::matrix::one_norm | ( | const Matrix & | matrix | ) | [inline] |
mtl::traits::mult_result<Op1, Op2>::type mtl::matrix::operator* | ( | const Op1 & | op1, | |
const Op2 & | op2 | |||
) | [inline] |
Multiplication for all supported types of operations.
Enable-if-like technique make sure that only called when properly defined
mtl::traits::div_result<Op1,Op2>::type mtl::matrix::operator/ | ( | const Op1 & | op1, | |
const Op2 & | op2 | |||
) | [inline] |
Division of matrices and vectors by salars.
Enable-if-like technique make sure that only called when properly defined
mtl::traits::enable_if_matrix<Matrix>::type mtl::matrix::random | ( | Matrix & | A | ) | [inline] |
Fill matrix with random values.
Currently done with rand(). Will be improved one day. You can provide your own generator as second argument.
void mtl::matrix::rank_one_update | ( | Matrix & | matrix, | |
const VectorX & | x, | |||
const VectorY & | y | |||
) | [inline] |
Rank-one update: rank_one_update(A, x, y) computes A+= x * conj(y)^T.
The current implementation works for column and row vectors (although the notation above refers to column vectors).
void mtl::matrix::rank_two_update | ( | Matrix & | matrix, | |
const VectorX & | x, | |||
const VectorY & | y | |||
) | [inline] |
Rank-two update: rank_two_update(A, x, y) computes A+= x * conj(y)^T + y * conj(x)^T.
The current implementation works for column and row vectors (although the notation above refers to column vectors).
Matrix mtl::matrix::reorder_matrix_rows | ( | const ReorderVector & | v, | |
const Matrix & | A | |||
) | [inline] |
mtl::traits::enable_if_matrix<Coll>::type mtl::matrix::set_to_zero | ( | Coll & | collection | ) | [inline] |
Sets all values of a collection to 0 More spefically the defined multiplicative identity element
recursator<Matrix>::size_type mtl::matrix::size | ( | const recursator< Matrix > & | rec | ) | [inline] |
The number of elements (rows times columns) that a sub-matrix would have if it was constructed.
recursator<Matrix> mtl::matrix::south_east | ( | const recursator< Matrix > & | rec | ) | [inline] |
Compute the south-east quadrant of a recursator (i.e. its referred matrix). The result is itself a recursator.
recursator<Matrix> mtl::matrix::south_west | ( | const recursator< Matrix > & | rec | ) | [inline] |
Compute the south-west quadrant of a recursator (i.e. its referred matrix). The result is itself a recursator.
int mtl::matrix::umfpack_solve | ( | const compressed2D< Value, Parameters > & | A, | |
VectorX & | x, | |||
const VectorB & | b | |||
) | [inline] |
Solve A*x == b with umfpack.
Only available when compiled with enabled macro MTL_HAS_UMFPACK. Uses classes umfpack::solver internally. If you want more control on single operations or to keep umfpack's internal factorization, use this class.
mtl::matrix Namespace Reference -- MTL 4 -- Peter Gottschling and Andrew Lumsdaine
-- Gen. with
rev. 7542
on 7 Apr 2011 by doxygen 1.5.9 -- © 2010 by SimuNova UG.