FsAlg


FsAlg: Generic Linear Algebra Library

FsAlg is a linear algebra library that supports generic types. It is implemented in the F# language.

The library provides generic Vector and Matrix types that support most of the commonly used linear algebra operations, including matrix–vector operations, matrix inverse, determinants, eigenvalues, LU and QR decompositions. Its intended use is to enable writing generic linear algebra code with custom numeric types. It can also be used as a lightweight library for prototyping and scripting with primitive floating point types.

FsAlg is developed by Atılım Güneş Baydin and Barak A. Pearlmutter as part of their work at the Brain and Computation Lab, Hamilton Institute, National University of Ireland Maynooth.

How to Get

You can install the library via NuGet. You can also download the source code or the binaries of the latest release on GitHub.

The FsAlg library is available on NuGet. To install, run the following command in the Package Manager Console:
PM> Install-Package FsAlg

Quick Usage Example

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
open FsAlg.Generic

let A = matrix [[3.; 1.]; [2.; -1.]]
let b = vector [5.; 0.]

// Solve a matrix equation
let x = Matrix.solve A b

// Find inverse of A
let Ainv = Matrix.inverse A

// Initialize a vector
let w = Vector.init 2 (fun i -> float (i * i))

// Map a function to a vector
let y = Vector.map (fun x -> sin (exp x)) w

// Matrix-vector operations
let z = A * (x - y)
namespace FsAlg
namespace FsAlg.Generic
val A : Matrix<float>

Full name: Index.A
val matrix : m:seq<seq<'T>> -> Matrix<'T> (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)

Full name: FsAlg.Generic.Ops.matrix
val b : Vector<float>

Full name: Index.b
val vector : v:seq<'T> -> Vector<'T> (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)

Full name: FsAlg.Generic.Ops.vector
val x : Vector<float>

Full name: Index.x
Multiple items
union case Matrix.Matrix: 'T [,] -> Matrix<'T>

--------------------
module Matrix

from FsAlg.Generic

--------------------
type Matrix<'T (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)> =
  | ZeroMatrix of 'T
  | Matrix of 'T [,]
  member Copy : unit -> Matrix<'T>
  member GetDeterminant : unit -> 'T
  member GetDiagonal : unit -> 'T []
  member GetEigenvalues : unit -> 'T []
  member GetEnumerator : unit -> IEnumerator<'T>
  member GetInverse : unit -> Matrix<'T>
  member GetLUDecomposition : unit -> Matrix<'T> * int [] * 'T
  member GetQRDecomposition : unit -> Matrix<'T> * Matrix<'T>
  member GetSlice : rowStart:int option * rowFinish:int option * col:int -> Matrix<'T>
  member GetSlice : row:int * colStart:int option * colFinish:int option -> Matrix<'T>
  member GetSlice : rowStart:int option * rowFinish:int option * colStart:int option * colFinish:int option -> Matrix<'T>
  member GetTrace : unit -> 'T
  member GetTranspose : unit -> Matrix<'T>
  member ToArray : unit -> 'T [] []
  member ToArray2D : unit -> 'T [,]
  member ToMathematicaString : unit -> string
  member ToMatlabString : unit -> string
  member ToSeq : unit -> seq<'T>
  member Cols : int
  member Item : i:int * j:int -> 'T with get
  member Rows : int
  member Item : i:int * j:int -> 'T with set
  static member Zero : Matrix<'T>
  static member ( + ) : a:'T * b:Matrix<'T> -> Matrix<'T>
  static member ( + ) : a:Matrix<'T> * b:'T -> Matrix<'T>
  static member ( + ) : a:Matrix<'T> * b:Matrix<'T> -> Matrix<'T>
  static member ( / ) : a:'T * b:Matrix<'T> -> Matrix<'T>
  static member ( / ) : a:Matrix<'T> * b:'T -> Matrix<'T>
  static member ( ./ ) : a:Matrix<'T> * b:Matrix<'T> -> Matrix<'T>
  static member ( .* ) : a:Matrix<'T> * b:Matrix<'T> -> Matrix<'T>
  static member op_Explicit : m:Matrix<'T> -> float [,]
  static member ( * ) : a:'T * b:Matrix<'T> -> Matrix<'T>
  static member ( * ) : a:Matrix<'T> * b:'T -> Matrix<'T>
  static member ( * ) : a:Vector<'T> * b:Matrix<'T> -> Vector<'T>
  static member ( * ) : a:Matrix<'T> * b:Vector<'T> -> Vector<'T>
  static member ( * ) : a:Matrix<'T> * b:Matrix<'T> -> Matrix<'T>
  static member ( - ) : a:'T * b:Matrix<'T> -> Matrix<'T>
  static member ( - ) : a:Matrix<'T> * b:'T -> Matrix<'T>
  static member ( - ) : a:Matrix<'T> * b:Matrix<'T> -> Matrix<'T>
  static member ( ~- ) : a:Matrix<'T> -> Matrix<'T>

