hmatrix: Linear algebra and numerical computations

[ bsd3, library, math ] [ Propose Tags ]

This library provides a purely functional interface to basic linear algebra and other numerical computations, internally implemented using GSL, BLAS and LAPACK.

[Skip to Readme]


Automatic Flags

Choose the new smaller, split-up base package.


Link with Intel's MKL optimized libraries.


Compile the library with bound checking disabled.


Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Versions [RSS],,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, 0.20.1, 0.20.2
Dependencies array, base, haskell98, HUnit, QuickCheck, storable-complex [details]
License LicenseRef-GPL
Author Alberto Ruiz
Maintainer Alberto Ruiz <>
Category Math
Home page
Uploaded by AlbertoRuiz at 2008-11-15T13:20:15Z
Distributions Debian:, LTSHaskell:0.20.2, NixOS:0.20.2, Stackage:0.20.2
Reverse Dependencies 123 direct, 54 indirect [details]
Downloads 74518 total (253 in the last 30 days)
Rating 2.5 (votes: 9) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for hmatrix-

[back to package description]
 A simple scientific library for Haskell


Recommended method (ok in Ubuntu/Debian systems):
    $ sudo apt-get install libgsl0-dev refblas3-dev lapack3-dev atlas3-[your_arch]-dev
    $ cabal install hmatrix

Detailed installation instructions:

For installation in Windows see the companion INSTALL file.

TESTS ---------------------------------------------

$ ghci
GHCi, version 6.8.2:  :? for help
Prelude> Numeric.LinearAlgebra.Tests.runTests 20

Additional tests with big matrices (taking a few minutes):

$ runhaskell examples/experiments/bigtests

EXAMPLES ------------------------------------------------------

$ ghci
Prelude> :m + Numeric.GSL
Prelude Numeric.GSL> let quad = integrateQNG 1E-10
Prelude Numeric.GSL> quad (^2) 0 1

Prelude Numeric.GSL> :m + Numeric.LinearAlgebra
Prelude Numeric.LinearAlgebra> let m = (2><3)[1,2,3,4,5,6::Double]
Prelude Numeric.LinearAlgebra> let (u,d,v) = full svd m
Prelude Numeric.LinearAlgebra> d
 [ 9.508032000695724,                0.0, 0.0
 ,               0.0, 0.7728696356734838, 0.0 ]
Prelude Numeric.LinearAlgebra> u <> d <> trans v
 [ 1.0000000000000004,               2.0, 3.0
 , 3.9999999999999996, 5.000000000000001, 6.0 ]
Prelude Numeric.GSL> :q
Leaving GHCi.

A number of illustrative programs are included in the examples folder.

KNOWN PROBLEMS / BUGS -------------------------------

- On 64-bit machines the example "minimize.hs", when run from ghci,
  produces a segmentation fault. It happens in the call to
  gsl_multimin_fdfminimizer_alloc, inside the C wrapper.
  If the program is called by runhaskell, it just terminates
  prematurely, producing no results. Curiously, in compiled mode the
  program seems to work perfectly well.

- On Ubuntu 6.06 LTS (Dapper) atlas3-sse2-dev (3.6.0-20)
  produced segmentation faults when working with big matrices
  on compiled programs.

- On distributions with old GSL versions you should comment out a couple of functions
  in the export lists of Ellint.hs and Debye.hs

ACKNOWLEDGEMENTS -----------------------------------------------------

I thank Don Stewart, Henning Thielemann, Bulat Ziganshin and all the people
in the Haskell mailing lists for their help.

- Nico Mahlo discovered a bug in the eigendecomposition wrapper.

- Frederik Eaton discovered a bug in the design of the wrappers.

- Eric Kidd has created a wiki page explaining the installation on MacOS X:

- Fawzi Mohamed discovered a portability bug in the lapack wrappers.

- Pedro E. López de Teruel fixed the interface to lapack.

- Antti Siira discovered a bug in the plotting functions.

- Paulo Tanimoto helped to fix the configuration of the required libraries.
  He also discovered the segfault of minimize.hs in ghci.

- Xiao-Yong Jin reported a bug on x86_64 caused by the assumptions in f2c.h,
  which are wrong for this architecture.

- Jason Schroeder reported an error in the documentation.

- Bulat Ziganshin gave invaluable help for the ST monad interface to
  in-place modifications.

- Don Stewart fixed the implementation of the internal data structures
  to achieve excellent, C-like performance in Haskell functions which
  explicitly work with the elements of vectors and matrices.

- Dylan Alex Simon improved the numeric instances to allow optimized
  implementations of signum and abs on Vectors.

- Pedro E. López de Teruel discovered the need of asm("finit") to
  avoid the wrong NaNs produced by foreign functions.

- Reiner Pope added support for luSolve, based on (d|z)getrs.