Browse Source

F#: Simplify and clarify project file structure

pull/61/merge
Christoph Ruegg 14 years ago
parent
commit
892bbe510e
  1. 2
      src/FSharp/AssemblyInfo.fs
  2. 101
      src/FSharp/DenseMatrix.fs
  3. 69
      src/FSharp/DenseVector.fs
  4. 12
      src/FSharp/FSharp.fsproj
  5. 119
      src/FSharp/LinearAlgebra.Double.Matrix.fs
  6. 61
      src/FSharp/LinearAlgebra.Double.Vector.fs
  7. 4
      src/FSharp/LinearAlgebra.fs
  8. 4
      src/FSharp/Main.fs
  9. 75
      src/FSharp/SparseMatrix.fs
  10. 48
      src/FSharp/SparseVector.fs
  11. 27
      src/FSharpPortable/FSharpPortable.fsproj

2
src/FSharp/AssemblyInfo.fs

@ -35,7 +35,7 @@ open System.Resources;
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
[<assembly: AssemblyTitle("Math.NET Numerics F# Modules")>]
[<assembly: AssemblyTitle("Math.NET Numerics for F#")>]
[<assembly: AssemblyDescription("F# Modules for Math.NET Numerics, providing methods and algorithms for numerical computations in science, engineering and every day use.")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("Math.NET Project")>]

101
src/FSharp/DenseMatrix.fs

