2
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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

When you create the matrix using either the matrix function (matrix [[ 5.0; 3.0]; [2.0; 11.0]]) or one of the factory functions in the DenseMatrix module of the F# extensions, the matrix will automatically be of the generic type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.