IGLib 1.4
The IGLib base library for development of numerical, technical and business applications.

IG::Num::Matrix Class Reference

Real matrix class. Some operations are performed by the MathNet.Numerics.LinearAlgebra.Matrix class. More...

Inheritance diagram for IG::Num::Matrix:
Collaboration diagram for IG::Num::Matrix:

List of all members.

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

Detailed Description

Real matrix class. Some operations are performed by the MathNet.Numerics.LinearAlgebra.Matrix class.

$A Igor Jan08 Jul10 Nov10;


Constructor & Destructor Documentation

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.

Parameters:
AMatrix 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.

Parameters:
AMathNet.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.

Parameters:
d1Number of rows.
d1Number 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.

Parameters:
d1Number of rows.
d2Number of columns.
valueValue of all components.
IG::Num::Matrix::Matrix ( IVector  diagonal) [inline]

Constructs a square matrix with specified diagonal values.

Parameters:
dSize of the square matrix.
valVector of diagonal values.
IG::Num::Matrix::Matrix ( int  dim,
double  elementValue 
) [inline]

Constructs a d*d square matrix with specified diagonal value.

Parameters:
dimSize of the square matrix.
elementValueDiagonal 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.

Parameters:
ATwo-dimensional jagged array of doubles.
Exceptions:
System.ArgumentExceptionAll rows must have the same length.
See also:
Matrix.Create(double[][]), Matrix.Create(double[,])
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.

Parameters:
elementTableTwo-dimensional array of doubles.
IG::Num::Matrix::Matrix ( double[]  _matrixElements,
int  numRows 
) [inline]

Construct a matrix from a one-dimensional packed array.

Parameters:
_matrixElementsOne-dimensional array of doubles, packed by columns (ala Fortran).
numRowsNumber of rows.
Exceptions:
System.ArgumentExceptionArray length must be a multiple of numrows.

Member Function Documentation

static Matrix IG::Num::Matrix::Create ( double  A[][]) [inline, static]

Constructs a matrix from a copy of a 2-D array by deep-copy.

Parameters:
ATwo-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.

Parameters:
ATwo-dimensional array of doubles.
static Matrix IG::Num::Matrix::CreateFromColumns ( IList< Vector columnVectors) [inline, static]

Construct a complex matrix from a set of real column vectors.

static Matrix IG::Num::Matrix::CreateFromRows ( IList< Vector rowVectors) [inline, static]

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.

Parameters:
d1Number of rows.
d2Number of columns.
Returns:
An d1*d2 matrix with ones on the diagonal and zeros elsewhere.
static Matrix IG::Num::Matrix::Identity ( int  d) [inline, static]

Creates a square identity matrix of dimension d*d.

Parameters:
dMatrix dimension.
Returns:
A d*d identity matrix.
static Matrix IG::Num::Matrix::Zeros ( int  d1,
int  d2 
) [inline, static]

Creates a d1*d2 matrix filled with 0.

Parameters:
d1Number of rows.
d2Number of columns.
static Matrix IG::Num::Matrix::Zeros ( int  d) [inline, static]

creates a square d*d matrix filled with 0.

Parameters:
dNumber of rows and columns.
static Matrix IG::Num::Matrix::Ones ( int  d1,
int  d2 
) [inline, static]

Creates a d1*d2 matrix filled with 1.

Parameters:
d1Number of rows.
d2Number of columns.
static Matrix IG::Num::Matrix::Ones ( int  d) [inline, static]

Generates a square d*d matrix filled with 1.

Parameters:
d1Number 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.

Parameters:
diagonalVectorThe values of the matrix diagonal.
d1Number of rows.
d2Number of columns.
Returns:
A d1*d2 matrix with the values from the diagonal vector on the diagonal and zeros elsewhere.
static Matrix IG::Num::Matrix::Diagonal ( IVector< double >  diagonalVector) [inline, static]

Creates a new square diagonal matrix based on the diagonal vector.

Parameters:
diagonalVectorThe values of the matrix diagonal.
Returns:
A square matrix with the values from the diagonal vector on the diagonal and zeros elsewhere.
static Matrix IG::Num::Matrix::Random ( int  d1,
int  d2 
) [inline, static]

Generates a d1*d2 matrix with uniformly distributed random elements.

Parameters:
d1Number of rows.
d2Number of columns.
Returns:
A d1*d2 matrix with uniformly distributed random elements in [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.

Parameters:
d1Number of rows.
d2Number of columns.
Returns:
A d1*d2 matrix with uniformly distributed random elements in [0, 1) interval.
static Matrix IG::Num::Matrix::Random ( int  d) [inline, static]

Generates a d*d square matrix with standard-distributed random elements.

Parameters:
dNumber of rows and columns.
Returns:
A d*d square matrix with uniformly distributed random elements in [0, 1) interval.
void IG::Num::Matrix::CopyFromMatNetNumericsMatrix ( Matrix_MathNetNumerics  A) [inline, protected]

Copies components from a specified MathNet.Numerics matrix.

Parameters:
AMatrix 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.

Returns:
A new copy of the current matrix. The copy is supposed to be of the same type as the current matrix.
override MatrixBase IG::Num::Matrix::GetCopyBase ( ) [inline, virtual]

Creates and returns a copy of the current matrix.

Returns:
A new copy of the current matrix. The copy is supposed to be of the same type as 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.

Parameters:
rowCountNumber fo rows of the newly created matrix.
columnCountNumber of columns of the newly created matrix.
Returns:
A newly created matrix of the specified dimensions and of the same type as the current 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.

Parameters:
rowCountNumber fo rows of the newly created matrix.
columnCountNumber of columns of the newly created matrix.
Returns:
A newly created matrix of the specified dimensions and of the same type as the current 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.

Parameters:
lengthDimension of the newly created vector.
Returns:
A newly created vector of the specified dimension and of the same type as the current matrix.
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.

Parameters:
lengthDimension of the newly created vector.
Returns:
A newly created vector of the specified dimension and of the same type as the current matrix.

Implements IG::Num::MatrixBase.

static void IG::Num::Matrix::Copy ( Matrix  a,
Matrix  result 
) [inline, static]

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).

Parameters:
aOriginal matrix.
resultMaterix where copy will be stored. Dimensions must match dimensions of a.
static void IG::Num::Matrix::Copy ( Matrix  a,
ref Matrix  result 
) [inline, static]

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).

Parameters:
aOriginal matrix.
resultMaterix 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).

Parameters:
m1First operand.
m2Second 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).

Parameters:
m1First operand.
m2Second 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).

Parameters:
m1First operand.
m2Second 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.


Member Data Documentation

double [][] IG::Num::Matrix::_elements [protected]
int IG::Num::Matrix::_rowCount [protected]
Matrix_MathNetNumerics IG::Num::Matrix::_copyMathNetNumerics = null [protected]

Property Documentation

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.

Parameters:
iRow index.
jColumn 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.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties Events