Heidelberg Educational Numerics Library Version 0.27 (from 15 March 2021)
|
Class with mathematical matrix operations. More...
#include <densematrix.hh>
Public Types | |
typedef std::size_t | size_type |
Type used for array indices. | |
typedef std::vector< REAL > | VType |
typedef VType::const_iterator | ConstVectorIterator |
typedef VType::iterator | VectorIterator |
Public Member Functions | |
DenseMatrix () | |
default constructor (empty Matrix) | |
DenseMatrix (const std::size_t _rows, const std::size_t _cols, const REAL def_val=0) | |
constructor | |
DenseMatrix (const std::initializer_list< std::initializer_list< REAL > > &v) | |
constructor from initializer list | |
DenseMatrix (const hdnum::SparseMatrix< REAL > &other) | |
constructor from hdnum::SparseMatrix | |
void | addNewRow (const hdnum::Vector< REAL > &rowvector) |
size_t | rowsize () const |
get number of rows of the matrix | |
size_t | colsize () const |
get number of columns of the matrix | |
bool | scientific () const |
void | scientific (bool b) const |
Switch between floating point (default=true) and fixed point (false) display. | |
std::size_t | iwidth () const |
get index field width for pretty-printing | |
std::size_t | width () const |
get data field width for pretty-printing | |
std::size_t | precision () const |
get data precision for pretty-printing | |
void | iwidth (std::size_t i) const |
set index field width for pretty-printing | |
void | width (std::size_t i) const |
set data field width for pretty-printing | |
void | precision (std::size_t i) const |
set data precision for pretty-printing | |
REAL & | operator() (const std::size_t row, const std::size_t col) |
(i,j)-operator for accessing entries of a (m x n)-matrix directly | |
const REAL & | operator() (const std::size_t row, const std::size_t col) const |
read-access on matrix element A_ij using A(i,j) | |
const ConstVectorIterator | operator[] (const std::size_t row) const |
read-access on matrix element A_ij using A[i][j] | |
VectorIterator | operator[] (const std::size_t row) |
write-access on matrix element A_ij using A[i][j] | |
DenseMatrix & | operator= (const DenseMatrix &A) |
assignment operator | |
DenseMatrix & | operator= (const REAL value) |
assignment from a scalar value | |
DenseMatrix | sub (size_type i, size_type j, size_type rows, size_type cols) |
Submatrix extraction. | |
DenseMatrix | transpose () const |
Transposition. | |
DenseMatrix & | operator+= (const DenseMatrix &B) |
Addition assignment. | |
DenseMatrix & | operator-= (const DenseMatrix &B) |
Subtraction assignment. | |
DenseMatrix & | operator*= (const REAL s) |
Scalar multiplication assignment. | |
DenseMatrix & | operator/= (const REAL s) |
Scalar division assignment. | |
void | update (const REAL s, const DenseMatrix &B) |
Scaled update of a Matrix. | |
template<class V > | |
void | mv (Vector< V > &y, const Vector< V > &x) const |
matrix vector product y = A*x | |
template<class V > | |
void | umv (Vector< V > &y, const Vector< V > &x) const |
update matrix vector product y += A*x | |
template<class V > | |
void | umv (Vector< V > &y, const V &s, const Vector< V > &x) const |
update matrix vector product y += sA*x | |
void | mm (const DenseMatrix< REAL > &A, const DenseMatrix< REAL > &B) |
assign to matrix product C = A*B to matrix C | |
void | umm (const DenseMatrix< REAL > &A, const DenseMatrix< REAL > &B) |
add matrix product A*B to matrix C | |
void | sc (const Vector< REAL > &x, std::size_t k) |
set column: make x the k'th column of A | |
void | sr (const Vector< REAL > &x, std::size_t k) |
set row: make x the k'th row of A | |
REAL | norm_infty () const |
compute row sum norm | |
REAL | norm_1 () const |
compute column sum norm | |
Vector< REAL > | operator* (const Vector< REAL > &x) const |
vector = matrix * vector | |
DenseMatrix | operator* (const DenseMatrix &x) const |
matrix = matrix * matrix | |
DenseMatrix | operator+ (const DenseMatrix &x) const |
matrix = matrix + matrix | |
DenseMatrix | operator- (const DenseMatrix &x) const |
matrix = matrix - matrix | |
Related Symbols | |
(Note that these are not member symbols.) | |
template<class T > | |
void | identity (DenseMatrix< T > &A) |
template<typename REAL > | |
void | spd (DenseMatrix< REAL > &A) |
template<typename REAL > | |
void | vandermonde (DenseMatrix< REAL > &A, const Vector< REAL > x) |
template<typename REAL > | |
void | readMatrixFromFileDat (const std::string &filename, DenseMatrix< REAL > &A) |
Read matrix from a text file. | |
template<typename REAL > | |
void | readMatrixFromFileMatrixMarket (const std::string &filename, DenseMatrix< REAL > &A) |
Read matrix from a matrix market file. | |
|
inline |
get number of columns of the matrix
Example:
Output:
Matrix A has 5 columns.
|
inline |
assign to matrix product C = A*B to matrix C
Implements C = A*B where A and B are matrices
[in] | A | constant reference to a DenseMatrix |
[in] | B | constant reference to a DenseMatrix |
Example:
Output:
A = 0 1 2 3 4 5 0 1.000 1.000 1.000 1.000 1.000 1.000 1 1.000 1.000 1.000 1.000 1.000 1.000 B = 0 1 2 0 -1.000 -1.000 -1.000 1 -1.000 -1.000 -1.000 2 -1.000 -1.000 -1.000 3 -1.000 -1.000 -1.000 4 -1.000 -1.000 -1.000 5 -1.000 -1.000 -1.000 C = A*B = 0 1 2 0 -6.000 -6.000 -6.000 1 -6.000 -6.000 -6.000
matrix vector product y = A*x
Implements y = A*x where x and y are a vectors and A is a matrix
Example:
Output:
A = 0 1 2 0 1.000 1.000 1.000 1 1.000 1.000 1.000 x = [ 0] 10.0000000 [ 1] 10.0000000 [ 2] 10.0000000 y = A*x = [ 0] 30.0000000 [ 1] 30.0000000
|
inline |
(i,j)-operator for accessing entries of a (m x n)-matrix directly
[in] | row | row index (0...m-1) |
[in] | col | column index (0...n-1) |
Example:
Output:
A= 0 1 2 3 0 1.000 0.000 0.000 0.000 1 0.000 1.000 0.000 0.000 2 0.000 0.000 1.000 0.000 3 0.000 0.000 0.000 1.000 reading A(0,0)=1.000 resetting A(0,0) and A(2,3)... A= 0 1 2 3 0 1.234 0.000 0.000 0.000 1 0.000 1.000 0.000 0.000 2 0.000 0.000 1.000 432.100 3 0.000 0.000 0.000 1.000
|
inline |
matrix = matrix * matrix
[in] | x | constant reference to a DenseMatrix |
Example:
Output:
A= 0 1 2 0 2.0 2.0 2.0 1 2.0 2.0 2.0 2 2.0 2.0 2.0 B= 0 1 2 0 4.0 4.0 4.0 1 4.0 4.0 4.0 2 4.0 4.0 4.0 C=A*B= 0 1 2 0 24.0 24.0 24.0 1 24.0 24.0 24.0 2 24.0 24.0 24.0
|
inline |
vector = matrix * vector
[in] | x | constant reference to a Vector |
Example:
Output:
A= 0 1 2 0 2.0 2.0 2.0 1 2.0 2.0 2.0 2 2.0 2.0 2.0 x= [ 0] 4.0 [ 1] 4.0 [ 2] 4.0 y=A*x [ 0] 24.0 [ 1] 24.0 [ 2] 24.0
|
inline |
Scalar multiplication assignment.
Implements A *= s where s is a scalar
[in] | s | scalar value to multiply with |
Example:
Output:
A= 0 1 2 0 1.000e+00 1.000e+00 1.000e+00 1 1.000e+00 1.000e+00 1.000e+00 0.5*A = 0 1 2 0 5.000e-01 5.000e-01 5.000e-01 1 5.000e-01 5.000e-01 5.000e-01
|
inline |
matrix = matrix + matrix
[in] | x | constant reference to a DenseMatrix |
Example:
Output:
A= 0 1 2 0 2.0 2.0 2.0 1 2.0 2.0 2.0 2 2.0 2.0 2.0 B= 0 1 2 0 4.0 4.0 4.0 1 4.0 4.0 4.0 2 4.0 4.0 4.0 C=A+B= 0 1 2 0 6.0 6.0 6.0 1 6.0 6.0 6.0 2 6.0 6.0 6.0
|
inline |
Addition assignment.
Implements A += B matrix addition
[in] | B | another Matrix |
|
inline |
matrix = matrix - matrix
[in] | x | constant reference to a DenseMatrix |
Example:
Output:
A= 0 1 2 0 2.0 2.0 2.0 1 2.0 2.0 2.0 2 2.0 2.0 2.0 B= 0 1 2 0 4.0 4.0 4.0 1 4.0 4.0 4.0 2 4.0 4.0 4.0 C=A-B= 0 1 2 0 -2.0 -2.0 -2.0 1 -2.0 -2.0 -2.0 2 -2.0 -2.0 -2.0
|
inline |
Subtraction assignment.
Implements A -= B matrix subtraction
[in] | B | another matrix |
|
inline |
Scalar division assignment.
Implements A /= s where s is a scalar
[in] | s | scalar value to multiply with |
Example:
Output:
A= 0 1 2 0 1.000e+00 1.000e+00 1.000e+00 1 1.000e+00 1.000e+00 1.000e+00 A/0.5 = 0 1 2 0 2.000e+00 2.000e+00 2.000e+00 1 2.000e+00 2.000e+00 2.000e+00
|
inline |
assignment operator
Example:
Output:
B= 0 1 2 3 0 4.000e+00 -1.000e+00 -2.500e-01 -1.111e-01 1 -1.000e+00 4.000e+00 -1.000e+00 -2.500e-01 2 -2.500e-01 -1.000e+00 4.000e+00 -1.000e+00 3 -1.111e-01 -2.500e-01 -1.000e+00 4.000e+00
|
inline |
assignment from a scalar value
Example:
Output:
A= 0 1 2 0 5.432 5.432 5.432 1 5.432 5.432 5.432
|
inline |
get number of rows of the matrix
Example:
Output:
Matrix A has 4 rows.
set column: make x the k'th column of A
[in] | x | constant reference to a Vector |
[in] | k | number of the column of A to be set |
Example:
Output:
original A= 0 1 2 3 4 5 0 0.0 0.0 0.0 0.0 0.0 0.0 1 0.0 0.0 0.0 0.0 0.0 0.0 modified A= 0 1 2 3 4 5 0 0.0 0.0 0.0 434.0 0.0 0.0 1 0.0 0.0 0.0 434.0 0.0 0.0
Switch between floating point (default=true) and fixed point (false) display.
Example:
Output:
A= 0 1 2 3 0 1.000 0.000 0.000 0.000 1 0.000 1.000 0.000 0.000 2 0.000 0.000 1.000 0.000 3 0.000 0.000 0.000 1.000
set row: make x the k'th row of A
[in] | x | constant reference to a Vector |
[in] | k | number of the row of A to be set |
Example:
Output:
original A= 0 1 2 0 0.0 0.0 0.0 1 0.0 0.0 0.0 2 0.0 0.0 0.0 modified A= 0 1 2 0 0.0 0.0 0.0 1 434.0 434.0 434.0 2 0.0 0.0 0.0
|
inline |
Submatrix extraction.
Returns a new matrix that is a subset of the components of the given matrix.
[in] | i | first row index of the new matrix |
[in] | j | first column index of the new matrix |
[in] | rows | row size of the new matrix, i.e. it has components [i,i+rows-1] |
[in] | cols | column size of the new matrix, i.e. it has components [j,j+cols-1] |
|
inline |
Transposition.
Return the transposed as a new matrix.
|
inline |
add matrix product A*B to matrix C
Implements C += A*B where A, B and C are matrices
[in] | A | constant reference to a DenseMatrix |
[in] | B | constant reference to a DenseMatrix |
Example:
Output:
C = 0 1 2 0 0.500 0.500 0.500 1 0.500 0.500 0.500 A = 0 1 2 3 4 5 0 1.000 1.000 1.000 1.000 1.000 1.000 1 1.000 1.000 1.000 1.000 1.000 1.000 B = 0 1 2 0 -1.000 -1.000 -1.000 1 -1.000 -1.000 -1.000 2 -1.000 -1.000 -1.000 3 -1.000 -1.000 -1.000 4 -1.000 -1.000 -1.000 5 -1.000 -1.000 -1.000 C + A*B = 0 1 2 0 -5.500 -5.500 -5.500 1 -5.500 -5.500 -5.500
|
inline |
update matrix vector product y += sA*x
Implements y += sA*x where s is a scalar value, x and y are a vectors and A is a matrix
[in] | y | reference to the resulting Vector |
[in] | s | constant reference to a number type |
[in] | x | constant reference to a Vector |
Example:
Output:
y = [ 0] 5.0000000 [ 1] 5.0000000 A = 0 1 2 0 1.000 1.000 1.000 1 1.000 1.000 1.000 x = [ 0] 10.0000000 [ 1] 10.0000000 [ 2] 10.0000000 y = s*A*x = [ 0] 20.0000000 [ 1] 20.0000000
update matrix vector product y += A*x
Implements y += A*x where x and y are a vectors and A is a matrix
Example:
Output:
y = [ 0] 5.0000000 [ 1] 5.0000000 A = 0 1 2 0 1.000 1.000 1.000 1 1.000 1.000 1.000 x = [ 0] 10.0000000 [ 1] 10.0000000 [ 2] 10.0000000 y + A*x = [ 0] 35.0000000 [ 1] 35.0000000
|
inline |
Scaled update of a Matrix.
Implements A += s*B where s is a scalar and B a matrix
[in] | s | scalar value to multiply with |
[in] | B | another matrix |
Example:
Output:
A + s*B = 0 1 2 0 1.500 1.500 1.500 1 1.500 1.500 1.500
|
related |
Function: make identity matrix
[in] | A | reference to a DenseMatrix that shall be filled with entries |
Example:
Output:
A= 0 1 2 3 0 1.00000 0.00000 0.00000 0.00000 1 0.00000 1.00000 0.00000 0.00000 2 0.00000 0.00000 1.00000 0.00000 3 0.00000 0.00000 0.00000 1.00000
|
related |
Read matrix from a text file.
[in] | filename | name of the text file |
[in,out] | A | reference to a DenseMatrix |
Example:
Output:
Contents of "matrixL.dat": 1.000e+00 0.000e+00 0.000e+00 2.000e+00 1.000e+00 0.000e+00 3.000e+00 2.000e+00 1.000e+00 would give: L= 0 1 2 0 1.000e+00 0.000e+00 0.000e+00 1 2.000e+00 1.000e+00 0.000e+00 2 3.000e+00 2.000e+00 1.000e+00
|
related |
Read matrix from a matrix market file.
[in] | filename | name of the text file |
[in,out] | A | reference to a DenseMatrix |
Example:
Output:
Contents of "matrixL.mtx": 3 3 6 1 1 1 2 1 2 2 2 1 3 1 3 3 2 2 3 3 1 would give: L= 0 1 2 0 1.000e+00 0.000e+00 0.000e+00 1 2.000e+00 1.000e+00 0.000e+00 2 3.000e+00 2.000e+00 1.000e+00
|
related |
Function: make a symmetric and positive definite matrix
[in] | A | reference to a DenseMatrix that shall be filled with entries |
Example:
Output:
A= 0 1 2 3 0 4.00000 -1.00000 -0.25000 -0.11111 1 -1.00000 4.00000 -1.00000 -0.25000 2 -0.25000 -1.00000 4.00000 -1.00000 3 -0.11111 -0.25000 -1.00000 4.00000
Function: make a vandermonde matrix
[in] | A | reference to a DenseMatrix that shall be filled with entries |
[in] | x | constant reference to a Vector |
Example:
Output:
x= [ 0] 2.00000 [ 1] 3.00000 [ 2] 4.00000 [ 3] 5.00000 A= 0 1 2 3 0 1.00000 2.00000 4.00000 8.00000 1 1.00000 3.00000 9.00000 27.00000 2 1.00000 4.00000 16.00000 64.00000 3 1.00000 5.00000 25.00000 125.00000