Browse Source

Matrix: updated F# module for ofColumn/RowVectors

v2
Christoph Ruegg 13 years ago
parent
commit
89a110db1a
  1. 6
      src/FSharp/LinearAlgebra.Double.Matrix.fs
  2. 8
      src/FSharpUnitTests/DenseMatrixTests.fs

6
src/FSharp/LinearAlgebra.Double.Matrix.fs

@ -300,12 +300,18 @@ module DenseMatrix =
/// Create a matrix from a list of float lists. Every list in the master list specifies a row. /// Create a matrix from a list of float lists. Every list in the master list specifies a row.
let inline ofRowsList (rows: int) (cols: int) (fll: float list list) = DenseMatrix.OfRowsCovariant(rows, cols, fll) let inline ofRowsList (rows: int) (cols: int) (fll: float list list) = DenseMatrix.OfRowsCovariant(rows, cols, fll)
/// Create a matrix from a list of row vectors.
let inline ofRowVectors (vectors: #Vector<float> list) = DenseMatrix.OfRowVectors(vectors |> Array.ofList |> box |> unbox)
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a column. /// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a column.
let inline ofColumns (rows: int) (cols: int) (fss: #seq<#seq<float>>) = DenseMatrix.OfColumnsCovariant(rows, cols, fss) let inline ofColumns (rows: int) (cols: int) (fss: #seq<#seq<float>>) = DenseMatrix.OfColumnsCovariant(rows, cols, fss)
/// Create a matrix from a list of float lists. Every list in the master list specifies a column. /// Create a matrix from a list of float lists. Every list in the master list specifies a column.
let inline ofColumnsList (rows: int) (cols: int) (fll: float list list) = DenseMatrix.OfColumnsCovariant(rows, cols, fll) let inline ofColumnsList (rows: int) (cols: int) (fll: float list list) = DenseMatrix.OfColumnsCovariant(rows, cols, fll)
/// Create a matrix from a list of column vectors.
let inline ofColumnVectors (vectors: #Vector<float> list) = DenseMatrix.OfColumnVectors(vectors |> Array.ofSeq |> box |> unbox)
/// Create a matrix with a given dimension from an indexed sequences of row, column, value tuples. /// 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) let inline ofSeqi (rows: int) (cols: int) (fs: #seq<int * int * float>) = DenseMatrix.OfIndexed(rows, cols, fs)

8
src/FSharpUnitTests/DenseMatrixTests.fs

@ -60,6 +60,10 @@ module DenseMatrixTests =
let ``DenseMatrix.ofRowsList`` () = let ``DenseMatrix.ofRowsList`` () =
DenseMatrix.ofRowsList 3 2 [[0.3;0.3];[0.3;0.3];[0.3;0.3]] |> should equal smallM DenseMatrix.ofRowsList 3 2 [[0.3;0.3];[0.3;0.3];[0.3;0.3]] |> should equal smallM
[<Test>]
let ``DenseMatrix.ofRowVectors`` () =
DenseMatrix.ofRowVectors [vector [0.3;0.3]; vector [0.3;0.3]; vector [0.3;0.3]] |> should equal smallM
[<Test>] [<Test>]
let ``DenseMatrix.ofColumn`` () = let ``DenseMatrix.ofColumn`` () =
DenseMatrix.ofColumns 3 2 (Seq.ofList [[0.3;0.3;0.3];[0.3;0.3;0.3]]) |> should equal smallM DenseMatrix.ofColumns 3 2 (Seq.ofList [[0.3;0.3;0.3];[0.3;0.3;0.3]]) |> should equal smallM
@ -68,6 +72,10 @@ module DenseMatrixTests =
let ``DenseMatrix.ofColumnsList`` () = let ``DenseMatrix.ofColumnsList`` () =
DenseMatrix.ofColumnsList 3 2 [[0.3;0.3;0.3];[0.3;0.3;0.3]] |> should equal smallM DenseMatrix.ofColumnsList 3 2 [[0.3;0.3;0.3];[0.3;0.3;0.3]] |> should equal smallM
[<Test>]
let ``DenseMatrix.ofColumnVectors`` () =
DenseMatrix.ofColumnVectors [vector [0.3;0.3;0.3]; vector [0.3;0.3;0.3]] |> should equal smallM
[<Test>] [<Test>]
let ``DenseMatrix.ofSeqi`` () = let ``DenseMatrix.ofSeqi`` () =
seq { for i in 0 .. 99 do for j in 0 .. 119 -> (i,j, float i * 100.0 + float j)} seq { for i in 0 .. 99 do for j in 0 .. 119 -> (i,j, float i * 100.0 + float j)}

Loading…
Cancel
Save