FsAlg


Matrix

Operations on Matrix type. (Implementing functionality similar to Microsoft.FSharp.Collections.Array2D)

Functions and values

Function or valueDescription
appendCol(v m)
Signature: v:Vector<^T> -> m:Matrix<^T> -> Matrix<^T>
Type parameters: ^T

Returns a matrix where vector v is appended as a new column to matrix m

appendRow(v m)
Signature: v:Vector<^T> -> m:Matrix<^T> -> Matrix<^T>
Type parameters: ^T

Returns a matrix where vector v is appended as a new row to matrix m

col(j m)
Signature: j:int -> m:Matrix<^T> -> Matrix<^T>
Type parameters: ^T

Returns the j-th column of matrix m

cols(m)
Signature: m:Matrix<^T> -> int
Type parameters: ^T

Returns the number of columns in matrix m. This is the same with Matrix.length2.

copy(m)
Signature: m:Matrix<^T> -> Matrix<^T>
Type parameters: ^T

Creates a copy of Matrix m

create(m n v)
Signature: m:int -> n:int -> v:^T -> Matrix<^T>
Type parameters: ^T

Creates a matrix with m rows, n columns, and all entries having value v

createRows(m v)
Signature: m:int -> v:^T [] -> Matrix<^T>
Type parameters: ^T

Creates a matrix with m rows and all rows equal to array v

decomposeLU(m)
Signature: m:Matrix<^T> -> Matrix<^T> * int [] * ^T
Type parameters: ^T

Gets the LU decomposition of matrix m. The return values are the LU matrix, pivot indices, and a toggle value indicating the number of row exchanges during the decomposition, which is +1 if the number of exchanges were even, -1 if odd.

decomposeQR(m)
Signature: m:Matrix<^T> -> Matrix<^T> * Matrix<^T>
Type parameters: ^T

Gets the QR decomposition of matrix m

det(m)
Signature: m:Matrix<^T> -> ^T
Type parameters: ^T

Gets the determinant of matrix m

diagonal(m)
Signature: m:Matrix<^T> -> Vector<^T>
Type parameters: ^T

Gets the diagonal elements of matrix m

eigenvalues(m)
Signature: m:Matrix<^T> -> Vector<^T>
Type parameters: ^T

Gets the eigenvalues of matrix m

get(m i j)
Signature: m:Matrix<^T> -> i:int -> j:int -> ^T
Type parameters: ^T

Gets the entry of matrix m with indices i and j

identity(m)
Signature: m:int -> Matrix<^T>
Type parameters: ^T

Creates the identity matrix with m rows and columns

init(m n f)
Signature: m:int -> n:int -> f:(int -> int -> ^T) -> Matrix<^T>
Type parameters: ^T

Creates a matrix with m rows, n columns and a generator function f to compute the entries

initCols(n f)
Signature: n:int -> f:(int -> Vector<^T>) -> Matrix<^T>
Type parameters: ^T

Creates a matrix with n columns and a generator function f that gives each column as a vector

initRows(m f)
Signature: m:int -> f:(int -> Vector<^T>) -> Matrix<^T>
Type parameters: ^T

Creates a matrix with m rows and a generator function f that gives each row as a a vector

initSymmetric(m f)
Signature: m:int -> f:(int -> int -> ^T) -> Matrix<^T>
Type parameters: ^T

Creates a square matrix with m rows and columns and a generator function f to compute the elements. Function f is used only for populating the diagonal and the upper triangular part of the matrix, the lower triangular part will be the reflection.

inverse(m)
Signature: m:Matrix<^T> -> Matrix<^T>
Type parameters: ^T

Gets the inverse of matrix m

iter(f m)
Signature: f:(^T -> unit) -> m:Matrix<^T> -> unit
Type parameters: ^T

Applies function f to each element of matrix m

iteri(f m)
Signature: f:(int -> int -> ^T -> unit) -> m:Matrix<^T> -> unit
Type parameters: ^T

Applies function f to each element of matrix m. Element indices are also supplied to function f.

length1(m)
Signature: m:Matrix<^T> -> int
Type parameters: ^T

Returns the number of rows in matrix m. This is the same with Matrix.rows.

length2(m)
Signature: m:Matrix<^T> -> int
Type parameters: ^T

Returns the number of columns in matrix m. This is the same with Matrix.cols.

map(f m)
Signature: f:(^T -> ^U) -> m:Matrix<^T> -> Matrix<^U>
Type parameters: ^T, ^U

Creates a matrix whose entries are the results of applying function f to each entry of matrix m

mapi(f m)
Signature: f:(int -> int -> ^T -> ^U) -> m:Matrix<^T> -> Matrix<^U>
Type parameters: ^T, ^U

Creates a matrix whose entries are the results of applying function f to each entry of matrix m. Element indices are also supplied to function f.

ofArray(m a)
Signature: m:int -> a:^T [] -> Matrix<^T>
Type parameters: ^T

Creates a matrix with m rows from the one dimensional array a, filling columns from left to right and rows from top to bottom. The number of columns will be deduced from m and the length of the array a. The length of a must be an integer multiple of m.

ofArray2D(m)
Signature: m:^T [,] -> Matrix<^T>
Type parameters: ^T

Creates a matrix from 2d array m

ofArrayArray(m)
Signature: m:^T [] [] -> Matrix<^T>
Type parameters: ^T

Creates a matrix from a jagged array, e.g. from float[][] to Matrix

ofCols(v)
Signature: v:seq<Vector<^T>> -> Matrix<^T>
Type parameters: ^T

