Click or drag to resize

DoubleMatrix Class

Represents a collection of doubles arranged in rows and columns. Provides methods to operate algebraically on matrices.
Inheritance Hierarchy
SystemObject
  Novacta.AnalyticsDoubleMatrix

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public class DoubleMatrix : IList<double>, 
	ICollection<double>, IEnumerable<double>, IEnumerable, 
	IReadOnlyList<double>, IReadOnlyCollection<double>, IComplexMatrixPatterns, 
	IMatrixPatterns, IReadOnlyTabularCollection<double, DoubleMatrix>, ITabularCollection<double, DoubleMatrix>

The DoubleMatrix type exposes the following members.

Constructors
  NameDescription
Public methodDoubleMatrix
Initializes a new instance of the DoubleMatrix class as a scalar matrix having the specified value.
Top
Properties
  NameDescription
Public propertyColumnNames
Exposes the dictionary of column names, keyed by column indexes.
Public propertyCount
Gets the number of elements in this instance.
Public propertyHasColumnNames
Gets a value indicating whether this instance has at least a named column.
Public propertyHasRowNames
Gets a value indicating whether this instance has at least a named row.
Public propertyIsBidiagonal
Gets a value indicating whether this instance is bidiagonal.
Public propertyIsColumnVector
Gets a value indicating whether this instance is a column vector.
Public propertyIsDiagonal
Gets a value indicating whether this instance is diagonal.
Public propertyIsHermitian
Gets a value indicating whether this instance is Hermitian.
Public propertyIsHessenberg
Gets a value indicating whether this instance is Hessenberg.
Public propertyIsLowerBidiagonal
Gets a value indicating whether this instance is lower bidiagonal.
Public propertyIsLowerHessenberg
Gets a value indicating whether this instance is lower Hessenberg.
Public propertyIsLowerTriangular
Gets a value indicating whether this instance is lower triangular.
Public propertyIsReadOnly
Gets a value indicating whether this instance is read-only.
Public propertyIsRowVector
Gets a value indicating whether this instance is a row vector.
Public propertyIsScalar
Gets a value indicating whether this instance is scalar.
Public propertyIsSkewHermitian
Gets a value indicating whether this instance is Skew-Hermitian.
Public propertyIsSkewSymmetric
Gets a value indicating whether this instance is skew symmetric.
Public propertyIsSquare
Gets a value indicating whether this instance is square.
Public propertyIsSymmetric
Gets a value indicating whether this instance is symmetric.
Public propertyIsTriangular
Gets a value indicating whether this instance is triangular.
Public propertyIsTridiagonal
Gets a value indicating whether this instance is tridiagonal.
Public propertyIsUpperBidiagonal
Gets a value indicating whether this instance is upper bidiagonal.
Public propertyIsUpperHessenberg
Gets a value indicating whether this instance is upper Hessenberg.
Public propertyIsUpperTriangular
Gets a value indicating whether this instance is upper triangular.
Public propertyIsVector
Gets a value indicating whether this instance is a vector.
Public propertyCode exampleItemInt32
Gets or sets the element of this instance corresponding to the specified linear index.
Public propertyCode exampleItemIndexCollection, IndexCollection
Gets or sets the elements of this instance corresponding to the specified row and column indexes.
Public propertyCode exampleItemIndexCollection, Int32
Gets or sets the elements of this instance corresponding to the specified row and column indexes.
Public propertyCode exampleItemIndexCollection, String
Gets or sets the elements of this instance corresponding to the specified row and column indexes.
Public propertyCode exampleItemInt32, IndexCollection
Gets or sets the elements of this instance corresponding to the specified row and column indexes.
Public propertyCode exampleItemInt32, Int32
Gets or sets the element of this instance corresponding to the specified row and column indexes.
Public propertyCode exampleItemInt32, String
Gets or sets the elements of this instance corresponding to the specified row and column indexes.
Public propertyCode exampleItemString, IndexCollection
Gets or sets the elements of this instance corresponding to the specified row and column indexes.
Public propertyCode exampleItemString, Int32
Gets or sets the elements of this instance corresponding to the specified row and column indexes.
Public propertyCode exampleItemString, String
Gets or sets the elements of this instance corresponding to the specified row and column indexes.
Public propertyItemIndexCollection, IndexCollection, Boolean Obsolete.
Gets the elements of this instance corresponding to the specified row and column indexes.
Public propertyItemIndexCollection, String, Boolean Obsolete.
Gets the elements of this instance corresponding to the specified row and column indexes.
Public propertyItemString, IndexCollection, Boolean Obsolete.
Gets the elements of this instance corresponding to the specified row and column indexes.
Public propertyItemString, String, Boolean Obsolete.
Gets the elements of this instance corresponding to the specified row and column indexes.
Public propertyLowerBandwidth
Gets the lower bandwidth of this instance.
Public propertyName
Gets or sets the name of this instance.
Public propertyNumberOfColumns
Gets the number of columns of this instance.
Public propertyNumberOfRows
Gets the number of rows of this instance.
Public propertyRowNames
Exposes the dictionary of row names, keyed by row indexes.
Public propertyStorageOrder
Gets the storage order of this instance.
Public propertyStorageScheme
Gets the storage scheme of this instance.
Public propertyUpperBandwidth
Gets the upper bandwidth of this instance.
Top
Methods
  NameDescription