@ -1,101 +0,0 @@
// <copyright file="DenseMatrix.fs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://mathnet.opensourcedotnet.info
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Double
open MathNet.Numerics.LinearAlgebra
open MathNet.Numerics.LinearAlgebra.Generic
/// A module which implements functional dense vector operations.
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.[i,j] <- f i j
A
/// 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) =
let n = List.length fll
let m = List.length (List.head fll)
let A = DenseMatrix(n,m)
fll |> List.iteri (fun i fl ->
if (List.length fl) <> m then failwith "Each subrow must be of the same length." else
List.iteri (fun j f -> A.[i,j] <- f) fl)
A
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a row.
let inline ofSeq (fss: #seq<#seq<float>>) =
let n = Seq.length fss
let m = Seq.length (Seq.head fss)
let A = DenseMatrix(n,m)
fss |> Seq.iteri (fun i fs ->
if (Seq.length fs) <> m then failwith "Each subrow must be of the same length." else
Seq.iteri (fun j f -> A.[i,j] <- f) fs)
A
/// Create a matrix from a 2D array of floating point numbers.
let inline ofArray2 (arr: float[,]) = new DenseMatrix(arr)
/// Create a matrix with the given entries.
let inline initDense (n: int) (m: int) (es: #seq<int * int * float>) =
let A = new DenseMatrix(n,m)
Seq.iter (fun (i,j,f) -> A.[i,j] <- f) es
A
/// Create a square matrix with constant diagonal entries.
let inline constDiag (n: int) (f: float) =
let A = new DenseMatrix(n,n)
for i=0 to n-1 do
A.[i,i] <- f
A
/// Create a square matrix with the vector elements on the diagonal.
let inline diag (v: #Vector<float>) =
let n = v.Count
let A = new DenseMatrix(n,n)
for i=0 to n-1 do
A.[i,i] <- v.Item(i)
A
/// Initialize a matrix by calling a construction function for every row.
let inline initRow (n: int) (m: int) (f: int -> #Vector<float>) =
let A = new DenseMatrix(n,m)
for i=0 to n-1 do A.SetRow(i, f i)
A
/// Initialize a matrix by calling a construction function for every column.
let inline initCol (n: int) (m: int) (f: int -> #Vector<float>) =
let A = new DenseMatrix(n,m)
for i=0 to m-1 do A.SetColumn(i, f i)
A

69
src/FSharp/DenseVector.fs

@ -1,69 +0,0 @@
// <copyright file="DenseVector.fs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Double
open MathNet.Numerics.LinearAlgebra
/// A module which implements functional dense vector operations.
module DenseVector =
/// Initialize a vector by calling a construction function for every element.
let inline init (n: int) f =
let v = new Double.DenseVector(n)
for i=0 to n-1 do
v.[i] <- f i
v
/// Create a vector from a float list.
let inline ofList (fl: float list) =
let n = List.length fl
let v = Double.DenseVector(n)
fl |> List.iteri (fun i f -> v.[i] <- f)
v
/// Create a vector from a sequences.
let inline ofSeq (fs: #seq<float>) =
let n = Seq.length fs
let v = DenseVector(n)
fs |> Seq.iteri (fun i f -> v.[i] <- f)
v
/// Create a vector with evenly spaced entries: e.g. rangef -1.0 0.5 1.0 = [-1.0 -0.5 0.0 0.5 1.0]
let inline rangef (start: float) (step: float) (stop: float) =
let n = (int ((stop - start) / step)) + 1
let v = new DenseVector(n)
for i=0 to n-1 do
v.[i] <- (float i) * step + start
v
/// Create a vector with integer entries in the given range.
let inline range (start: int) (stop: int) =
new DenseVector([| for i in [start .. stop] -> float i |])

12
src/FSharp/FSharp.fsproj

@ -50,15 +50,11 @@
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition="(!Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')) And (Exists('$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets'))" />
<Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="(!Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')) And (!Exists('$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets')) And (Exists('$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets'))" />
<ItemGroup>
<Compile Include="Extensions.fs" />
<Compile Include="DenseVector.fs" />
<Compile Include="DenseMatrix.fs" />
<Compile Include="SparseMatrix.fs" />
<Compile Include="SparseVector.fs" />
<Compile Include="Vector.fs" />
<Compile Include="Matrix.fs" />
<Compile Include="Main.fs" />
<Compile Include="AssemblyInfo.fs" />
<Compile Include="LinearAlgebra.fs" />
<Compile Include="LinearAlgebra.Double.Vector.fs" />
<Compile Include="LinearAlgebra.Double.Matrix.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Core" />

119
src/FSharp/Matrix.fs → src/FSharp/LinearAlgebra.Double.Matrix.fs

@ -1,10 +1,10 @@
// <copyright file="Matrix.fs" company="Math.NET">
// <copyright file="LinearAlgebra.Double.Matrix.fs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009 Math.NET
// Copyright (c) 2009-2012 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -30,10 +30,10 @@
namespace MathNet.Numerics.LinearAlgebra.Double
open MathNet.Numerics.LinearAlgebra.Double
open MathNet.Numerics.LinearAlgebra.Generic
/// A module which implements functional matrix operations.
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Matrix =
/// Fold a function over all matrix elements.
@ -240,4 +240,115 @@ module Matrix =
for i=0 to A.ColumnCount-1 do
macc <- f macc (A.Item(k,i))
v.[k] <- macc
v :> Vector<float>
v :> Vector<float>
/// A module which implements functional dense vector operations.
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
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.[i,j] <- f i j
A
/// 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) =
let n = List.length fll
let m = List.length (List.head fll)
let A = DenseMatrix(n,m)
fll |> List.iteri (fun i fl ->
if (List.length fl) <> m then failwith "Each subrow must be of the same length." else
List.iteri (fun j f -> A.[i,j] <- f) fl)
A
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a row.
let inline ofSeq (fss: #seq<#seq<float>>) =
let n = Seq.length fss
let m = Seq.length (Seq.head fss)
let A = DenseMatrix(n,m)
fss |> Seq.iteri (fun i fs ->
if (Seq.length fs) <> m then failwith "Each subrow must be of the same length." else
Seq.iteri (fun j f -> A.[i,j] <- f) fs)
A
/// Create a matrix from a 2D array of floating point numbers.
let inline ofArray2 (arr: float[,]) = new DenseMatrix(arr)
/// Create a matrix with the given entries.
let inline initDense (n: int) (m: int) (es: #seq<int * int * float>) =
let A = new DenseMatrix(n,m)
Seq.iter (fun (i,j,f) -> A.[i,j] <- f) es
A
/// Create a square matrix with constant diagonal entries.
let inline constDiag (n: int) (f: float) =
let A = new DenseMatrix(n,n)
for i=0 to n-1 do
A.[i,i] <- f
A
/// Create a square matrix with the vector elements on the diagonal.
let inline diag (v: #Vector<float>) =
let n = v.Count
let A = new DenseMatrix(n,n)
for i=0 to n-1 do
A.[i,i] <- v.Item(i)
A
/// Initialize a matrix by calling a construction function for every row.
let inline initRow (n: int) (m: int) (f: int -> #Vector<float>) =
let A = new DenseMatrix(n,m)
for i=0 to n-1 do A.SetRow(i, f i)
A
/// Initialize a matrix by calling a construction function for every column.
let inline initCol (n: int) (m: int) (f: int -> #Vector<float>) =
let A = new DenseMatrix(n,m)
for i=0 to m-1 do A.SetColumn(i, f i)
A
/// A module which implements functional sparse vector operations.
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module SparseMatrix =
/// 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)
fll |> List.iter (fun (i, j, x) -> A.[i,j] <- x)
A
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a row.
let inline ofSeq (rows: int) (cols: int) (fss: #seq<int * int * float>) =
let A = new SparseMatrix(rows, cols)
fss |> Seq.iter (fun (i, j, x) -> A.[i,j] <- x)
A
/// Create a square matrix with constant diagonal entries.
let inline constDiag (n: int) (f: float) =
let A = new SparseMatrix(n,n)
for i=0 to n-1 do
A.[i,i] <- f
A
/// Create a square matrix with the vector elements on the diagonal.
let inline diag (v: #Vector<float>) =
let n = v.Count
let A = new SparseMatrix(n,n)
for i=0 to n-1 do
A.[i,i] <- v.Item(i)
A
/// Initialize a matrix by calling a construction function for every row.
let inline initRow (n: int) (m: int) (f: int -> #Vector<float>) =
let A = new SparseMatrix(n,m)
for i=0 to n-1 do A.SetRow(i, f i)
A
/// Initialize a matrix by calling a construction function for every column.
let inline initCol (n: int) (m: int) (f: int -> #Vector<float>) =
let A = new SparseMatrix(n,m)
for i=0 to m-1 do A.SetColumn(i, f i)
A

61
src/FSharp/Vector.fs → src/FSharp/LinearAlgebra.Double.Vector.fs

@ -1,10 +1,10 @@
// <copyright file="Vector.fs" company="Math.NET">
// <copyright file="LinearAlgebra.Double.Vector.fs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009 Math.NET
// Copyright (c) 2009-2012 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -30,10 +30,10 @@
namespace MathNet.Numerics.LinearAlgebra.Double
open MathNet.Numerics.LinearAlgebra
open MathNet.Numerics.LinearAlgebra.Generic
/// A module which implements functional vector operations.
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Vector =
/// Transform a vector into an array.
@ -184,4 +184,57 @@ module Vector =
newV.Item(index) <- value
for i = index + 1 to v.Count do
newV.Item(i) <- v.Item(i - 1)
newV
newV
/// A module which implements functional dense vector operations.
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
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.[i] <- f i
v
/// Create a vector from a float list.
let inline ofList (fl: float list) =
let n = List.length fl
let v = DenseVector(n)
fl |> List.iteri (fun i f -> v.[i] <- f)
v
/// Create a vector from a sequences.
let inline ofSeq (fs: #seq<float>) =
let n = Seq.length fs
let v = DenseVector(n)
fs |> Seq.iteri (fun i f -> v.[i] <- f)
v
/// Create a vector with evenly spaced entries: e.g. rangef -1.0 0.5 1.0 = [-1.0 -0.5 0.0 0.5 1.0]
let inline rangef (start: float) (step: float) (stop: float) =
let n = (int ((stop - start) / step)) + 1
let v = new DenseVector(n)
for i=0 to n-1 do
v.[i] <- (float i) * step + start
v
/// Create a vector with integer entries in the given range.
let inline range (start: int) (stop: int) =
new DenseVector([| for i in [start .. stop] -> float i |])
/// A module which implements functional sparse vector operations.
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module SparseVector =
/// 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)
fl |> List.iter (fun (i, f) -> v.[i] <- f)
v
/// Create a sparse vector with a given dimension from a sequence of entry, value pairs.
let inline ofSeq (dim: int) (fs: #seq<int * float>) =
let v = new SparseVector(dim)
fs |> Seq.iter (fun (i, f) -> v.[i] <- f)
v

4
src/FSharp/Extensions.fs → src/FSharp/LinearAlgebra.fs

@ -1,10 +1,10 @@
// <copyright file="Extensions.fs" company="Math.NET">
// <copyright file="LinearAlgebra.fs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009 Math.NET
// Copyright (c) 2009-2012 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation

4
src/FSharp/Main.fs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009 Math.NET
// Copyright (c) 2009-2012 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -30,8 +30,8 @@
namespace MathNet.Numerics
open MathNet.Numerics.LinearAlgebra.Double
open MathNet.Numerics.LinearAlgebra.Generic
open MathNet.Numerics.LinearAlgebra.Double
/// A module which implements some F# utility functions.
module FSharp =

75
src/FSharp/SparseMatrix.fs

@ -1,75 +0,0 @@
// <copyright file="SparseMatrix.fs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Double
open MathNet.Numerics.LinearAlgebra
open MathNet.Numerics.LinearAlgebra.Generic
/// A module which implements functional sparse vector operations.
module SparseMatrix =
/// 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 Double.SparseMatrix(rows, cols)
fll |> List.iter (fun (i, j, x) -> A.[i,j] <- x)
A
/// Create a matrix from a list of sequences. Every sequence in the master sequence specifies a row.
let inline ofSeq (rows: int) (cols: int) (fss: #seq<int * int * float>) =
let A = new Double.SparseMatrix(rows, cols)
fss |> Seq.iter (fun (i, j, x) -> A.[i,j] <- x)
A
/// Create a square matrix with constant diagonal entries.
let inline constDiag (n: int) (f: float) =
let A = new Double.SparseMatrix(n,n)
for i=0 to n-1 do
A.[i,i] <- f
A
/// Create a square matrix with the vector elements on the diagonal.
let inline diag (v: #Vector<float>) =
let n = v.Count
let A = new Double.SparseMatrix(n,n)
for i=0 to n-1 do
A.[i,i] <- v.Item(i)
A
/// Initialize a matrix by calling a construction function for every row.
let inline initRow (n: int) (m: int) (f: int -> #Vector<float>) =
let A = new Double.SparseMatrix(n,m)
for i=0 to n-1 do A.SetRow(i, f i)
A
/// Initialize a matrix by calling a construction function for every column.
let inline initCol (n: int) (m: int) (f: int -> #Vector<float>) =
let A = new Double.SparseMatrix(n,m)
for i=0 to m-1 do A.SetColumn(i, f i)
A

48
src/FSharp/SparseVector.fs

@ -1,48 +0,0 @@
// <copyright file="SparseVector.fs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Double
open MathNet.Numerics.LinearAlgebra
/// A module which implements functional sparse vector operations.
module SparseVector =
/// 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 Double.SparseVector(dim)
fl |> List.iter (fun (i, f) -> v.[i] <- f)
v
/// Create a sparse vector with a given dimension from a sequence of entry, value pairs.
let inline ofSeq (dim: int) (fs: #seq<int * float>) =
let v = new Double.SparseVector(dim)
fs |> Seq.iter (fun (i, f) -> v.[i] <- f)
v

27
src/FSharpPortable/FSharpPortable.fsproj

@ -41,30 +41,21 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\FSharp\DenseMatrix.fs">
<Link>DenseMatrix.fs</Link>
<Compile Include="..\FSharp\AssemblyInfo.fs">
<Link>AssemblyInfo.fs</Link>
</Compile>
<Compile Include="..\FSharp\DenseVector.fs">
<Link>DenseVector.fs</Link>
<Compile Include="..\FSharp\LinearAlgebra.fs">
<Link>LinearAlgebra.fs</Link>
</Compile>
<Compile Include="..\FSharp\Extensions.fs">
<Link>Extensions.fs</Link>
<Compile Include="..\FSharp\LinearAlgebra.Double.Matrix.fs">
<Link>LinearAlgebra.Double.Matrix.fs</Link>
</Compile>
<Compile Include="..\FSharp\LinearAlgebra.Double.Vector.fs">
<Link>LinearAlgebra.Double.Vector.fs</Link>
</Compile>
<Compile Include="..\FSharp\Main.fs">
<Link>Main.fs</Link>
</Compile>
<Compile Include="..\FSharp\Matrix.fs">
<Link>Matrix.fs</Link>
</Compile>
<Compile Include="..\FSharp\SparseMatrix.fs">
<Link>SparseMatrix.fs</Link>
</Compile>
<Compile Include="..\FSharp\SparseVector.fs">
<Link>SparseVector.fs</Link>
</Compile>
<Compile Include="..\FSharp\Vector.fs">
<Link>Vector.fs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Portable\Portable.csproj">

Loading…
Cancel
Save