|
Core 1.0
|
A simple, non-optimized implementation of rectangular matrixes. More...
#include <matrix-mn.h>
Public Member Functions | |
| MatrixMN (int, int, double=0.0) | |
| Create a rectangular matrix. | |
| MatrixMN (int, double=0.0) | |
| Create a square matrix. | |
| MatrixMN (int, int, const std::vector< double > &) | |
| Create a rectangular matrix. | |
| MatrixMN (const std::vector< std::vector< double > > &) | |
| Creates a rectangular matrix from a 2D std::vector. | |
| double & | operator() (int, int) |
| Return the matrix entry at row i, column j. | |
| double | operator() (int, int) const |
| Return the matrix entry at row i, column j. | |
| void | SwapRows (int, int) |
| Swap rows. | |
| MatrixMN | Transpose () const |
| Transpose. | |
| MatrixMN | Inverse () const |
| Compute the Gauss Jordan inverse. | |
| double | LogDet () const |
| Compute the log of the (assumed positive) determinant, via Gaussian elimination with partial pivoting. | |
| MatrixMN | operator- () const |
| Returns the negation of a matrix -A. | |
| MatrixMN & | operator+= (const MatrixMN &) |
| Self sum. | |
| MatrixMN & | operator-= (const MatrixMN &) |
| Self difference. | |
| MatrixMN & | operator*= (const MatrixMN &) |
| Self product. | |
| MatrixMN & | operator*= (const double &) |
| Self multiply by a scalar. | |
| MatrixMN & | operator/= (const double &) |
| Self division by a scalar. | |
Static Public Member Functions | |
| static MatrixMN | Identity (int) |
| Create the identity matrix. | |
| static MatrixMN | Covariance (const std::vector< std::vector< double > > &vectors) |
| Create the covariance matrix of a given set of vectors. | |
Protected Member Functions | |
| int | Index (int, int) const |
| Compute the entry of a term. | |
| bool | SameSize (const MatrixMN &) const |
| Test if the matrix has the same size as the argument matrix. | |
Protected Attributes | |
| int | m = 0 |
| Rows. | |
| int | n = 0 |
| Columns. | |
| std::vector< double > | v |
| Array of data. | |
Friends | |
| MatrixMN | operator+ (const MatrixMN &a, const MatrixMN &b) |
| Sum. | |
| MatrixMN | operator- (const MatrixMN &a, const MatrixMN &b) |
| Difference. | |
| MatrixMN | operator* (const MatrixMN &a, const MatrixMN &b) |
| Product. | |
| MatrixMN | operator* (const MatrixMN &a, double b) |
| Right multiply by a scalar. | |
| MatrixMN | operator* (double b, const MatrixMN &a) |
| Left multiply by a scalar. | |
| MatrixMN | operator/ (const MatrixMN &a, const double &d) |
| Divide all entries by a scalar. | |
| std::ostream & | operator<< (std::ostream &s, const MatrixMN &mat) |
| Overloaded. | |
A simple, non-optimized implementation of rectangular matrixes.
| MatrixMN::MatrixMN | ( | int | m, |
| int | n, | ||
| double | d = 0.0 ) |
Create a rectangular matrix.
| m,n | Size in rows, columns. |
| d | Default scalar value. |
| MatrixMN::MatrixMN | ( | int | n, |
| double | d = 0.0 ) |
Create a square matrix.
| n | Size. |
| d | Default scalar value. |
| MatrixMN::MatrixMN | ( | int | m, |
| int | n, | ||
| const std::vector< double > & | data ) |
Create a rectangular matrix.
| m,n | Number of rows and columns. |
| data | Linearized array of values in row-major order (m*n elements). |
| MatrixMN::MatrixMN | ( | const std::vector< std::vector< double > > & | data | ) |
Creates a rectangular matrix from a 2D std::vector.
| data | 2D std::vector, each row must have same number of elements. |
|
static |
Create the covariance matrix of a given set of vectors.
| vectors | Set of vectors, they must have the same size. |
|
static |
Create the identity matrix.
| n | Size. |
|
inlineprotected |
Compute the entry of a term.
| i,j | Indexes. |
| MatrixMN MatrixMN::Inverse | ( | ) | const |
Compute the Gauss Jordan inverse.
The function only works if the matrix is square.
The pivot of every column is the coefficient of largest absolute value among the remaining rows (partial pivoting), which limits the amplification of the rounding errors. The matrix is considered as singular if this pivot is smaller than 1e-12 times the largest absolute value of the coefficients of the matrix: in that case the identity matrix is returned.
| double MatrixMN::LogDet | ( | ) | const |
Compute the log of the (assumed positive) determinant, via Gaussian elimination with partial pivoting.
The function only works if the matrix is square. Returns minus infinity if the matrix is singular.
The matrix is considered as singular if a pivot is smaller than 1e-12 times the largest absolute value of its coefficients: the test does not depend on the scale of the coefficients, so that the determinant of a well conditioned matrix with small (or large) coefficients is computed.
|
inline |
Return the matrix entry at row i, column j.
| i,j | Integer coordinates of the matrix entry. |
|
inline |
Return the matrix entry at row i, column j.
| i,j | Integer coordinates of the matrix entry. |
| MatrixMN & MatrixMN::operator*= | ( | const double & | d | ) |
Self multiply by a scalar.
| d | Real. |
| MatrixMN & MatrixMN::operator/= | ( | const double & | d | ) |
Self division by a scalar.
| d | Real. |
|
inlineprotected |
Test if the matrix has the same size as the argument matrix.
| A | Matrix |
| void MatrixMN::SwapRows | ( | int | i, |
| int | j ) |
Swap rows.
| i,j | Indexes. |
Product.
| a,b | Matrixes. |
Right multiply by a scalar.
| a | Matrix. |
| b | Real. |
Left multiply by a scalar.
| a | Matrix. |
| b | Real. |
Difference.
| a,b | Matrixes. |
Divide all entries by a scalar.
| a | Matrix. |
| d | Scalar divisor. |
|
friend |
Overloaded.
| s | Stream. |
| mat | Matrix. |