Public methodStatic memberAdd(Complex, DoubleMatrix)
Determines the addition of a scalar to a matrix.
Public methodStatic memberCode exampleAdd(Double, DoubleMatrix)
Determines the addition of a scalar to a matrix.
Public methodStatic memberCode exampleAdd(DoubleMatrix, DoubleMatrix)
Determines the sum of two matrices.
Public methodStatic memberCode exampleAdd(DoubleMatrix, Double)
Determines the addition of a matrix to a scalar.
Public methodStatic memberAdd(DoubleMatrix, Complex)
Determines the addition of a matrix to a scalar.
Public methodCode exampleApply
Evaluates the specified function at each entry of this instance, and returns a matrix whose entries are given by the corresponding function values.
Public methodAsColumnMajorDenseArray
Returns a column major ordered, dense representation of this instance.
Public methodAsReadOnly
Returns a read-only representation of the DoubleMatrix.
Public methodCode exampleAsRowCollection
Returns the collection of rows in the DoubleMatrix.
Public methodCode exampleAsRowCollection(IndexCollection)
Returns the collection of the rows in the DoubleMatrix corresponding to the specified indexes.
Public methodContains
Public methodCopyTo
Public methodStatic memberCode exampleDense(Double)
Creates a dense DoubleMatrix instance having the same size and data of the specified two-dimensional array.
Public methodStatic memberCode exampleDense(Int32, Int32)
Creates a dense DoubleMatrix instance having the specified size, and assigns zero to each matrix entry.
Public methodStatic memberCode exampleDense(Int32, Int32, IEnumerableDouble)
Creates a dense DoubleMatrix instance having the specified size, and assigns data to entries assuming ColMajor ordering.
Public methodStatic memberCode exampleDense(Int32, Int32, Double)
Creates a dense DoubleMatrix instance having the specified size, and assigns the same value to each matrix entry.
Public methodStatic memberCode exampleDense(Int32, Int32, Double)
Creates a dense DoubleMatrix instance having the specified size, and assigns data to entries assuming ColMajor ordering.
Public methodStatic memberCode exampleDense(Int32, Int32, IEnumerableDouble, StorageOrder)
Creates a dense DoubleMatrix instance having the specified size, and assigns data to entries applying the given storage order.
Public methodStatic memberCode exampleDense(Int32, Int32, Double, StorageOrder)
Creates a dense DoubleMatrix instance having the specified size, and assigns data to entries applying the given storage order.
Public methodStatic memberDense(Int32, Int32, Double, Boolean)
Creates a dense DoubleMatrix instance having the specified size, and assigns data to entries, possibly preventing copying operations before creation.
Public methodStatic memberCode exampleDiagonal(DoubleMatrix)
Creates a square DoubleMatrix instance having the specified data on its main diagonal and zero otherwise.
Public methodStatic memberCode exampleDiagonal(ReadOnlyDoubleMatrix)
Creates a square DoubleMatrix instance having the specified data on its main diagonal and zero otherwise.
Public methodDispose
Disposes this instance.
Protected methodDispose(Boolean)
Releases unmanaged and - optionally - managed resources.
Public methodStatic memberDivide(Complex, DoubleMatrix)
Determines the division of a scalar by a matrix.
Public methodStatic memberCode exampleDivide(Double, DoubleMatrix)
Determines the division of a scalar by a matrix.
Public methodStatic memberCode exampleDivide(DoubleMatrix, DoubleMatrix)
Determines the division of a matrix by another.
Public methodStatic memberCode exampleDivide(DoubleMatrix, Double)
Determines the division of a matrix by a scalar.
Public methodStatic memberDivide(DoubleMatrix, Complex)
Determines the division of a matrix by a scalar.
Public methodStatic memberCode exampleElementWiseMultiply
Determines the element wise product of two matrices.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Finalizes an instance of the DoubleMatrix class.
(Overrides ObjectFinalize.)
Public methodCode exampleFind
Searches for entries in this instance that equal the specified value, and returns their zero-based linear indexes.
Public methodCode exampleFindNonzero
Searches for nonzero entries in this instance, and returns their zero-based linear indexes.
Public methodCode exampleFindWhile
Searches for entries in this instance that matches the conditions defined by the specified predicate, and returns their zero-based linear indexes.
Public methodStatic memberFromDouble
Converts from Double to DoubleMatrix.
Public methodStatic memberCode exampleFromIndexPartition
Public methodStatic memberFromReadOnlyDoubleMatrix
Converts from ReadOnlyDoubleMatrix to DoubleMatrix.
Public methodGetEnumerator
Returns an enumerator that iterates through the collection.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetStorage
Gets the elements currently stored in this instance.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberIdentity
Creates a DoubleMatrix instance representing the identity matrix having the specified dimension.
Public methodIndexOf
Public methodCode exampleInPlaceApply
Evaluates the specified function at each entry of this instance, and substitutes each entry with its corresponding function value.
Public methodCode exampleInPlaceTranspose
Transposes this instance.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodStatic memberMultiply(Complex, DoubleMatrix)
Determines the multiplication of a scalar by a matrix.
Public methodStatic memberCode exampleMultiply(Double, DoubleMatrix)
Determines the multiplication of a scalar by a matrix.
Public methodStatic memberCode exampleMultiply(DoubleMatrix, DoubleMatrix)
Determines the product of two matrices.
Public methodStatic memberCode exampleMultiply(DoubleMatrix, Double)
Determines the multiplication of a matrix by a scalar.
Public methodStatic memberMultiply(DoubleMatrix, Complex)
Determines the multiplication of a matrix by a scalar.
Public methodStatic memberCode exampleNegate
Determines the negation of a matrix.
Public methodRemoveAllColumnNames
Removes all column names.
Public methodRemoveAllRowNames
Removes all row names.
Public methodRemoveColumnName
Removes the name of the specified column.
Public methodRemoveRowName
Removes the name of the specified row.
Public methodSetColumnName
Sets the name of the specified column.
Public methodSetRowName
Sets the name of the specified row.
Public methodStatic memberCode exampleSparse
Creates a sparse DoubleMatrix instance having the specified size and initial capacity to store entries different from zero.
Public methodStatic memberSubtract(Complex, DoubleMatrix)
Determines the subtraction of a matrix from a scalar.
Public methodStatic memberCode exampleSubtract(Double, DoubleMatrix)
Determines the subtraction of a matrix from a scalar.
Public methodStatic memberCode exampleSubtract(DoubleMatrix, DoubleMatrix)
Determines the difference between two matrices.
Public methodStatic memberCode exampleSubtract(DoubleMatrix, Double)
Determines the subtraction of a scalar from a matrix.
Public methodStatic memberSubtract(DoubleMatrix, Complex)
Determines the subtraction of a scalar from a matrix.
Public methodStatic memberToDouble
Converts from DoubleMatrix to Double.
Public methodToString
Returns a String that represents this instance.
(Overrides ObjectToString.)
Public methodCode exampleTranspose
Returns the transpose of this instance.
Public methodTryGetColumnName
Tries to get the name of the specified column.
Public methodTryGetRowName
Tries to get the name of the specified row.
Public methodCode exampleVec
Returns the vectorization of this instance.
Public methodCode exampleVec(IndexCollection)
Returns a column vector obtained by stacking the specified elements of this instance.
Top
Operators
  NameDescription
