Browse Source

FSharp: leverage functional matrix/vector init of core

pull/112/head
Christoph Ruegg 13 years ago
parent
commit
e40928256e
  1. 10
      src/FSharp/LinearAlgebra.Double.Matrix.fs
  2. 9
      src/FSharp/LinearAlgebra.Double.Vector.fs

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

@ -247,12 +247,7 @@ module Matrix =
module DenseMatrix =
/// Initialize a matrix by calling a construction function for every element.
let inline init (n: int) (m: int) f =
let A = new DenseMatrix(n,m)
for i=0 to n-1 do
for j=0 to m-1 do
A.At(i, j, f i j)
A
let inline init (n: int) (m: int) (f: int -> int -> float) = DenseMatrix.Create(n, m, fun n m -> f n m)
/// Create a matrix from a list of float lists. Every list in the master list specifies a row.
let inline ofList (fll: float list list) =
@ -314,6 +309,9 @@ module DenseMatrix =
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module SparseMatrix =
/// Initialize a matrix by calling a construction function for every element.
let inline init (n: int) (m: int) (f: int -> int -> float) = SparseMatrix.Create(n, m, fun n m -> f n m)
/// Create a matrix from a list of float lists. Every list in the master list specifies a row.
let inline ofList (rows: int) (cols: int) (fll: list<int * int * float>) =
let A = new SparseMatrix(rows, cols)

9
src/FSharp/LinearAlgebra.Double.Vector.fs

@ -187,11 +187,7 @@ module Vector =
module DenseVector =
/// Initialize a vector by calling a construction function for every element.
let inline init (n: int) f =
let v = new DenseVector(n)
for i=0 to n-1 do
v.At(i, f i)
v
let inline init (n: int) (f: int -> float) = DenseVector.Create(n, fun i -> f i)
/// Create a vector from a float list.
let inline ofList (fl: float list) = DenseVector(Array.ofList fl)
@ -215,6 +211,9 @@ module DenseVector =
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module SparseVector =
/// Initialize a vector by calling a construction function for every element.
let inline init (n: int) (f: int -> float) = SparseVector.Create(n, fun i -> f i)
/// Create a sparse vector with a given dimension from a list of entry, value pairs.
let inline ofList (dim: int) (fl: list<int * float>) =
let v = new SparseVector(dim)

Loading…
Cancel
Save