NoIdeaHowToFixThis
NoIdeaHowToFixThis

Reputation: 4564

math.net conversion of Matrix to Generic.Matrix<float>

let v = [| 5.0; 2.0; 3.0; 11.0 |]
let m2 = new DenseMatrix(2, 2, v)
let invm = m2.Inverse()
let invt = m2.Transpose()

Here m2 is a Matrix. However, invm and invt are Generic.Matrix<float>. Why this conversion?

Upvotes: 2

Views: 335

Answers (1)

Gene Belitski
Gene Belitski

Reputation: 10350

Shortly, because the signatures of DenseMatrix.Inverse() and DenseMatrix.Transpose() are

DenseMatrix.Inverse: unit -> Matrix<float>
DenseMatrix.Transpose: unit -> Matrix<float>

Matrix is an abstract class that provides common implementation of Inverse and Transpose methods for any matrix. Concrete derived subclasses DenseMatrix, SparseMatrix, and DiagonalMatrix just optimize way of storing matrix data depending on each use case.

You may upcast

let m2 = new DenseMatrix(2, 2, v) :> Matrix<float>

and manipulate with generic types after matrix creation. You may want checking related topic Matrix vs DenseMatrix for further details.

Upvotes: 4

Related Questions