Public operatorStatic memberAddition(Complex, DoubleMatrix)
Determines the addition of a scalar to a matrix.
Public operatorStatic memberCode exampleAddition(Double, DoubleMatrix)
Determines the addition of a scalar to a matrix.
Public operatorStatic memberCode exampleAddition(DoubleMatrix, DoubleMatrix)
Determines the sum of two matrices.
Public operatorStatic memberCode exampleAddition(DoubleMatrix, Double)
Determines the addition of a matrix to a scalar.
Public operatorStatic memberAddition(DoubleMatrix, Complex)
Determines the addition of a matrix to a scalar.
Public operatorStatic memberDivision(Complex, DoubleMatrix)
Determines the division of a scalar by a matrix.
Public operatorStatic memberCode exampleDivision(Double, DoubleMatrix)
Determines the division of a scalar by a matrix.
Public operatorStatic memberCode exampleDivision(DoubleMatrix, DoubleMatrix)
Determines the division of a matrix by another.
Public operatorStatic memberCode exampleDivision(DoubleMatrix, Double)
Determines the division of a matrix by a scalar.
Public operatorStatic memberDivision(DoubleMatrix, Complex)
Determines the division of a matrix by a scalar.
Public operatorStatic member(Double to DoubleMatrix)
Performs an explicit conversion from Double to DoubleMatrix.
Public operatorStatic member(DoubleMatrix to Double)
Performs an explicit conversion from DoubleMatrix to Double.
Public operatorStatic memberCode example(IndexPartitionDouble to DoubleMatrix)
Public operatorStatic member(ReadOnlyDoubleMatrix to DoubleMatrix)
Performs an explicit conversion from ReadOnlyDoubleMatrix to DoubleMatrix.
Public operatorStatic memberMultiply(Complex, DoubleMatrix)
Determines the multiplication of a scalar by a matrix.
Public operatorStatic memberCode exampleMultiply(Double, DoubleMatrix)
Determines the multiplication of a scalar by a matrix.
Public operatorStatic memberCode exampleMultiply(DoubleMatrix, DoubleMatrix)
Determines the product of two matrices.
Public operatorStatic memberCode exampleMultiply(DoubleMatrix, Double)
Determines the multiplication of a matrix by a scalar.
Public operatorStatic memberMultiply(DoubleMatrix, Complex)
Determines the multiplication of a matrix by a scalar.
Public operatorStatic memberSubtraction(Complex, DoubleMatrix)
Determines the subtraction of a matrix from a scalar.
Public operatorStatic memberCode exampleSubtraction(Double, DoubleMatrix)
Determines the subtraction of a matrix from a scalar.
Public operatorStatic memberCode exampleSubtraction(DoubleMatrix, DoubleMatrix)
Determines the difference between two matrices.
Public operatorStatic memberCode exampleSubtraction(DoubleMatrix, Double)
Determines the subtraction of a scalar from a matrix.
Public operatorStatic memberSubtraction(DoubleMatrix, Complex)
Determines the subtraction of a scalar from a matrix.
Public operatorStatic memberCode exampleUnaryNegation
Determines the negation of a matrix.
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implementationPrivate methodICollectionDoubleAdd
Explicit interface implementationPrivate methodICollectionDoubleClear
Explicit interface implementationPrivate methodICollectionDoubleRemove
Explicit interface implementationPrivate methodIEnumerableGetEnumerator
Returns an enumerator that iterates through a collection.
Explicit interface implementationPrivate methodIListDoubleInsert
Explicit interface implementationPrivate methodIListDoubleRemoveAt
Top
Remarks