Constructs a matrix out of a sequence of column vectors v. The column vectors should be of equal length.

ofRows(v)
Signature: v:seq<Vector<^T>> -> Matrix<^T>
Type parameters: ^T

Constructs a matrix out of a sequence of row vectors v. The row vectors should be of equal length.

ofSeq(m s)
Signature: m:int -> s:seq<^T> -> Matrix<^T>
Type parameters: ^T

Creates a matrix with m rows from the one dimensional sequence s, filling columns from left to right and rows from top to bottom. The number of columns will be deduced from m and the length of the sequence s. The length of s must be an integer multiple of m.

ofSeqSeq(s)
Signature: s:seq<seq<^T>> -> Matrix<^T>
Type parameters: ^T

Creates a matrix from sequence of sequences s

ofVector(m v)
Signature: m:int -> v:Vector<^T> -> Matrix<^T>
Type parameters: ^T

Creates a matrix with m rows from the vector v, filling columns from left to right and rows from top to bottom. The number of columns will be deduced from m and the length of the vector v. The length of v must be an integer multiple of m.

prependCol(v m)
Signature: v:Vector<^T> -> m:Matrix<^T> -> Matrix<^T>
Type parameters: ^T

Returns a matrix where vector v is prepended as a new column to matrix m

prependRow(v m)
Signature: v:Vector<^T> -> m:Matrix<^T> -> Matrix<^T>
Type parameters: ^T

Returns a matrix where vector v is appended as a new row to matrix m

replace(f m)
Signature: f:(^T -> ^T) -> m:Matrix<^T> -> unit
Type parameters: ^T

Replaces the elements of matrix m by mutating them in place, passing them through function f

replace2(f m1 m2)
Signature: f:(^T1 -> ^T2 -> ^T1) -> m1:Matrix<^T1> -> m2:Matrix<^T2> -> unit
Type parameters: ^T1, ^T2

Replaces the elements of matrix m1 by mutating them in place. The new values are computed by applying function f to the corresponding elements of matrices m1 and m2 pairwise. The two input matrices should have the same dimensions, otherwise ArgumentException is raised.

replacei(f m)
Signature: f:(int -> int -> ^T -> ^T) -> m:Matrix<^T> -> unit
Type parameters: ^T

Replaces the elements of matrix m by mutating them in place, passing them through functionf`. Element indices are also supplied to functionf`.

replacei2(f m1 m2)
Signature: f:(int -> int -> ^T1 -> ^T2 -> ^T1) -> m1:Matrix<^T1> -> m2:Matrix<^T2> -> unit
Type parameters: ^T1, ^T2

Replaces the elements of matrix m1 by mutating them in place. The new values are computed by applying function f to the corresponding elements of matrices m1 and m2 pairwise. Element indices are also supplied to function f. The two input matrices should have the same dimensions, otherwise ArgumentException is raised.

replaceWith(m1 m2)
Signature: m1:Matrix<^T> -> m2:Matrix<^T> -> unit
Type parameters: ^T

Replaces the elements of matrix m1 with the elements of matrix m2, by mutating them in place. The two input matrices should have the same dimensions, otherwise ArgumentException is raised.

row(i m)
Signature: i:int -> m:Matrix<^T> -> Matrix<^T>
Type parameters: ^T

Returns the i-th row of matrix m

rows(m)
Signature: m:Matrix<^T> -> int
Type parameters: ^T

Returns the number of rows in matrix m. This is the same with Matrix.length1.

set(m i j a)
Signature: m:Matrix<^T> -> i:int -> j:int -> a:^T -> unit
Type parameters: ^T

Sets the entry of matrix m with indices i and j to value a

solve(a b)
Signature: a:Matrix<^T> -> b:Vector<^T> -> Vector<^T>
Type parameters: ^T

Solves a system of linear equations ax = b, where the coefficients are given in matrix a and the result vector is vector b. The returned vector will correspond to x.

toArray(m)
Signature: m:Matrix<^T> -> ^T []
Type parameters: ^T

Converts matrix m to a one dimensional array, scanning columns from left to right and rows from top to bottom

toArray2D(m)
Signature: m:Matrix<^T> -> ^T [,]
Type parameters: ^T

Converts matrix m to a 2d array, e.g. from Matrix to float[,]

toArrayArray(m)
Signature: m:Matrix<^T> -> ^T [] []
Type parameters: ^T

Converts matrix m to a jagged array, e.g. from Matrix to float[][]

toCols(m)
Signature: m:Matrix<^T> -> seq<Matrix<^T>>
Type parameters: ^T

Returns the columns of matrix m as a sequence of matrices

toRows(m)
Signature: m:Matrix<^T> -> seq<Matrix<^T>>
Type parameters: ^T

Returns the rows of matrix m as a sequence of matrices

toSeq(m)
Signature: m:Matrix<^T> -> seq<^T>
Type parameters: ^T

Converts matrix m to a one dimensional sequence, scanning columns from left to right and rows from top to bottom

toSeqSeq(m)
Signature: m:Matrix<^T> -> seq<seq<^T>>
Type parameters: ^T

Converts matrix m to a sequence of sequences

toVector(m)
Signature: m:Matrix<^T> -> Vector<^T>
Type parameters: ^T

Converts matrix m to a vector, scanning columns from left to right and rows from top to bottom

trace(m)
Signature: m:Matrix<^T> -> ^T
Type parameters: ^T

Gets the trace of matrix m

transpose(m)
Signature: m:Matrix<^T> -> Matrix<^T>
Type parameters: ^T

Gets the transpose of matrix m