Efficient Matrix operations in 100% Haskell.

Latest on Hackage:0.4.3

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow to host generated Haddocks.

MIT licensed and maintained by Julian Fleischer


Matrix operations in 100% pure Haskell.

Bed and Breakfast is a linear algebra library written in Haskell. It provides fast matrix operations like finding the determinant or the inverse of a matrix.

Example (GHCi Session)

*Numeric.Matrix> let m = fromList [[0,3,2],[5,6,10],[4,3,2.0]] :: Matrix Double
*Numeric.Matrix> inv m
Just  -0.2499999999999999  0.0  0.25
0.4166666666666667  -0.11111111111111112  0.1388888888888889
-0.12500000000000006  0.16666666666666669  -0.20833333333333334

*Numeric.Matrix> let m = fromList [[0,3,2],[5,6,10],[4,3,2.0]] :: Matrix Rational
*Numeric.Matrix> inv m
Just  (-1) % 4  0 % 1  1 % 4
5 % 12  (-1) % 9  5 % 36
(-1) % 8  1 % 6  (-5) % 24

Example (with Template Haskell Syntactic Sugar)

{-# LANGUAGE Haskell2010, TemplateHaskell, QuasiQuotes #-}

import Numeric.Matrix
import Numeric.Matrix.Sugar

m :: Matrix Double
m = [dMatrix| 20   30 40
              40.5 71 23
              20   20 27 |]

mInv = maybe (error "not invertible") id $ inv m


Initial version, features det, basic arithmetic operations, and instances for Float, Double, Complex, and Rational.
Fixed wrong algorithm for computing the inverse of a Matrix.
Added instances for Num Matrix, Fractional Matrix, and Eq Matrix.
inv is now a total function and will no longer call error if a matrix is not invertible. Also Matrix derives Data.Typeable. now.
Added scale, and methods for joining matrices vertically and horizontally. Corrected a bug in isUnit reported by Charles Durham. isUnit returned True for any matrix for which all (== 1) . trace would have, which is wrong).
A little bit more documentation. Also moved some functions (isXXX) away from the type class MatrixElement. Properly flagged the package as experimental (was improperly marked as stable, copied form a template).
Added cofactors, adjugate, minor, and minorMatrix.
rank works now for any Matrix component type.
Added Read instance for Matrix. Improved on documentation.
Added a QuickCheck test suite, fixed a bug in det (det would crash for singular matrices, where it should return 0).
Added TemplateHaskell syntactic sugar (see Numeric.Matrix.Sugar). Rewrote multiplication. matrix function build an array faster now.
Numeric.Matrix.Sugar was not mentioned in the cabal file. Improved test suite. Improved documentation.
Fixed a bug regarding empty and fromList. Use unsafe operations where it is safe for speed. Added RULES. Added an instance for binary.
The unsafe operations used in v0.4 turned out to fatally fail on certain platforms. Revoked this change.
Fixed a tiny bug regarding the row function for extracting the number of rows in a Matrix. Thanks to Tim Makarios for finding and fixing the bug.
Fixed a bug in @transpose@ that prevented it from working correctly with non-square matrices. Thanks to @owst@ from
Used by 1 package:
comments powered byDisqus