Full name: FsAlg.Generic.Matrix<_>
val solve : a:Matrix<'T> -> b:Vector<'T> -> Vector<'T> (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)

Full name: FsAlg.Generic.Matrix.solve
val Ainv : Matrix<float>

Full name: Index.Ainv
val inverse : m:Matrix<'T> -> Matrix<'T> (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)

Full name: FsAlg.Generic.Matrix.inverse
val w : Vector<float>

Full name: Index.w
Multiple items
union case Vector.Vector: 'T [] -> Vector<'T>

--------------------
module Vector

from FsAlg.Generic

--------------------
type Vector<'T (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)> =
  | ZeroVector of 'T
  | Vector of 'T []
  member Convert : f:('T -> 'a) -> Vector<'a> (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)
  member Copy : unit -> Vector<'T>
  member GetEnumerator : unit -> IEnumerator<'T>
  member GetL1Norm : unit -> 'T
  member GetL2Norm : unit -> 'T
  member GetL2NormSq : unit -> 'T
  member GetLPNorm : p:'T -> 'T
  member GetMax : unit -> 'T
  member GetMaxBy : f:('T -> 'a1) -> 'T (requires comparison)
  member GetMin : unit -> 'T
  member GetMinBy : f:('T -> 'a1) -> 'T (requires comparison)
  member GetSlice : lower:int option * upper:int option -> Vector<'T>
  member GetSubVector : s:int * c:int -> Vector<'T>
  member GetUnitVector : unit -> Vector<'T>
  member Split : n:seq<int> -> seq<Vector<'T>>
  member SplitEqual : n:int -> seq<Vector<'T>>
  member ToArray : unit -> 'T []
  member ToMathematicaString : unit -> string
  member ToMatlabString : unit -> string
  member ToSeq : unit -> seq<'T>
  member FirstItem : 'T
  member Item : i:int -> 'T with get
  member Length : int
  member Item : i:int -> 'T with set
  static member Zero : Vector<'T>
  static member ( + ) : a:'T * b:Vector<'T> -> Vector<'T>
  static member ( + ) : a:Vector<'T> * b:'T -> Vector<'T>
  static member ( + ) : a:Vector<'T> * b:Vector<'T> -> Vector<'T>
  static member ( / ) : a:'T * b:Vector<'T> -> Vector<'T>
  static member ( / ) : a:Vector<'T> * b:'T -> Vector<'T>
  static member ( ./ ) : a:Vector<'T> * b:Vector<'T> -> Vector<'T>
  static member ( .* ) : a:Vector<'T> * b:Vector<'T> -> Vector<'T>
  static member op_Explicit : v:Vector<'T> -> float []
  static member ( * ) : a:'T * b:Vector<'T> -> Vector<'T>
  static member ( * ) : a:Vector<'T> * b:'T -> Vector<'T>
  static member ( * ) : a:Vector<'T> * b:Vector<'T> -> 'T
  static member ( %* ) : a:Vector<'T> * b:Vector<'T> -> Vector<'T>
  static member ( - ) : a:'T * b:Vector<'T> -> Vector<'T>
  static member ( - ) : a:Vector<'T> * b:'T -> Vector<'T>
  static member ( - ) : a:Vector<'T> * b:Vector<'T> -> Vector<'T>
  static member ( ~- ) : a:Vector<'T> -> Vector<'T>

Full name: FsAlg.Generic.Vector<_>
val init : n:int -> f:(int -> 'T) -> Vector<'T> (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)

Full name: FsAlg.Generic.Vector.init
val i : int
Multiple items
val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = System.Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
val y : Vector<float>

Full name: Index.y
val map : f:('T -> 'U) -> v:Vector<'T> -> Vector<'U> (requires member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison and member get_Zero and member get_One and member ( + ) and member ( - ) and member ( * ) and member ( / ) and member ( ~- ) and member Abs and member Pow and member Sqrt and member op_Explicit and comparison)

Full name: FsAlg.Generic.Vector.map
val x : float
val sin : value:'T -> 'T (requires member Sin)

Full name: Microsoft.FSharp.Core.Operators.sin
val exp : value:'T -> 'T (requires member Exp)

Full name: Microsoft.FSharp.Core.Operators.exp
val z : Vector<float>

Full name: Index.z