diff --git a/src/FSharp/LinearAlgebra.Double.Matrix.fs b/src/FSharp/LinearAlgebra.Double.Matrix.fs index ea5d3f88..32215ebd 100644 --- a/src/FSharp/LinearAlgebra.Double.Matrix.fs +++ b/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. 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 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. let inline ofColumns (rows: int) (cols: int) (fss: #seq<#seq>) = DenseMatrix.OfColumnsCovariant(rows, cols, fss) /// 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) + /// Create a matrix from a list of column vectors. + let inline ofColumnVectors (vectors: #Vector list) = DenseMatrix.OfColumnVectors(vectors |> Array.ofSeq |> box |> unbox) + /// 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) = DenseMatrix.OfIndexed(rows, cols, fs) diff --git a/src/FSharpUnitTests/DenseMatrixTests.fs b/src/FSharpUnitTests/DenseMatrixTests.fs index 055210fa..1af975b2 100644 --- a/src/FSharpUnitTests/DenseMatrixTests.fs +++ b/src/FSharpUnitTests/DenseMatrixTests.fs @@ -60,6 +60,10 @@ module DenseMatrixTests = let ``DenseMatrix.ofRowsList`` () = DenseMatrix.ofRowsList 3 2 [[0.3;0.3];[0.3;0.3];[0.3;0.3]] |> should equal smallM + [] + let ``DenseMatrix.ofRowVectors`` () = + DenseMatrix.ofRowVectors [vector [0.3;0.3]; vector [0.3;0.3]; vector [0.3;0.3]] |> should equal smallM + [] let ``DenseMatrix.ofColumn`` () = 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`` () = DenseMatrix.ofColumnsList 3 2 [[0.3;0.3;0.3];[0.3;0.3;0.3]] |> should equal smallM + [] + let ``DenseMatrix.ofColumnVectors`` () = + DenseMatrix.ofColumnVectors [vector [0.3;0.3;0.3]; vector [0.3;0.3;0.3]] |> should equal smallM + [] let ``DenseMatrix.ofSeqi`` () = seq { for i in 0 .. 99 do for j in 0 .. 119 -> (i,j, float i * 100.0 + float j)}