@ -61,6 +61,7 @@ module Matrix =
v.At(k, m a c c )
v :> _ V e c t o r
/// A module which implements functional dense vector o p e r a t i o n s .
[ < C o m p i l a t i o n R e p r e s e n t a t i o n ( C o m p i l a t i o n R e p r e s e n t a t i o n F l a g s . M o d u l e S u f f i x ) > ]
module DenseMatrix =
@ -78,7 +79,7 @@ module DenseMatrix =
let inline create (rows: int) (cols: int) x = DenseMatrix.Create(rows, cols, fun i j -> x) :> _ M a t r i x
/// Create a matrix with the given dimension and set all diagonal values to x. All other values are z e r o .
let inline createDiag (rows: int) (cols: int) x =
let createDiag (rows: int) (cols: int) x =
let A = D e n s e M a t r i x ( r o w s , c o l s )
for i=0 to min (rows-1) (cols-1) do A . A t ( i , i , x )
A :> _ M a t r i x
@ -86,8 +87,14 @@ module DenseMatrix =
/// Initialize a matrix by calling a construction function for every e l e m e n t .
let inline init (rows: int) (cols: int) (f: int -> int -> float) = DenseMatrix.Create(rows, cols, fun i j -> f i j) :> _ M a t r i x
/// Initialize a matrix by calling a construction function for every r o w .
let inline initRows (rows: int) (f: int -> Vector<float>) = DenseMatrix.OfRowVectors(Array.init rows f) :> _ M a t r i x
/// Initialize a matrix by calling a construction function for every c o l u m n .
let inline initColumns (cols: int) (f: int -> Vector<float>) = DenseMatrix.OfColumnVectors(Array.init cols f) :> _ M a t r i x
/// Initialize a matrix by calling a construction function for every diagonal element. All other values are z e r o .
let inline initDiag (rows: int) (cols: int) (f: int -> float) =
let initDiag (rows: int) (cols: int) (f: int -> float) =
let A = D e n s e M a t r i x ( r o w s , c o l s )
for i=0 to min (rows-1) (cols-1) do A.At(i,i,f i )
A :> _ M a t r i x
@ -95,67 +102,54 @@ module DenseMatrix =
/// Create an identity matrix with the given d i m e n s i o n .
let inline identity (rows: int) (cols: int) = createDiag rows cols 1 .0
/// Create a matrix from a 2 D array of floating point n u m b e r s .
let inline ofArray2 array = DenseMatrix.OfArray(array) :> _ M a t r i x
/// Create a matrix from a list of float lists. Every list in the master list specifies a r o w .
/// If the dimensions are known, consider to use ofRowList instead to avoid multiple e n u m e r a t i o n .
let inline ofList (fll: float list list) =
let n = List.length f l l
let m = List.length (List.head f l l )
DenseMatrix.OfRowsCovariant(n, m, fll) :> _ M a t r i x
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a r o w .
/// If the dimensions are known, consider to use ofRowSeq instead to avoid multiple e n u m e r a t i o n .
let inline ofSeq (fss: #seq<#seq<float>>) =
let n = Seq.length f s s
let m = Seq.length (Seq.head f s s )
DenseMatrix.OfRowsCovariant(n, m, fss) :> _ M a t r i x
/// Create a matrix from a list of row v e c t o r s .
let inline ofRows (vectors: #Vector<float> list) = DenseMatrix.OfRowVectors(vectors |> Array.ofList |> box |> unbox) :> _ M a t r i x
let inline ofRows (rows: Vector<float> list) = DenseMatrix.OfRowVectors(Array.ofList rows) :> _ M a t r i x
/// Create a matrix from a list of row a r r a y s .
let inline ofRowArrays (rows: float[][]) = DenseMatrix.OfRowArrays(rows) :> _ M a t r i x
/// Create a matrix from a list of float lists. Every list in the master list specifies a r o w .
let inline ofRowList (rows: int) (cols: int) (fll: float list list) = DenseMatrix.OfRowsCovariant(rows, cols, fll) :> _ M a t r i x
let inline ofRowList (rows: float list list) = DenseMatrix.OfRowArrays(rows |> List.map List.toArray |> List.toArray) :> _ M a t r i x
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a r o w .
let inline ofRowSeq (rows: #seq<#seq<float>>) = DenseMatrix.OfRowArrays(rows |> Seq.map Seq.toArray |> Seq.toArray) :> _ M a t r i x
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a r o w .
let inline ofRowSeq (rows: int) (cols: int) (fss: #seq<#seq<float>>) = DenseMatrix.OfRowsCovariant(rows, cols, fss) :> _ M a t r i x
let inline ofRowSeq2 (rows: int) (cols: int) (seqOfRows: #seq<seq<float>>) = DenseMatrix.OfRows(rows, cols, seqOfRows) :> _ M a t r i x
/// Create a matrix from a list of column v e c t o r s .
let inline ofColumns (vectors: #Vector<float> list) = DenseMatrix.OfColumnVectors(vectors |> Array.ofList |> box |> unbox) :> _ M a t r i x
let inline ofColumns (columns: Vector<float> list) = DenseMatrix.OfColumnVectors(Array.ofList columns) :> _ M a t r i x
/// Create a matrix from a list of column a r r a y s .
let inline ofColumnArrays (columns: float[][]) = DenseMatrix.OfColumnArrays(columns) :> _ M a t r i x
/// Create a matrix from a list of float lists. Every list in the master list specifies a c o l u m n .
let inline ofColumnList (rows: int) (cols: int) (fll: float list list) = DenseMatrix.OfColumnsCovariant(rows, cols, fll) :> _ M a t r i x
let inline ofColumnList (columns: float list list) = DenseMatrix.OfColumnArrays(columns |> List.map List.toArray |> List.toArray) :> _ M a t r i x
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a c o l u m n .
let inline ofColumnSeq (columns: #seq<#seq<float>>) = DenseMatrix.OfColumnArrays(columns |> Seq.map Seq.toArray |> Seq.toArray) :> _ M a t r i x
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a c o l u m n .
let inline ofColumnSeq (rows: int) (cols: int) (fss: #seq<#seq<float>>) = DenseMatrix.OfColumnsCovariant(rows, cols, fss) :> _ M a t r i x
let inline ofColumnSeq2 (rows: int) (cols: int) (seqOfCol s: #seq<seq<float>>) = DenseMatrix.OfColumns(rows, cols, seqOfCol s) :> _ M a t r i x
/// Create a matrix with a given dimension from an indexed list of row, column, value tuples.
let inline ofListi (rows: int) (cols: int) (fl : list<int * int * float>) = DenseMatrix.OfIndexed(rows, cols, Seq.ofList fl ) :> _ M a t r i x
let inline ofListi (rows: int) (cols: int) (indexed : list<int * int * float>) = DenseMatrix.OfIndexed(rows, cols, Seq.ofList indexed ) :> _ M a t r i x
/// Create a matrix with a given dimension from an indexed sequences of row, column, value tuples.
let inline ofSeqi (rows: int) (cols: int) (fs : #seq<int * int * float>) = DenseMatrix.OfIndexed(rows, cols, fs ) :> _ M a t r i x
let inline ofSeqi (rows: int) (cols: int) (indexed : #seq<int * int * float>) = DenseMatrix.OfIndexed(rows, cols, indexed ) :> _ M a t r i x
/// Create a square matrix with the vector elements on the d i a g o n a l .
let inline ofDiag (v: #Vector<float>) =
let n = v . C o u n t
let A = D e n s e M a t r i x ( n , n )
/// Create a matrix with the vector elements on the d i a g o n a l .
let ofDiag2 (rows: int) (cols: int) (v: Vector<float>) =
let A = D e n s e M a t r i x ( r o w s , c o l s )
A . S e t D i a g o n a l ( v )
A :> _ M a t r i x
/// Initialize a matrix by calling a construction function for every r o w .
let inline initRow (rows: int) (cols: int) (f: int -> #Vector<float>) =
let A = D e n s e M a t r i x ( r o w s , c o l s )
for i=0 to rows-1 do A.SetRow(i, f i )
A :> _ M a t r i x
/// Create a square matrix with the vector elements on the d i a g o n a l .
let inline ofDiag (v: Vector<float>) = ofDiag2 v.Count v.Count v
/// Initialize a matrix by calling a construction function for every c o l u m n .
let inline initCol (rows: int) (cols: int) (f: int -> #Vector<float>) =
let A = D e n s e M a t r i x ( r o w s , c o l s )
for i=0 to cols-1 do A.SetColumn(i, f i )
A :> _ M a t r i x
/// A module which implements functional sparse vector o p e r a t i o n s .
[ < C o m p i l a t i o n R e p r e s e n t a t i o n ( C o m p i l a t i o n R e p r e s e n t a t i o n F l a g s . M o d u l e S u f f i x ) > ]
@ -165,7 +159,7 @@ module SparseMatrix =
let inline zeroCreate (rows: int) (cols: int) = SparseMatrix(rows, cols) :> _ M a t r i x
/// Create a matrix with the given dimension and set all diagonal values to x. All other values are z e r o .
let inline createDiag (rows: int) (cols: int) x =
let createDiag (rows: int) (cols: int) x =
let A = S p a r s e M a t r i x ( r o w s , c o l s )
for i=0 to min (rows-1) (cols-1) do A . A t ( i , i , x )
A :> _ M a t r i x
@ -173,8 +167,14 @@ module SparseMatrix =
/// Initialize a matrix by calling a construction function for every e l e m e n t .
let inline init (rows: int) (cols: int) (f: int -> int -> float) = SparseMatrix.Create(rows, cols, fun n m -> f n m) :> _ M a t r i x
/// Initialize a matrix by calling a construction function for every r o w .
let inline initRows (rows: int) (f: int -> Vector<float>) = SparseMatrix.OfRowVectors(Array.init rows f) :> _ M a t r i x
/// Initialize a matrix by calling a construction function for every c o l u m n .
let inline initColumns (cols: int) (f: int -> Vector<float>) = SparseMatrix.OfColumnVectors(Array.init cols f) :> _ M a t r i x
/// Initialize a matrix by calling a construction function for every diagonal element. All other values are z e r o .
let inline initDiag (rows: int) (cols: int) (f: int -> float) =
let initDiag (rows: int) (cols: int) (f: int -> float) =
let A = S p a r s e M a t r i x ( r o w s , c o l s )
for i=0 to min (rows-1) (cols-1) do A.At(i,i,f i )
A :> _ M a t r i x
@ -182,58 +182,50 @@ module SparseMatrix =
/// Create an identity matrix with the given d i m e n s i o n .
let inline identity (rows: int) (cols: int) = createDiag rows cols 1 .0
/// Create a matrix from a 2 D array of floating point n u m b e r s .
let inline ofArray2 array = SparseMatrix.OfArray(array) :> _ M a t r i x
/// Create a matrix with a given dimension from an indexed sequences of row, column, value tuples.
[<System.ObsoleteAttribute("Use ofSeqi instead. Will be changed to expect a non-indexed seq in a future v e r s i o n . " ) > ]
let inline ofSeq (rows: int) (cols: int) (fs: #seq<int * int * float>) = SparseMatrix.OfIndexed(rows, cols, fs) :> _ M a t r i x
/// Create a matrix with a given dimension from an indexed list of row, column, value tuples.
[<System.ObsoleteAttribute("Use ofListi instead. Will be changed to expect a non-indexed list in a future v e r s i o n . " ) > ]
let inline ofList (rows: int) (cols: int) (fl: list<int * int * float>) = SparseMatrix.OfIndexed(rows, cols, Seq.ofList fl) :> _ M a t r i x
/// Create a matrix from a list of row v e c t o r s .
let inline ofRows (vectors: #Vector<float> list) = SparseMatrix.OfRowVectors(vectors |> Array.ofList |> box |> unbox) :> _ M a t r i x
let inline ofRows (rows: Vector<float> list) = SparseMatrix.OfRowVectors(Array.ofList rows) :> _ M a t r i x
/// Create a matrix from a list of row a r r a y s .
let inline ofRowArrays (rows: float[][]) = SparseMatrix.OfRowArrays(rows) :> _ M a t r i x
/// Create a matrix from a list of float lists. Every list in the master list specifies a r o w .
let inline ofRowList (rows: int) (cols: int) (fll: float list list) = SparseMatrix.OfRowsCovariant(rows, cols, fll) :> _ M a t r i x
let inline ofRowList (rows: float list list) = SparseMatrix.OfRowArrays(rows |> List.map List.toArray |> List.toArray) :> _ M a t r i x
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a r o w .
let inline ofRowSeq (rows: #seq<#seq<float>>) = SparseMatrix.OfRowArrays(rows |> Seq.map Seq.toArray |> Seq.toArray) :> _ M a t r i x
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a r o w .
let inline ofRowSeq (rows: int) (cols: int) (fss: #seq<#seq<float>>) = SparseMatrix.OfRowsCovariant(rows, cols, fss) :> _ M a t r i x
let inline ofRowSeq2 (rows: int) (cols: int) (seqOfRow s: #seq<seq<float>>) = SparseMatrix.OfRows(rows, cols, seqOfRow s) :> _ M a t r i x
/// Create a matrix from a list of column v e c t o r s .
let inline ofColumns (vectors: #Vector<float> list) = SparseMatrix.OfColumnVectors(vectors |> Array.ofList |> box |> unbox) :> _ M a t r i x
let inline ofColumns (columns: Vector<float> list) = SparseMatrix.OfColumnVectors(Array.ofList columns) :> _ M a t r i x
/// Create a matrix from a list of column a r r a y s .
let inline ofColumnArrays (columns: float[][]) = SparseMatrix.OfColumnArrays(columns) :> _ M a t r i x
/// Create a matrix from a list of float lists. Every list in the master list specifies a c o l u m n .
let inline ofColumnList (rows: int) (cols: int) (fll: float list list) = SparseMatrix.OfColumnsCovariant(rows, cols, fll) :> _ M a t r i x
let inline ofColumnList (columns: float list list) = SparseMatrix.OfColumnArrays(columns |> List.map List.toArray |> List.toArray) :> _ M a t r i x
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a c o l u m n .
let inline ofColumnSeq (columns: #seq<#seq<float>>) = SparseMatrix.OfColumnArrays(columns |> Seq.map Seq.toArray |> Seq.toArray) :> _ M a t r i x
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a c o l u m n .
let inline ofColumnSeq (rows: int) (cols: int) (fss: #seq<#seq<float>>) = SparseMatrix.OfColumnsCovariant(rows, cols, fss) :> _ M a t r i x
let inline ofColumnSeq2 (rows: int) (cols: int) (seqOfCol s: #seq<seq<float>>) = SparseMatrix.OfColumns(rows, cols, seqOfCol s) :> _ M a t r i x
/// Create a matrix with a given dimension from an indexed list of row, column, value tuples.
let inline ofListi (rows: int) (cols: int) (fl : list<int * int * float>) = SparseMatrix.OfIndexed(rows, cols, Seq.ofList fl ) :> _ M a t r i x
let inline ofListi (rows: int) (cols: int) (indexed : list<int * int * float>) = SparseMatrix.OfIndexed(rows, cols, Seq.ofList indexed ) :> _ M a t r i x
/// Create a matrix with a given dimension from an indexed sequences of row, column, value tuples.
let inline ofSeqi (rows: int) (cols: int) (fs: #seq<int * int * float>) = SparseMatrix.OfIndexed(rows, cols, fs) :> _ M a t r i x
/// Create a square matrix with the vector elements on the d i a g o n a l .
let inline ofDiag (v: #Vector<float>) =
let n = v . C o u n t
let A = S p a r s e M a t r i x ( n , n )
A . S e t D i a g o n a l ( v )
A :> _ M a t r i x
let inline ofSeqi (rows: int) (cols: int) (indexed: #seq<int * int * float>) = SparseMatrix.OfIndexed(rows, cols, indexed) :> _ M a t r i x
/// Initialize a matrix by calling a construction function for every r o w .
let inline initRow (rows: int) (cols: int) (f: int -> # Vector<float>) =
/// Create a matrix with the vector elements on the d i a g o n a l .
let ofDiag2 (rows: int) (cols: int) (v: Vector<float>) =
let A = S p a r s e M a t r i x ( r o w s , c o l s )
for i=0 to rows-1 do A.SetRow(i, f i )
A . S e t D i a g o n a l ( v )
A :> _ M a t r i x
/// Initialize a matrix by calling a construction function for every c o l u m n .
let inline initCol (rows: int) (cols: int) (f: int -> #Vector<float>) =
let A = S p a r s e M a t r i x ( r o w s , c o l s )
for i=0 to cols-1 do A.SetColumn(i, f i )
A :> _ M a t r i x
/// Create a square matrix with the vector elements on the d i a g o n a l .
let inline ofDiag (v: Vector<float>) = ofDiag2 v.Count v.Count v