Instantiation

DoubleMatrix objects can be created using different storage schemes. To allocate storage for each matrix entry, so applying a Dense scheme, one can exploit one of the overloaded factory method Dense, such as Dense(Int32, Int32). On the contrary, method Sparse returns instances whose scheme is StorageScheme.CompressedRow, which means that storage is allocated for non-zero entries only, using a compressed sparse row scheme.

Indexing

In a matrix, entries are arranged in rows and columns. Zero-based indexes are assigned to rows and columns, so that each entry can be identified by the indexes of the specific row and column on which it lies.

Let LaTeX equation be a matrix, and consider its generic entry

LaTeX equation

where LaTeX equation and LaTeX equation are the number of rows and columns of LaTeX equation, respectively.

Entry LaTeX equation can be set or get through the indexer ItemInt32, Int32. Further overloads of the indexer enable the access to sub-matrices, as well.

A linear index completely identifies an entry, assuming that entries are linearly ordered following the ColumnMajor data order. This means that entry LaTeX equation has linear index equal to LaTeX equation, and matrix entries can be enumerated as follows:

LaTeX equation

where LaTeX equation is the Count of the matrix.

Given a linear index, the corresponding entry can be accessed via the indexer ItemInt32. In order to retrieve entries corresponding to multiple linear indexes simultaneously, linear indexers are also overloaded to accept IndexCollection instances, or strings as arguments.

