IGLib 1.4
The IGLib base library for development of numerical, technical and business applications.
|
Real matrix class. Some operations are performed by the MathNet.Numerics.LinearAlgebra.Matrix class. More...
Public Member Functions | |
Matrix (IMatrix A) | |
Constructs a matrix from another matrix by copying the provided matrix components to the internal data structure. | |
Matrix (MatrixBase_MathNetNumerics A) | |
Construct a matrix from MathNet.Numerics.LinearAlgebra.Matrix. Only a reference of A is copied. | |
Matrix (int d1, int d2) | |
Constructs an d1*d2 - dimensional matrix of zeros. | |
Matrix (int d1, int d2, double val) | |
Construct an numrows-by-d2 constant matrix with specified value for all elements. | |
Matrix (IVector diagonal) | |
Constructs a square matrix with specified diagonal values. | |
Matrix (int dim, double elementValue) | |
Constructs a d*d square matrix with specified diagonal value. | |
Matrix (double[][] A) | |
Constructs a matrix from a jagged 2-D array, directly using the provided array as internal data structure. | |
Matrix (double[,] elementTable) | |
Constructs a matrix from a 2-D array by deep-copying the provided array to the internal data structure. | |
Matrix (double[] _matrixElements, int numRows) | |
Construct a matrix from a one-dimensional packed array. | |
Matrix_MathNetNumerics | GetCopyMathNetNumerics () |
Creates and returns a newly allocated MathNet.Numerics representation of the current matrix. | |
Matrix | GetCopyThis () |
Creates and returns a copy of the current matrix. | |
override MatrixBase | GetCopyBase () |
Creates and returns a copy of the current matrix. | |
virtual Matrix | GetNewThis (int rowCount, int columnCount) |
Creates and returns a new matrix with the specified dimensions, and of the same type as the current matrix. | |
override MatrixBase | GetNewBase (int rowCount, int columnCount) |
Creates and returns a new matrix with the specified dimensions, and of the same type as the current matrix. | |
Matrix | GetNewThis () |
Creates and returns a new matrix with the same dimensions and of the same type as the current matrix. | |
override MatrixBase | GetNewBase () |
Creates and returns a new matrix with the same dimensions and of the same type as the current matrix. | |
Vector | GetNewVectorThis (int length) |
Creates and returns a new vector with the specified dimension, and of the type that is consistent with the type of the current matrix. | |
override VectorBase | GetNewVectorBase (int length) |
Creates and returns a new vector with the specified dimension, and of the type that is consistent with the type of the current matrix. | |
virtual string | ToStringBase () |
Returns a string representation of this vector in a readable form. | |
override int | GetHashCode () |
Returns the hash code (hash function) of the current matrix. | |
override bool | Equals (Object obj) |
Returns a value indicating whether the specified object is equal to the current matrix. True is returned if the object is a non-null matrix (i.e. it implements the IMatrix interface), and has the same dimension and equal elements as the current matrix. | |
Static Public Member Functions | |
static Matrix | Create (double[][] A) |
Constructs a matrix from a copy of a 2-D array by deep-copy. | |
static Matrix | Create (double[,] A) |
Constructs a matrix from a copy of a 2-D array by deep-copy. | |
static Matrix | CreateFromColumns (IList< Vector > columnVectors) |
Construct a complex matrix from a set of real column vectors. | |
static Matrix | CreateFromRows (IList< Vector > rowVectors) |
Construct a complex matrix from a set of real row vectors. | |
static Matrix | Identity (int d1, int d2) |
Creates a d1*d2 identity matrix. | |
static Matrix | Identity (int d) |
Creates a square identity matrix of dimension d*d. | |
static Matrix | Zeros (int d1, int d2) |
Creates a d1*d2 matrix filled with 0. | |
static Matrix | Zeros (int d) |
creates a square d*d matrix filled with 0. | |
static Matrix | Ones (int d1, int d2) |
Creates a d1*d2 matrix filled with 1. | |
static Matrix | Ones (int d) |
Generates a square d*d matrix filled with 1. | |
static Matrix | Diagonal (IVector< double > diagonalVector, int d1, int d2) |
Creates a new diagonal d1*d2 matrix based on the diagonal vector. | |
static Matrix | Diagonal (IVector< double > diagonalVector) |
Creates a new square diagonal matrix based on the diagonal vector. | |
static Matrix | Random (int d1, int d2) |
Generates a d1*d2 matrix with uniformly distributed random elements. | |
static Matrix | Random (int d1, int d2, IRandomGenerator rnd) |
Creates and returns a d1*d2 matrix with uniformly distributed random elements. | |
static Matrix | Random (int d) |
Generates a d*d square matrix with standard-distributed random elements. | |
static void | Copy (Matrix a, Matrix result) |
Copies components of a matrix to another matrix. WARNING: dimensions of the specified result matrix must match dimensions of the original matrix. REMARK: This method is implemented because it is more efficient than the corresponding method in MatrixBase (due to matched types). | |
static void | Copy (Matrix a, ref Matrix result) |
Copies components of a matrix to another matrix. Resulting matrix is allocated or reallocated if necessary. REMARK: This method is implemented because it is more efficient than the corresponding method in MatrixBase (due to matched types). | |
static void | KroneckerProduct (Matrix m1, Matrix m2, Matrix result) |
Kronecker product, A(m*n)*B(p*q)=C(mp*nq) Result is a block matrix with as many blocks as there are elements of the first matrix, each block being a product of the second matrix by an element of the first matrix. Both operands must be defined (non-null). | |
static void | KroneckerMultiply (Matrix m1, Matrix m2, Matrix result) |
Kronecker or tensor product, A(m*n)*B(p*q)=C(mp*nq) Result is a block matrix with as many blocks as there are elements of the first matrix, each block being a product of the second matrix by an element of the first matrix. Both operands must be defined (non-null). | |
static void | TensorMultiply (Matrix m1, Matrix m2, Matrix result) |
Kronecker or tensor product, A(m*n)*B(p*q)=C(mp*nq) Result is a block matrix with as many blocks as there are elements of the first matrix, each block being a product of the second matrix by an element of the first matrix. Both operands must be defined (non-null). | |
static new void | TestStaticMethodSpecific () |
A test method, just prints some output. | |
Protected Member Functions | |
Matrix () | |
void | CopyFromMatNetNumericsMatrix (Matrix_MathNetNumerics A) |
Copies components from a specified MathNet.Numerics matrix. | |
Protected Attributes | |
double[][] | _elements |
int | _rowCount |
Matrix_MathNetNumerics | _copyMathNetNumerics = null |
bool | _mathNetNumericsConsistent = false |
Properties | |
override int | RowCount [get] |
Gets the first dimension (number of rows) of the matrix. | |
override int | ColumnCount [get] |
Gets the second dimension (number of columns) of the matrix. | |
virtual int | RowCountSetter [set] |
Sets the first dimension (number of rows) of the matrix. This setter must be used very restrictively - only in setters that can change matrix dimensions. Setter is defined separately from getter because the base class' property does not define a getter. | |
virtual int | ColumnCountSetter [set] |
Sets the first dimension (number of rows) of the matrix. This setter must be used very restrictively - only in setters that can change matrix dimensions. Setter is defined separately from getter because the base class' property does not define a getter. | |
override double | this [int i, int j] [get, set] |
Gets or set the element indexed by (i, j) in the Matrix . | |
virtual bool | IsCopyMathNetNumericsConsistent [get, set] |
Tells whether the internal MathNet.Numerics matrix representation of the current matrix is consistent with the current matrix. The MathNet.Numerics representation is used for operations that are used from that library such as different kinds of decompositions. | |
virtual Matrix_MathNetNumerics | CopyMathNetNumerics [get] |
Gets the internal MathNet.Numerics representation of the current matrix. Representation is created on demand. However, the same copy is returned as long as it is consistent with the current matrix. Use GetCopyMathNet() to create a new copy each time. | |
new Matrix | T [get] |
Returns a new matrix that is transpose of the current matrix. Re-implemented here for efficiency (hides the base class property). | |
override double | NormEuclidean [get] |
Gets the Forbenius norm of the matrix, the square root of sum of squares of all elements. | |
override double | Norm [get] |
Gets the Forbenius norm of the matrix, the square root of sum of squares of all elements. | |
virtual double | Norm1 [get] |
Gets the one norm of the matrix, the maximum column sum of absolute values. | |
virtual double | Norm2 [get] |
Gets the two norm of the matrix, i.e. its maximal singular value. | |
virtual double | NormInf [get] |
Gets the infinity norm of the matrix, the maximum row sum of absolute values. | |
Private Attributes | |
int | _columnCount |
Real matrix class. Some operations are performed by the MathNet.Numerics.LinearAlgebra.Matrix class.
$A Igor Jan08 Jul10 Nov10;
IG::Num::Matrix::Matrix | ( | ) | [inline, protected] |
IG::Num::Matrix::Matrix | ( | IMatrix | A | ) | [inline] |
Constructs a matrix from another matrix by copying the provided matrix components to the internal data structure.
A | Matrix whose components are copied to the current matrix. |
IG::Num::Matrix::Matrix | ( | MatrixBase_MathNetNumerics | A | ) | [inline] |
Construct a matrix from MathNet.Numerics.LinearAlgebra.Matrix. Only a reference of A is copied.
A | MathNet.Numerics.LinearAlgebra.Matrix from which a new matrix is created. |
IG::Num::Matrix::Matrix | ( | int | d1, |
int | d2 | ||
) | [inline] |
Constructs an d1*d2 - dimensional matrix of zeros.
d1 | Number of rows. |
d1 | Number of columns. |
IG::Num::Matrix::Matrix | ( | int | d1, |
int | d2, | ||
double | val | ||
) | [inline] |
Construct an numrows-by-d2 constant matrix with specified value for all elements.
d1 | Number of rows. |
d2 | Number of columns. |
value | Value of all components. |
IG::Num::Matrix::Matrix | ( | IVector | diagonal | ) | [inline] |
Constructs a square matrix with specified diagonal values.
d | Size of the square matrix. |
val | Vector of diagonal values. |
IG::Num::Matrix::Matrix | ( | int | dim, |
double | elementValue | ||
) | [inline] |
Constructs a d*d square matrix with specified diagonal value.
dim | Size of the square matrix. |
elementValue | Diagonal value. |
IG::Num::Matrix::Matrix | ( | double | A[][] | ) | [inline] |
Constructs a matrix from a jagged 2-D array, directly using the provided array as internal data structure.
A | Two-dimensional jagged array of doubles. |
System.ArgumentException | All rows must have the same length. |
IG::Num::Matrix::Matrix | ( | double | elementTable[,] | ) | [inline] |
Constructs a matrix from a 2-D array by deep-copying the provided array to the internal data structure.
elementTable | Two-dimensional array of doubles. |
IG::Num::Matrix::Matrix | ( | double[] | _matrixElements, |
int | numRows | ||
) | [inline] |
Construct a matrix from a one-dimensional packed array.
_matrixElements | One-dimensional array of doubles, packed by columns (ala Fortran). |
numRows | Number of rows. |
System.ArgumentException | Array length must be a multiple of numrows. |
static Matrix IG::Num::Matrix::Create | ( | double | A[][] | ) | [inline, static] |
Constructs a matrix from a copy of a 2-D array by deep-copy.
A | Two-dimensional array of doubles. |
static Matrix IG::Num::Matrix::Create | ( | double | A[,] | ) | [inline, static] |
Constructs a matrix from a copy of a 2-D array by deep-copy.
A | Two-dimensional array of doubles. |
Construct a complex matrix from a set of real column vectors.
Construct a complex matrix from a set of real row vectors.
static Matrix IG::Num::Matrix::Identity | ( | int | d1, |
int | d2 | ||
) | [inline, static] |
Creates a d1*d2 identity matrix.
d1 | Number of rows. |
d2 | Number of columns. |
static Matrix IG::Num::Matrix::Identity | ( | int | d | ) | [inline, static] |
Creates a square identity matrix of dimension d*d.
d | Matrix dimension. |
static Matrix IG::Num::Matrix::Zeros | ( | int | d1, |
int | d2 | ||
) | [inline, static] |
Creates a d1*d2 matrix filled with 0.
d1 | Number of rows. |
d2 | Number of columns. |
static Matrix IG::Num::Matrix::Zeros | ( | int | d | ) | [inline, static] |
creates a square d*d matrix filled with 0.
d | Number of rows and columns. |
static Matrix IG::Num::Matrix::Ones | ( | int | d1, |
int | d2 | ||
) | [inline, static] |
Creates a d1*d2 matrix filled with 1.
d1 | Number of rows. |
d2 | Number of columns. |
static Matrix IG::Num::Matrix::Ones | ( | int | d | ) | [inline, static] |
Generates a square d*d matrix filled with 1.
d1 | Number of rows and columns. |
static Matrix IG::Num::Matrix::Diagonal | ( | IVector< double > | diagonalVector, |
int | d1, | ||
int | d2 | ||
) | [inline, static] |
Creates a new diagonal d1*d2 matrix based on the diagonal vector.
diagonalVector | The values of the matrix diagonal. |
d1 | Number of rows. |
d2 | Number of columns. |
Creates a new square diagonal matrix based on the diagonal vector.
diagonalVector | The values of the matrix diagonal. |
static Matrix IG::Num::Matrix::Random | ( | int | d1, |
int | d2 | ||
) | [inline, static] |
Generates a d1*d2 matrix with uniformly distributed random elements.
d1 | Number of rows. |
d2 | Number of columns. |
[0, 1)
interval.static Matrix IG::Num::Matrix::Random | ( | int | d1, |
int | d2, | ||
IRandomGenerator | rnd | ||
) | [inline, static] |
Creates and returns a d1*d2 matrix with uniformly distributed random elements.
d1 | Number of rows. |
d2 | Number of columns. |
[0, 1)
interval.static Matrix IG::Num::Matrix::Random | ( | int | d | ) | [inline, static] |
Generates a d*d square matrix with standard-distributed random elements.
d | Number of rows and columns. |
[0, 1)
interval.void IG::Num::Matrix::CopyFromMatNetNumericsMatrix | ( | Matrix_MathNetNumerics | A | ) | [inline, protected] |
Copies components from a specified MathNet.Numerics matrix.
A | Matrix from which elements are copied. |
Matrix_MathNetNumerics IG::Num::Matrix::GetCopyMathNetNumerics | ( | ) | [inline] |
Creates and returns a newly allocated MathNet.Numerics representation of the current matrix.
Matrix IG::Num::Matrix::GetCopyThis | ( | ) | [inline] |
Creates and returns a copy of the current matrix.
override MatrixBase IG::Num::Matrix::GetCopyBase | ( | ) | [inline, virtual] |
Creates and returns a copy of the current matrix.
Implements IG::Num::MatrixBase.
virtual Matrix IG::Num::Matrix::GetNewThis | ( | int | rowCount, |
int | columnCount | ||
) | [inline, virtual] |
Creates and returns a new matrix with the specified dimensions, and of the same type as the current matrix.
rowCount | Number fo rows of the newly created matrix. |
columnCount | Number of columns of the newly created matrix. |
override MatrixBase IG::Num::Matrix::GetNewBase | ( | int | rowCount, |
int | columnCount | ||
) | [inline, virtual] |
Creates and returns a new matrix with the specified dimensions, and of the same type as the current matrix.
rowCount | Number fo rows of the newly created matrix. |
columnCount | Number of columns of the newly created matrix. |
Implements IG::Num::MatrixBase.
Matrix IG::Num::Matrix::GetNewThis | ( | ) | [inline] |
Creates and returns a new matrix with the same dimensions and of the same type as the current matrix.
override MatrixBase IG::Num::Matrix::GetNewBase | ( | ) | [inline, virtual] |
Creates and returns a new matrix with the same dimensions and of the same type as the current matrix.
Implements IG::Num::MatrixBase.
Vector IG::Num::Matrix::GetNewVectorThis | ( | int | length | ) | [inline] |
Creates and returns a new vector with the specified dimension, and of the type that is consistent with the type of the current matrix.
length | Dimension of the newly created vector. |
override VectorBase IG::Num::Matrix::GetNewVectorBase | ( | int | length | ) | [inline, virtual] |
Creates and returns a new vector with the specified dimension, and of the type that is consistent with the type of the current matrix.
length | Dimension of the newly created vector. |
Implements IG::Num::MatrixBase.
Copies components of a matrix to another matrix. WARNING: dimensions of the specified result matrix must match dimensions of the original matrix. REMARK: This method is implemented because it is more efficient than the corresponding method in MatrixBase (due to matched types).
a | Original matrix. |
result | Materix where copy will be stored. Dimensions must match dimensions of a. |
Copies components of a matrix to another matrix. Resulting matrix is allocated or reallocated if necessary. REMARK: This method is implemented because it is more efficient than the corresponding method in MatrixBase (due to matched types).
a | Original matrix. |
result | Materix where copy will be stored. Dimensions must match dimensions of a. |
static void IG::Num::Matrix::KroneckerProduct | ( | Matrix | m1, |
Matrix | m2, | ||
Matrix | result | ||
) | [inline, static] |
Kronecker product, A(m*n)*B(p*q)=C(mp*nq) Result is a block matrix with as many blocks as there are elements of the first matrix, each block being a product of the second matrix by an element of the first matrix. Both operands must be defined (non-null).
m1 | First operand. |
m2 | Second operand. |
result |
static void IG::Num::Matrix::KroneckerMultiply | ( | Matrix | m1, |
Matrix | m2, | ||
Matrix | result | ||
) | [inline, static] |
Kronecker or tensor product, A(m*n)*B(p*q)=C(mp*nq) Result is a block matrix with as many blocks as there are elements of the first matrix, each block being a product of the second matrix by an element of the first matrix. Both operands must be defined (non-null).
m1 | First operand. |
m2 | Second operand. |
result |
static void IG::Num::Matrix::TensorMultiply | ( | Matrix | m1, |
Matrix | m2, | ||
Matrix | result | ||
) | [inline, static] |
Kronecker or tensor product, A(m*n)*B(p*q)=C(mp*nq) Result is a block matrix with as many blocks as there are elements of the first matrix, each block being a product of the second matrix by an element of the first matrix. Both operands must be defined (non-null).
m1 | First operand. |
m2 | Second operand. |
result |
virtual string IG::Num::Matrix::ToStringBase | ( | ) | [inline, virtual] |
Returns a string representation of this vector in a readable form.
override int IG::Num::Matrix::GetHashCode | ( | ) | [inline] |
Returns the hash code (hash function) of the current matrix.
This method calls the MatrixBase.GetHashCode to calculate the hash code, which is standard for all implementations of the IMatrix interface.
Two matrices that have the same dimensions and equal elements will produce the same hash codes.
Probability that two different matrices will produce the same hash code is small but it exists.
Overrides the object.GetHashCode method.
Reimplemented from IG::Num::MatrixBase.
override bool IG::Num::Matrix::Equals | ( | Object | obj | ) | [inline] |
Returns a value indicating whether the specified object is equal to the current matrix. True is returned if the object is a non-null matrix (i.e. it implements the IMatrix interface), and has the same dimension and equal elements as the current matrix.
This method calls the MatrixBase.Equals to obtain the returned value, which is standard for all implementations of the IMatrix interface.
Overrides the object.Equals method.
Reimplemented from IG::Num::MatrixBase.
static new void IG::Num::Matrix::TestStaticMethodSpecific | ( | ) | [inline, static] |
A test method, just prints some output.
Reimplemented from IG::Num::MatrixBase.
double [][] IG::Num::Matrix::_elements [protected] |
int IG::Num::Matrix::_rowCount [protected] |
int IG::Num::Matrix::_columnCount [private] |
Matrix_MathNetNumerics IG::Num::Matrix::_copyMathNetNumerics = null [protected] |
bool IG::Num::Matrix::_mathNetNumericsConsistent = false [protected] |
override int IG::Num::Matrix::RowCount [get] |
Gets the first dimension (number of rows) of the matrix.
Reimplemented from IG::Num::MatrixBase.
override int IG::Num::Matrix::ColumnCount [get] |
Gets the second dimension (number of columns) of the matrix.
Reimplemented from IG::Num::MatrixBase.
virtual int IG::Num::Matrix::RowCountSetter [set, protected] |
Sets the first dimension (number of rows) of the matrix. This setter must be used very restrictively - only in setters that can change matrix dimensions. Setter is defined separately from getter because the base class' property does not define a getter.
virtual int IG::Num::Matrix::ColumnCountSetter [set, protected] |
Sets the first dimension (number of rows) of the matrix. This setter must be used very restrictively - only in setters that can change matrix dimensions. Setter is defined separately from getter because the base class' property does not define a getter.
override double IG::Num::Matrix::this[int i, int j] [get, set] |
Gets or set the element indexed by (i, j)
in the Matrix
.
i | Row index. |
j | Column index. |
Component access is currently a bit slower because it works indirectly through the base matrix' access. This could be corrected if we could assign the components array _base._data to some internal variable, but there is no way to access the component array of a Math.Net matrix due to its protection level (which is currently default, i.e. private, but should be at least protected in order to solve this problem).
Reimplemented from IG::Num::MatrixBase.
virtual bool IG::Num::Matrix::IsCopyMathNetNumericsConsistent [get, set] |
Tells whether the internal MathNet.Numerics matrix representation of the current matrix is consistent with the current matrix. The MathNet.Numerics representation is used for operations that are used from that library such as different kinds of decompositions.
Currrently, an internal flag indicating consistency of the MathNet matrix is not used. Every time this property is required, the consistence is actually verified by comparing values. There may be derived matrix classes where the falg is actually used. These must keep track when anything in the matrix changes and invalidate the flag on each such event.
virtual Matrix_MathNetNumerics IG::Num::Matrix::CopyMathNetNumerics [get] |
Gets the internal MathNet.Numerics representation of the current matrix. Representation is created on demand. However, the same copy is returned as long as it is consistent with the current matrix. Use GetCopyMathNet() to create a new copy each time.
new Matrix IG::Num::Matrix::T [get] |
Returns a new matrix that is transpose of the current matrix. Re-implemented here for efficiency (hides the base class property).
Reimplemented from IG::Num::MatrixBase.
override double IG::Num::Matrix::NormEuclidean [get] |
Gets the Forbenius norm of the matrix, the square root of sum of squares of all elements.
Reimplemented from IG::Num::MatrixBase.
override double IG::Num::Matrix::Norm [get] |
Gets the Forbenius norm of the matrix, the square root of sum of squares of all elements.
Reimplemented from IG::Num::MatrixBase.
virtual double IG::Num::Matrix::Norm1 [get] |
Gets the one norm of the matrix, the maximum column sum of absolute values.
virtual double IG::Num::Matrix::Norm2 [get] |
Gets the two norm of the matrix, i.e. its maximal singular value.
virtual double IG::Num::Matrix::NormInf [get] |
Gets the infinity norm of the matrix, the maximum row sum of absolute values.