![]() |
KASKADE 7 development version
|
A LAPACK-compatible dense matrix class with shape specified at runtime. More...
#include <dynamicMatrix.hh>
Public Types | |
| using | size_type = typename Base::size_type |
| using | value_type = typename Base::value_type |
| using | field_type = typename Dune::FieldTraits<K>::field_type |
| typedef Base::row_type | row_type |
Public Member Functions | |
| DynamicMatrix & | operator= (DynamicMatrix const &a)=default |
| Copy assignment. | |
| DynamicMatrix & | operator= (DynamicMatrix &&a)=default |
| Move assignment. | |
| template<class OtherK> | |
| DynamicMatrix & | operator= (DynamicMatrix< OtherK > const &A) |
| Assignment from matrix with other scalar type. | |
| void | resize (size_type r, size_type c) |
| Resizes the matrix to r x c, leaving the entries in an undefined state. | |
| void | setSize (size_type r, size_type c) |
| Resizes the matrix to r x c, leaving the entries in an undefined state. | |
| void | fill (K val) |
| template<class RRange, class CRange> | |
| DynamicMatrix | operator() (RRange const &ridx, CRange const &cidx) const |
| Submatrix extraction. | |
Linear algebra operations | |
| template<class X, class Y> | |
| void | mv (X const &x, Y &y) const |
| matrix-vector product \( y \leftarrow A x \) | |
| template<class X, class Y> | |
| void | mtv (const X &x, Y &y) const |
| transpose matrix vector product \( y \leftarrow A^T x \) | |
| template<class X, class Y> | |
| void | umtv (const X &x, Y &y) const |
| update transpose matrix vector product \( y \leftarrow y + A^T x \). | |
| template<class X, class Y> | |
| void | usmv (typename Dune::FieldTraits< Y >::field_type alpha, X const &x, Y &y) const |
| update and scale matrix vector product \( y \leftarrow y + \alpha A x \). | |
| template<class X, class Y> | |
| void | usmtv (typename Dune::FieldTraits< Y >::field_type alpha, X const &x, Y &y) const |
| update and scale transposed matrix vector product \( y \leftarrow y + \alpha A^T x \). | |
| DynamicMatrix & | operator*= (field_type s) |
| Scales the matrix by a scalar: \( A \gets sA \). | |
Low level access | |
| size_type | lda () const |
| The leading dimension (for calling BLAS/LAPACK). | |
| field_type * | data () |
| Raw access to data (for calling BLAS/LAPACK). | |
| field_type const * | data () const |
| Raw access to data (for calling BLAS/LAPACK). | |
| size_type | mat_rows () const |
| size_type | mat_cols () const |
| row_reference | mat_access (size_type i) |
| const_row_reference | mat_access (size_type i) const |
Related Symbols | |
(Note that these are not member symbols.) | |
| template<class Entry> | |
| std::ostream & | operator<< (std::ostream &out, DynamicMatrix< Entry > const &A) |
| pretty output of dense matrices | |
| template<class Entry> | |
| DynamicMatrix< typename EntryTraits< Entry >::transpose_type > | transpose (DynamicMatrix< Entry > const &A) |
| Computes the transpose of a matrix \( A \mapsto A^T \). | |
| template<class Entry> | |
| std::tuple< DynamicMatrix< Dune::FieldMatrix< typename EntryTraits< Entry >::field_type, 1, 1 > >, std::vector< typename EntryTraits< Entry >::real_type >, DynamicMatrix< Dune::FieldMatrix< typename EntryTraits< Entry >::field_type, 1, 1 > > > | svd (DynamicMatrix< Entry > const &A, bool fullU=true, bool fullV=true) |
| Computes the singular value decomposition \( A = U \Sigma V^T \). | |
| template<class Entry> | |
| EntryTraits< Entry >::real_type | two_norm (DynamicMatrix< Entry > const &A) |
| Computes the spectral norm of the given matrix. | |
| template<class Entry> | |
| EntryTraits< Entry >::real_type | condition (DynamicMatrix< Entry > const &A) |
| Computes the condition number of the given square matrix. | |
| template<class MEntry, class Vector> | |
| Vector | gesv (DynamicMatrix< MEntry > const &A, Vector const &b) |
| Computes the solution of \( Ax = b \) for general invertible matrices. | |
| template<class MEntry, class Vector> | |
| Vector | posv (DynamicMatrix< MEntry > const &A, Vector const &b) |
| Computes the solution of \( Ax = b \) if \( A \) is symmetric positive definite. | |
| template<class MEntry, class Vector> | |
| Vector | gelss (DynamicMatrix< MEntry > const &A, Vector const &b) |
| Computes the solution of the standard least squares problem \( \|Ax-b\|=\min\). | |
| template<class Scalar> | |
| void | invert (DynamicMatrix< Scalar > &A) |
| Computes the inverse \( A^{-1} \). | |
| template<class Entry> | |
| DynamicMatrix< Entry > & | invertSpd (DynamicMatrix< Entry > &A, bool symmetrize=true) |
| In place computation of the inverse \( A^{-1} \). | |
| template<class Entry> | |
| DynamicMatrix< typename EntryTraits< Entry >::transpose_type > | pseudoinverse (DynamicMatrix< Entry > A) |
| Computes the right pseudoinverse \( A^+ \) of a wide matrix such that \( A A^+ = I \). | |
| template<class Entry> | |
| std::vector< typename EntryTraits< Entry >::real_type > | eigenvalues (DynamicMatrix< Entry > A) |
| Computes the eigenvalues of a symmetric matrix \( A \). | |
| template<class Entry> | |
| std::vector< typename EntryTraits< Entry >::real_type > | eig (DynamicMatrix< Entry > &A, bool computeEigenvectors=true) |
| Computes the eigenvalues and eigenvectors of a symmetric matrix \( A \). | |
| template<class Scalar, int d> | |
| bool | makePositiveSemiDefinite (Dune::FieldMatrix< Scalar, d, d > &A) |
| Computes a positive semi-definite approximation to \( A \) by cutting off negative eigenvalues. | |
| template<class Entry> | |
| bool | makePositiveSemiDefinite (DynamicMatrix< Entry > &A, typename ScalarTraits< typename EntryTraits< Entry >::field_type >::Real threshold=0) |
| Computes a positive semi-definite approximation to \( A \) by cutting off negative eigenvalues. | |
| template<class Entry> | |
| std::tuple< std::vector< typename EntryTraits< Entry >::field_type >, DynamicMatrix< typename EntryTraits< Entry >::field_type >, std::vector< int > > | qr (DynamicMatrix< Entry > const &A) |
| Computes a rank-revealing QR decomposition of \( A \) using column pivoting. | |
| template<class MEntry, class VEntry> | |
| auto | operator* (DynamicMatrix< MEntry > const &A, Dune::DynamicVector< VEntry > const &x) |
| matrix-vector product \( Ax \) | |
| template<class MEntry, class VEntry> | |
| auto | operator* (DynamicMatrix< MEntry > const &A, Dune::BlockVector< VEntry > const &x) |
| matrix-vector product \( Ax \) | |
| template<class MEntry> | |
| auto | operator* (typename Dune::FieldTraits< DynamicMatrix< MEntry > >::field_type x, DynamicMatrix< MEntry > A) |
| multiplication with scalar | |
| template<class MEntry> | |
| auto | operator- (DynamicMatrix< MEntry > const &A) |
| Multiplication with -1. | |
| template<class MEntry> | |
| auto | operator- (DynamicMatrix< MEntry > A, DynamicMatrix< MEntry > const &B) |
| matrix subtraction \( A-B \) | |
| template<class MEntry> | |
| auto | operator+ (DynamicMatrix< MEntry > A, DynamicMatrix< MEntry > const &B) |
| matrix addition \( A+B \) | |
| template<class EntryA, class EntryB> | |
| void | matrixMatrixProduct (DynamicMatrix< EntryA > const &A, DynamicMatrix< EntryB > const &B, DynamicMatrix< typename DynamicMatrixDetail::ProductTraits< EntryA, EntryB >::type > &C) |
| matrix-matrix product \( A B \) | |
| template<class EntryA, class EntryB> | |
| DynamicMatrix< typename DynamicMatrixDetail::ProductTraits< EntryA, EntryB >::type > | operator* (DynamicMatrix< EntryA > const &A, DynamicMatrix< EntryB > const &B) |
| matrix-matrix product \( A B \) | |
| template<class MEntry> | |
| DynamicMatrix< MEntry > | submatrix (DynamicMatrix< MEntry > const &A, int rowstart, int rowend, int colstart, int colend) |
| extracts contiguous submatrices, copying the data | |
| template<class EntryA, class EntryB> | |
| auto | kron (DynamicMatrix< EntryA > const &A, DynamicMatrix< EntryB > const &B) |
| Computes the Kronecker product of two matrices. | |
| template<class EntryA, class EntryB> | |
| auto | horzcat (DynamicMatrix< EntryA > const &A, DynamicMatrix< EntryB > const &B) |
| Concatenates two matrices horizontally. | |
| template<class EntryX, class EntryY> | |
| auto | vertcat (Dune::DynamicVector< EntryX > const &x, Dune::DynamicVector< EntryY > const &y) |
| Concatenes two (column) vectors vertically. | |
| template<class Entry> | |
| DynamicMatrix< Entry > | vertcat (DynamicMatrix< Entry > const &A, DynamicMatrix< Entry > const &B) |
| Concatenates two matrices vertically. | |
| template<class Entry> | |
| auto | dynamicUnitMatrix (Entry const &d, int n) |
| Returns the diagonal matrix with the given entry replicated on the diagonal. | |
Constructors | |
| template<class OtherK> | |
| class | DynamicMatrix |
| DynamicMatrix () | |
| Creates a 0 x 0 matrix. | |
| DynamicMatrix (Self const &a)=default | |
| Copy constructor. | |
| template<class OtherK> | |
| DynamicMatrix (DynamicMatrix< OtherK > const &A) | |
| Copies from a matrix with different entry type. | |
| DynamicMatrix (Self &&a)=default | |
| Move constructor. | |
| DynamicMatrix (size_type r, size_type c, value_type v=value_type()) | |
| Creates a r x c matrix, initialized with given value. | |
A LAPACK-compatible dense matrix class with shape specified at runtime.
| K | the entry type, either a scalar type or Dune::FieldMatrix or Dune::FieldVector |
The memory layout is BLAS-like column major. For K = Dune::FieldMatrix<double,n,1>, classical LAPACK and BLAS routines can be applied.
In contrast to Dune::DynamicMatrix this works with contiguous memory. In contrast to Dune::Matrix this does not reallocate on resize (unless the number of entries grows).
Note that the inherited "solve" method does not work for K=Dune::FieldMatrix<??,1,1>, probably due to a Dune bug around common/densematrix.hh:808 (wrong argument type - pivots are matrix entries, not vector entries...).
Definition at line 376 of file dynamicMatrix.hh.
| using Kaskade::DynamicMatrix< K >::field_type = typename Dune::FieldTraits<K>::field_type |
Definition at line 389 of file dynamicMatrix.hh.
| typedef Base::row_type Kaskade::DynamicMatrix< K >::row_type |
Definition at line 390 of file dynamicMatrix.hh.
| using Kaskade::DynamicMatrix< K >::size_type = typename Base::size_type |
Definition at line 387 of file dynamicMatrix.hh.
| using Kaskade::DynamicMatrix< K >::value_type = typename Base::value_type |
Definition at line 388 of file dynamicMatrix.hh.
|
inline |
Creates a 0 x 0 matrix.
Definition at line 400 of file dynamicMatrix.hh.
|
default |
Copy constructor.
|
inline |
Copies from a matrix with different entry type.
If the entry types have different size, the "flattend" matrices are copied scalar by scalar.
Definition at line 416 of file dynamicMatrix.hh.
|
default |
Move constructor.
|
inline |
Creates a r x c matrix, initialized with given value.
Definition at line 444 of file dynamicMatrix.hh.
|
inline |
Raw access to data (for calling BLAS/LAPACK).
Definition at line 700 of file dynamicMatrix.hh.
Referenced by Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::matrixMatrixProduct(), Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::mv(), Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::usmtv(), and Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::usmv().
|
inline |
Raw access to data (for calling BLAS/LAPACK).
Definition at line 706 of file dynamicMatrix.hh.
|
inline |
Definition at line 505 of file dynamicMatrix.hh.
Referenced by Kaskade::CoarseningDetail::GetLocalTransferProjection< Cell >::operator()().
|
inline |
The leading dimension (for calling BLAS/LAPACK).
Since entries are stored gap-less, this is always the number of matrix rows times the number of scalar rows in the entries.
Definition at line 691 of file dynamicMatrix.hh.
Referenced by Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::matrixMatrixProduct(), Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::mv(), Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::usmtv(), and Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::usmv().
|
inline |
Definition at line 711 of file dynamicMatrix.hh.
|
inline |
Definition at line 712 of file dynamicMatrix.hh.
|
inline |
Definition at line 710 of file dynamicMatrix.hh.
|
inline |
Definition at line 709 of file dynamicMatrix.hh.
|
inline |
transpose matrix vector product \( y \leftarrow A^T x \)
This computes \( y \leftarrow A^T x \). We cannot rely on the Dune implementation in DenseMatrix, as it does not transpose the individual entries. This leads to errors when the entries are not square.
Definition at line 587 of file dynamicMatrix.hh.
|
inline |
matrix-vector product \( y \leftarrow A x \)
| X | a vector type with subscript operator[]. Its value type must be multiplicable by the matrix entries. |
| Y | a vector type with subscript operator[]. Matrix entries times x entries need to be convertible to y's value type. |
| x | the source vector. The length of x needs to be at least the number of matrix columns. |
| y | the target vector, which is overwritten. The length of y needs to be at least the number of matrix rows. |
Even if of the same type, x and y shall not reference the same vector, as y is overwritten on the fly.
This implementation calls BLAS gemv if possible, and falls back to a simple double loop otherwise. The BLAS call is possible if the entries are either scalars or Dune FieldMatrix of size n x 1, with arbitrary n.
Definition at line 555 of file dynamicMatrix.hh.
Referenced by Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::operator*(), and Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::operator*().
|
inline |
Submatrix extraction.
This extracts a submatrix, as in Matlab A(ridx,cidx).
| RRange | an STL random access range type |
| CRange | an STL random access range type |
Definition at line 521 of file dynamicMatrix.hh.
|
inline |
Scales the matrix by a scalar: \( A \gets sA \).
This should be provided by the base class Dune::DenseMatrix, but as of Dune 2.5.2, the definition of field_type as value_type in the base class prevents this operator to work for matrix-valued entries. Thus we provide a working implementation.
Definition at line 669 of file dynamicMatrix.hh.
|
default |
Move assignment.
|
default |
Copy assignment.
The matrix size is adjusted as needed.
|
inline |
Assignment from matrix with other scalar type.
Definition at line 474 of file dynamicMatrix.hh.
|
inline |
Resizes the matrix to r x c, leaving the entries in an undefined state.
On resize, all row objects and iterators are invalidated. This method adheres to the Dune::DynamicMatrix interface.
Definition at line 488 of file dynamicMatrix.hh.
Referenced by Kaskade::EmptyShapeFunctionSet< ctype, dimension, T, comp >::interpolate(), Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::operator=(), Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::setSize(), and Kaskade::DynamicMatrixDetail::unflatten().
|
inline |
Resizes the matrix to r x c, leaving the entries in an undefined state.
On resize, all row objects and iterators are invalidated. This method adheres to the Dune::Matrix interface.
Definition at line 500 of file dynamicMatrix.hh.
Referenced by Kaskade::Matrix< ctype, dimension, Scalar >::evaluate(), Kaskade::interpolateGlobally(), Kaskade::interpolateGloballyWeak(), and Kaskade::CoarseningDetail::GetLocalTransferProjection< Cell >::operator()().
|
inline |
update transpose matrix vector product \( y \leftarrow y + A^T x \).
We cannot rely on the Dune implementation in DenseMatrix, as it does not transpose the individual entries. This leads to errors when the entries are not square.
Definition at line 601 of file dynamicMatrix.hh.
Referenced by Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::mtv().
|
inline |
update and scale transposed matrix vector product \( y \leftarrow y + \alpha A^T x \).
| X | a vector type with subscript operator[]. Its value type must be multiplicable by the matrix entries. |
| Y | a vector type with subscript operator[]. Matrix entries times x entries need to be convertible to y's value type. |
Dune 2.6 has a bug (the matrix entries are not transposed for multiplication), such that we provide a corrected version here.
Definition at line 648 of file dynamicMatrix.hh.
Referenced by Kaskade::DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > >::umtv().
|
inline |
update and scale matrix vector product \( y \leftarrow y + \alpha A x \).
| X | a vector type with subscript operator[]. Its value type must be multiplicable by the matrix entries. |
| Y | a vector type with subscript operator[]. Matrix entries times x entries need to be convertible to y's value type. |
Dune::DenseMatrix::usmv appears to run into a compile time bug, because DenseMatrix::field_type is defined as the same as value_type, which may not be scalar (as of Dune 2.5).
Definition at line 618 of file dynamicMatrix.hh.
Definition at line 408 of file dynamicMatrix.hh.
|
pretty output of dense matrices
Definition at line 741 of file dynamicMatrix.hh.