HyperHDG
|
#include <HyperHDG/hy_assert.hxx>
#include <array>
#include <cmath>
#include <ostream>
#include <vector>
#include <HyperHDG/wrapper/lapack.hxx>
Go to the source code of this file.
Classes | |
struct | SmallMatDivByZeroException |
Exception to be thrown if division by zero appears. More... | |
class | SmallMat< n_rowsT, n_colsT, mat_entry_t > |
This class implements a small/dense matrix. More... | |
Typedefs | |
template<unsigned int n_rows, typename mat_entry_t = double> | |
using | SmallSquareMat = SmallMat< n_rows, n_rows, mat_entry_t > |
A SmallSquareMat is a SmallMat, which is square. More... | |
template<unsigned int n_rows, typename mat_entry_t = double> | |
using | SmallVec = SmallMat< n_rows, 1, mat_entry_t > |
A SmallVec is a SmallMat of one column, where the standard mat_entry_t is double. More... | |
template<unsigned int n_rows, typename mat_entry_t = float> | |
using | Point = SmallVec< n_rows, mat_entry_t > |
A Point is a SmallMat of one column, where the standard mat_entry_t is float. More... | |
Functions | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | diagonal (const mat_entry_t diag_value) |
Create SmallMat that is a diagonal matrix with specified value on diagonal. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t , unsigned int n_vec> | |
SmallMat< n_rows, n_cols, mat_entry_t > | diagonal (const SmallMat< n_vec, 1, mat_entry_t > &diag) |
Create SmallMat that is a diagonal matrix with specified value on diagonal. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | rep_mat (const SmallMat< n_rows, 1, mat_entry_t > rep_vec) |
Create SmallMat that repeats given column vector. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | dyadic_product (const SmallMat< n_rows, 1, mat_entry_t > &left, const SmallMat< n_cols, 1, mat_entry_t > &right) |
Create dyadic product of two small vectors. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_cols, n_rows, mat_entry_t > | transposed (SmallMat< n_rows, n_cols, mat_entry_t > mat) |
Transpose given matrix. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
mat_entry_t | scalar_product (const SmallMat< n_rows, n_cols, mat_entry_t > &left, const SmallMat< n_rows, n_cols, mat_entry_t > &right) |
Euclidean scalar product of two SmallVecs / Frobenius scalar product for two SmallMats. More... | |
template<unsigned int n_rows, unsigned int n_cols_left, unsigned int n_cols_right, typename mat_entry_t > | |
SmallMat< n_rows, std::max(n_cols_left, n_cols_right), mat_entry_t > | operator+ (const SmallMat< n_rows, n_cols_left, mat_entry_t > &left, const SmallMat< n_rows, n_cols_right, mat_entry_t > &right) |
Add two small / dense matrices. More... | |
template<unsigned int n_rows, unsigned int n_cols_left, unsigned int n_cols_right, typename mat_entry_t > | |
SmallMat< n_rows, std::max(n_cols_left, n_cols_right), mat_entry_t > | operator- (const SmallMat< n_rows, n_cols_left, mat_entry_t > &left, const SmallMat< n_rows, n_cols_right, mat_entry_t > &right) |
Subtract second small/dense matrix from first. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | hada_prod (const SmallMat< n_rows, n_cols, mat_entry_t > &left, const SmallMat< n_rows, n_cols, mat_entry_t > &right) |
Hadamard product of two small/dense matrices. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | hada_divi (const SmallMat< n_rows, n_cols, mat_entry_t > &left, const SmallMat< n_rows, n_cols, mat_entry_t > &right) |
Divide first small/dense matrix element-wise by second. More... | |
template<unsigned int n_rowsA, unsigned int n_colsA, unsigned int n_colsB, typename mat_entry_t > | |
SmallMat< n_rowsA, n_colsB, mat_entry_t > | operator* (const SmallMat< n_rowsA, n_colsA, mat_entry_t > &A, const SmallMat< n_colsA, n_colsB, mat_entry_t > &B) |
Standard matrix–matrix multiplication. More... | |
template<unsigned int n_rowsA, unsigned int n_colsA, unsigned int n_rowsB, unsigned int n_colsB, typename mat_entry_t > | |
SmallMat< n_rowsA, n_colsB, mat_entry_t > | mat_times_mat_unfit (const SmallMat< n_rowsA, n_colsA, mat_entry_t > &A, const SmallMat< n_rowsB, n_colsB, mat_entry_t > &B) |
Standard matrix–matrix multiplication with non-fitting dimensions. More... | |
template<unsigned int n_rowsA, unsigned int n_colsA, unsigned int n_colsB, typename mat_entry_t > | |
SmallMat< n_colsA, n_colsB, mat_entry_t > | transposed_mat_times_mat (const SmallMat< n_rowsA, n_colsA, mat_entry_t > &A, const SmallMat< n_rowsA, n_colsB, mat_entry_t > &B) |
Transpose first small/dense matrix and multiply it with second. More... | |
template<unsigned int n_rowsA, unsigned int n_colsA, unsigned int n_rowsB, typename mat_entry_t > | |
SmallMat< n_rowsA, n_rowsB, mat_entry_t > | mat_times_transposed_mat (const SmallMat< n_rowsA, n_colsA, mat_entry_t > &A, const SmallMat< n_rowsB, n_colsA, mat_entry_t > &B) |
Multiply first matrix with transposed of second second. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | operator+ (const mat_entry_t &scalar, const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Add small/dense matrix to scalar. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | operator+ (const SmallMat< n_rows, n_cols, mat_entry_t > &mat, const mat_entry_t &scalar) |
Add scalar to small/dense matrix. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | operator- (const mat_entry_t &scalar, const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Subtract small/dense matrix from scalar. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | operator- (const SmallMat< n_rows, n_cols, mat_entry_t > &mat, const mat_entry_t &scalar) |
Subtract scalar from small/dense matrix. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | operator* (const mat_entry_t &scalar, const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Multiply scalar with small/dense matrix. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | operator* (const SmallMat< n_rows, n_cols, mat_entry_t > &mat, const mat_entry_t &scalar) |
Multiply small/dense matrix with scalar. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | operator/ (const mat_entry_t &scalar, const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Divide scalar by small/dense matrix. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_cols, mat_entry_t > | operator/ (const SmallMat< n_rows, n_cols, mat_entry_t > &mat, const mat_entry_t &scalar) |
Divide small/dense matrix by scalar. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
mat_entry_t | norm_1 (const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Column sum norm of a small/dense matrix. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
mat_entry_t | norm_2 (const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Euclidean norm of a small/dense vector. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
mat_entry_t | norm_infty (const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Row sum norm of a small/dense matrix. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
mat_entry_t | norm_p (const SmallMat< n_rows, n_cols, mat_entry_t > &mat, const mat_entry_t power) |
p-norm of a small/dense vector. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
mat_entry_t | entries_product (const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Return product of all entries. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
std::ostream & | operator<< (std::ostream &stream, const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Fill std::ostream with small/dense matrix. More... | |
template<unsigned int n_rowsA, unsigned int n_colsB, typename mat_entry_t > | |
SmallMat< n_rowsA, n_colsB, mat_entry_t > | operator/ (SmallMat< n_rowsA, n_colsB, mat_entry_t > &b, SmallMat< n_rowsA, n_rowsA, mat_entry_t > &A) |
Solve linear system of equations A * x = b <=> x = A / b. More... | |
template<unsigned int n_rowsA, unsigned int n_colsB, typename mat_entry_t > | |
SmallMat< n_rowsA, n_colsB, mat_entry_t > | operator/ (const SmallMat< n_rowsA, n_colsB, mat_entry_t > &b, const SmallMat< n_rowsA, n_rowsA, mat_entry_t > &A) |
Solve linear system of equations A * x = b <=> x = A / b. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_rows, mat_entry_t > | qr_decomp_q (SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Matrix Q of Householder QR decomposition. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
SmallMat< n_rows, n_rows, mat_entry_t > | qr_decomp_q (const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Matrix Q of Householder QR decomposition. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
void | qr_decomp (SmallMat< n_rows, n_cols, mat_entry_t > &mat, SmallSquareMat< n_rows, mat_entry_t > &mat_q, SmallSquareMat< n_cols, mat_entry_t > &mat_r) |
Normalized QR decomposition. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
void | qr_decomp (const SmallMat< n_rows, n_cols, mat_entry_t > &mat, SmallSquareMat< n_rows, mat_entry_t > &mat_q, SmallSquareMat< n_cols, mat_entry_t > &mat_r) |
Normalized QR decomposition. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
mat_entry_t | determinant (SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Determinant of a rectangular system. More... | |
template<unsigned int n_rows, unsigned int n_cols, typename mat_entry_t > | |
mat_entry_t | determinant (const SmallMat< n_rows, n_cols, mat_entry_t > &mat) |
Determinant of a rectangular system. More... | |
using Point = SmallVec<n_rows, mat_entry_t> |
A Point is a SmallMat of one column, where the standard mat_entry_t is float.
using SmallSquareMat = SmallMat<n_rows, n_rows, mat_entry_t> |
A SmallSquareMat is a SmallMat, which is square.
using SmallVec = SmallMat<n_rows, 1, mat_entry_t> |
A SmallVec is a SmallMat of one column, where the standard mat_entry_t is double.
mat_entry_t determinant | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ) |
Determinant of a rectangular system.
Calculate the generalized determinant of a rectangular matrix. If the matrix is square, this is the standard determinant. The determinant is determined by doing a QR decomposition based on Householder transformations. Thus det(Q) = +1, if the number of rows if even and det(Q) = -1, if the number of rows is odd. This number is multiplied by the diagonal entries of R.
mat_entry_t determinant | ( | SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ) |
Determinant of a rectangular system.
Calculate the generalized determinant of a rectangular matrix. If the matrix is square, this is the standard determinant. The determinant is determined by doing a QR decomposition based on Householder transformations. Thus det(Q) = +1, if the number of rows if even and det(Q) = -1, if the number of rows is odd. This number is multiplied by the diagonal entries of R.
The matrix is destroyed using this function. Its entries might be used to generate matrices Q and R of the QR descomposition.
SmallMat<n_rows, n_cols, mat_entry_t> diagonal | ( | const mat_entry_t | diag_value | ) |
Create SmallMat that is a diagonal matrix with specified value on diagonal.
diag_value | Diagonal value. |
diag_mat | Diagonal matrix. |
SmallMat<n_rows, n_cols, mat_entry_t> diagonal | ( | const SmallMat< n_vec, 1, mat_entry_t > & | diag | ) |
Create SmallMat that is a diagonal matrix with specified value on diagonal.
diag | Diagonal vector. |
diag_mat | Diagonal matrix. |
SmallMat<n_rows, n_cols, mat_entry_t> dyadic_product | ( | const SmallMat< n_rows, 1, mat_entry_t > & | left, |
const SmallMat< n_cols, 1, mat_entry_t > & | right | ||
) |
Create dyadic product of two small vectors.
left | Left vector in dyadic product. |
right | Right vector in dyadic product. |
dyad_prod | Dyadic product of both vectors. |
mat_entry_t entries_product | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ) |
Return product of all entries.
SmallMat<n_rows, n_cols, mat_entry_t> hada_divi | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | left, |
const SmallMat< n_rows, n_cols, mat_entry_t > & | right | ||
) |
Divide first small/dense matrix element-wise by second.
SmallMat<n_rows, n_cols, mat_entry_t> hada_prod | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | left, |
const SmallMat< n_rows, n_cols, mat_entry_t > & | right | ||
) |
Hadamard product of two small/dense matrices.
SmallMat<n_rowsA, n_colsB, mat_entry_t> mat_times_mat_unfit | ( | const SmallMat< n_rowsA, n_colsA, mat_entry_t > & | A, |
const SmallMat< n_rowsB, n_colsB, mat_entry_t > & | B | ||
) |
Standard matrix–matrix multiplication with non-fitting dimensions.
SmallMat<n_rowsA, n_rowsB, mat_entry_t> mat_times_transposed_mat | ( | const SmallMat< n_rowsA, n_colsA, mat_entry_t > & | A, |
const SmallMat< n_rowsB, n_colsA, mat_entry_t > & | B | ||
) |
Multiply first matrix with transposed of second second.
mat_entry_t norm_1 | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ) |
Column sum norm of a small/dense matrix.
mat_entry_t norm_2 | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ) |
Euclidean norm of a small/dense vector.
mat_entry_t norm_infty | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ) |
Row sum norm of a small/dense matrix.
mat_entry_t norm_p | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat, |
const mat_entry_t | power | ||
) |
p-norm of a small/dense vector.
SmallMat<n_rows, n_cols, mat_entry_t> operator* | ( | const mat_entry_t & | scalar, |
const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ||
) |
Multiply scalar with small/dense matrix.
SmallMat<n_rows, n_cols, mat_entry_t> operator* | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat, |
const mat_entry_t & | scalar | ||
) |
Multiply small/dense matrix with scalar.
SmallMat<n_rowsA, n_colsB, mat_entry_t> operator* | ( | const SmallMat< n_rowsA, n_colsA, mat_entry_t > & | A, |
const SmallMat< n_colsA, n_colsB, mat_entry_t > & | B | ||
) |
Standard matrix–matrix multiplication.
SmallMat<n_rows, n_cols, mat_entry_t> operator+ | ( | const mat_entry_t & | scalar, |
const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ||
) |
Add small/dense matrix to scalar.
SmallMat<n_rows, n_cols, mat_entry_t> operator+ | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat, |
const mat_entry_t & | scalar | ||
) |
Add scalar to small/dense matrix.
SmallMat<n_rows, std::max(n_cols_left, n_cols_right), mat_entry_t> operator+ | ( | const SmallMat< n_rows, n_cols_left, mat_entry_t > & | left, |
const SmallMat< n_rows, n_cols_right, mat_entry_t > & | right | ||
) |
Add two small / dense matrices.
SmallMat<n_rows, n_cols, mat_entry_t> operator- | ( | const mat_entry_t & | scalar, |
const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ||
) |
Subtract small/dense matrix from scalar.
SmallMat<n_rows, n_cols, mat_entry_t> operator- | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat, |
const mat_entry_t & | scalar | ||
) |
Subtract scalar from small/dense matrix.
SmallMat<n_rows, std::max(n_cols_left, n_cols_right), mat_entry_t> operator- | ( | const SmallMat< n_rows, n_cols_left, mat_entry_t > & | left, |
const SmallMat< n_rows, n_cols_right, mat_entry_t > & | right | ||
) |
Subtract second small/dense matrix from first.
SmallMat<n_rows, n_cols, mat_entry_t> operator/ | ( | const mat_entry_t & | scalar, |
const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ||
) |
Divide scalar by small/dense matrix.
SmallMat<n_rows, n_cols, mat_entry_t> operator/ | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat, |
const mat_entry_t & | scalar | ||
) |
Divide small/dense matrix by scalar.
SmallMat<n_rowsA, n_colsB, mat_entry_t> operator/ | ( | const SmallMat< n_rowsA, n_colsB, mat_entry_t > & | b, |
const SmallMat< n_rowsA, n_rowsA, mat_entry_t > & | A | ||
) |
Solve linear system of equations A * x = b <=> x = A / b.
SmallMat<n_rowsA, n_colsB, mat_entry_t> operator/ | ( | SmallMat< n_rowsA, n_colsB, mat_entry_t > & | b, |
SmallMat< n_rowsA, n_rowsA, mat_entry_t > & | A | ||
) |
Solve linear system of equations A * x = b <=> x = A / b.
std::ostream& operator<< | ( | std::ostream & | stream, |
const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ||
) |
Fill std::ostream
with small/dense matrix.
void qr_decomp | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat, |
SmallSquareMat< n_rows, mat_entry_t > & | mat_q, | ||
SmallSquareMat< n_cols, mat_entry_t > & | mat_r | ||
) |
Normalized QR decomposition.
Do a QR decomposition of the matrix mat
and write result into mat_q
(matrix Q of QR decomposition), and mat_r
is a square matrix with n_cols
rows and columns containing R (without some entries).
mat | Matrix that is to be QR decomposed. |
mat_q | Matrix containing space for Q of QR decomposition. |
mat_r | Matrix containing space for reduced R of QR decomposition. |
mat_q | Matrix Q of QR decomposition. |
mat_r | Reduced matrix R of QR decomposition. |
void qr_decomp | ( | SmallMat< n_rows, n_cols, mat_entry_t > & | mat, |
SmallSquareMat< n_rows, mat_entry_t > & | mat_q, | ||
SmallSquareMat< n_cols, mat_entry_t > & | mat_r | ||
) |
Normalized QR decomposition.
Do a QR decomposition of the matrix mat
and write result into mat_q
(matrix Q of QR decomposition), and mat
(matrix R of QR decomposition). Moreover, mat_r
is a square matrix with n_cols
rows and columns containing R (without some entries).
mat | Matrix that is to be QR decomposed. |
mat_q | Matrix containing space for Q of QR decomposition. |
mat_r | Matrix containing space for reduced R of QR decomposition. |
mat | Matrix R of QR decomposition. |
mat_q | Matrix Q of QR decomposition. |
mat_r | Reduced matrix R of QR decomposition. |
SmallMat<n_rows, n_rows, mat_entry_t> qr_decomp_q | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ) |
Matrix Q of Householder QR decomposition.
Note that Q might be different from the matrix Q attained from qr_decomp
.
SmallMat<n_rows, n_rows, mat_entry_t> qr_decomp_q | ( | SmallMat< n_rows, n_cols, mat_entry_t > & | mat | ) |
Matrix Q of Householder QR decomposition.
Note that Q might be different from the matrix Q attained from qr_decomp
.
SmallMat<n_rows, n_cols, mat_entry_t> rep_mat | ( | const SmallMat< n_rows, 1, mat_entry_t > | rep_vec | ) |
Create SmallMat that repeats given column vector.
rep_vec | Column vector that is to be repeated. |
rep_mat | Matrix whose columns coincide with given vector. |
mat_entry_t scalar_product | ( | const SmallMat< n_rows, n_cols, mat_entry_t > & | left, |
const SmallMat< n_rows, n_cols, mat_entry_t > & | right | ||
) |
Euclidean scalar product of two SmallVecs / Frobenius scalar product for two SmallMats.
SmallMat<n_cols, n_rows, mat_entry_t> transposed | ( | SmallMat< n_rows, n_cols, mat_entry_t > | mat | ) |
Transpose given matrix.
mat | Matrix to be transposed. |
transposed | Transposed of the given matrix. |
SmallMat<n_colsA, n_colsB, mat_entry_t> transposed_mat_times_mat | ( | const SmallMat< n_rowsA, n_colsA, mat_entry_t > & | A, |
const SmallMat< n_rowsA, n_colsB, mat_entry_t > & | B | ||
) |
Transpose first small/dense matrix and multiply it with second.