Dimensions

The dimensions of a matrix can be inspected using the properties NumberOfRows and NumberOfColumns, Use the property Count to know how many entries are arranged in a matrix.

The following table reports some particular dimensions for which a property exists which can be evaluated to inspect if the dimensions hold true for a given matrix.

Matrix PropertyNumber of rowsNumber of columns
IsScalar11
IsRowVector1Any
IsColumnVectorAny1

In addition, property IsSquare returns true for matrices having the same number of rows and columns. You can also inspect property IsVector to verify if a matrix instance has only one row or column.

Diagonals

There are LaTeX equation diagonals in LaTeX equation.

The main diagonal of LaTeX equation is also said the diagonal of order 0, and is the collection of entries LaTeX equation such that LaTeX equation.

If LaTeX equation, then the matrix has LaTeX equation super-diagonals: for LaTeX equation, the LaTeX equation-th super-diagonal is the collection of entries corresponding to the positions

LaTeX equation

If LaTeX equation, the matrix has LaTeX equation sub-diagonals: for LaTeX equation, the LaTeX equation-th sub-diagonal is the collection of entries corresponding to the positions

LaTeX equation

Bandwidths

The lower bandwidth of LaTeX equation is the smallest integer, say LaTeX equation, such that LaTeX equation if LaTeX equation.

The upper bandwidth of a matrix LaTeX equation is the smallest integer, say LaTeX equation, such that LaTeX equation if LaTeX equation.

These definitions imply that, if LaTeX equation, then the sub-diagonal of order LaTeX equation contains all zero entries, and if LaTeX equation, then the super-diagonal of order LaTeX equation contains all zero entries.

Properties LowerBandwidth and UpperBandwidth can be inspected to access the bandwidths of a given instance.

Patterns

The arrangement of zero entries in a matrix often follows a particular pattern. Some properties are defined which can be tested to verify if any of these patterns hold for a given matrix.

Relevant patterns can be described by means of lower and upper matrix bandwidths. For instance, an upper triangular matrix can be defined as a square matrix having sub-diagonals whose entries are all zero, or, equivalently, as a square matrix having a lower bandwidth equal to 0.

The following table reports some bandwidth-dependent patterns for which a property exists which can be evaluated to inspect if the pattern holds true for a given square matrix.

Matrix Pattern PropertyLower BandwidthUpper Bandwidth
IsLowerTriangularAny0
IsUpperTriangular0Any
IsLowerHessenbergAny0 or 1
IsUpperHessenberg0 or 1Any
IsDiagonal00
IsLowerBidiagonal0 or 10
IsUpperBidiagonal00 or 1
IsTridiagonal0 or 10 or 1

Finally, property IsTriangular can be inspected to verify if a matrix instance is lower or upper triangular, IsBidiagonal to verify if the instance is lower or upper bidiagonal, while property IsHessenberg returns a value indicating if a matrix instance is lower or upper Hessenberg.

Enumeration of entries and rows

Matrix values can be enumerated, and queried, using the "Linq to Objects" paradigm (see, e.g., the System.Linq documentation). Matrices can also be enumerated by rows using the iterator AsRowCollection. This means that you can apply the LINQ approach to retrieve data from a matrix: you write declarative code that describes what you want to retrieve and at what conditions, which can be specified to filter, order, and aggregate data as needed.

Memory usage

Matrix entries can be stored using different data schemes, as enumerated in StorageScheme.

The data currently stored can be accessed as an array through the GetStorage method.

Caution note Caution
This method is intended for advanced users and must always be used carefully. For performance reasons, the returned reference points directly to the matrix internal data. Do not call GetStorage if you do not have complete control of the instance you used to invoke the method.

Method AsColumnMajorDenseArray always returns a ColumnMajor ordered array which is a dense representation of the matrix entries, irrespective of the specific data scheme used to implement the matrix. If the underlying scheme is Dense, such method returns a copy of the matrix data.

Serialization

Matrices can be loaded from, or saved to a CSV file through the CsvDoubleMatrixSerializer class.

Matrices can also be represented as JSON strings, see JsonSerialization.

See Also