/LinAlg

A Haskell interface for specifying linear algebra computations

Primary LanguageHaskell

LinAlg

LinAlg is a Haskell library which provides an interface for specifying numeric linear algebra computations in a purely functional manner. Its interface is very much in the spirit of the Haskell library hmatrix. Array sizes are reflected statically in the types.

Backends exist to execute these computations on the CPU (using hmatrix) or on the GPU (using bindings to CUBLAS and MAGMA).

For example, suppose we'd like to express parameter estimation for ordinary least-squares linear regression:

import Numeric.LinAlg

-- | Given a matrix of features of input data (where
-- each row is a datum) and a vector of outputs,
-- compute the parameters which minimize the sum
-- of squared error.
linearRegression :: Matr k arr => arr (M n m) k -> arr (V n) k -> arr (V m) k
linearRegression x y = (trans x >< x) <\> (trans x >< y)

Backends

  1. HMatrix (included in this package) for execution of computations on the CPU. It depends on hmatrix, which in turn uses a CPU BLAS library as well as LAPACK.

It's a rather straightforward translation from hmatrix to LinAlg; in fact, the names for many functions are exactly the same.

The HMatrix backend is installed by default, but can be disabled by disabling the "hmatrix" flag (so the dependency on the hmatrix package is obviated).

  1. LinAlg-magma (an external package) for execution of computations on the GPU (using CUDA). It depends on the CUBLAS and MAGMA libraries, and so it depends on both Haskell bindings to CUBLAS as well as Haskell bindings to MAGMA.

Documentation

See the Haddock documentation.

Installation

It's just a simple Cabal package:

cabal install