bed-and-breakfast-0.2: Efficient Matrix operations in 100% Haskell.

Safe HaskellTrustworthy

Numeric.Matrix

Contents

Description

Efficient matrix operations in 100% pure Haskell.

This package uses miscellaneous implementations, depending on the type of its components. Typically unboxed arrays will perform best, while unboxed arrays give you certain features such as Rational or Complex components.

The following component types are supported by Matrix:

Int
Uses unboxed arrays internally. inv will always return Nothing.
Integer
Uses boxed arrays internally. inv will always return Nothing.
Double and Float
Uses unboxed arrays internally. All matrix operations will work as expected. Matrix Double will probably yield the best peformance.
Rational
Best choice if precision is what you aim for. Uses boxed arrays internally. All matrix operations will work as expected.
Complex
Experimental. Uses boxed arrays internally. The current implementation of inv requires an instance of Ord for the component type, therefor it is currently not possible to calculate the inverse of a complex matrix (on my to do list).

Synopsis

Documentation

data family Matrix e Source

class (Eq e, Num e) => MatrixElement e whereSource

Methods

matrix :: (Int, Int) -> ((Int, Int) -> e) -> Matrix eSource

select :: ((Int, Int) -> Bool) -> Matrix e -> [e]Source

at :: Matrix e -> (Int, Int) -> eSource

row :: Int -> Matrix e -> [e]Source

col :: Int -> Matrix e -> [e]Source

dimensions :: Matrix e -> (Int, Int)Source

numRows :: Matrix e -> IntSource

numCols :: Matrix e -> IntSource

fromList :: [[e]] -> Matrix eSource

toList :: Matrix e -> [[e]]Source

unit :: Int -> Matrix eSource

zero :: Int -> Matrix eSource

diag :: [e] -> Matrix eSource

empty :: Matrix eSource

minus :: Matrix e -> Matrix e -> Matrix eSource

plus :: Matrix e -> Matrix e -> Matrix eSource

times :: Matrix e -> Matrix e -> Matrix eSource

inv :: Matrix e -> Maybe (Matrix e)Source

det :: Matrix e -> eSource

transpose :: Matrix e -> Matrix eSource

rank :: Matrix e -> eSource

trace :: Matrix e -> [e]Source

map :: MatrixElement f => (e -> f) -> Matrix e -> Matrix fSource

all :: (e -> Bool) -> Matrix e -> BoolSource

any :: (e -> Bool) -> Matrix e -> BoolSource

mapWithIndex :: MatrixElement f => ((Int, Int) -> e -> f) -> Matrix e -> Matrix fSource

allWithIndex :: ((Int, Int) -> e -> Bool) -> Matrix e -> BoolSource

anyWithIndex :: ((Int, Int) -> e -> Bool) -> Matrix e -> BoolSource

Matrix property and utility functions.

Joins two matrices horizontally.

 1 2 3     1 0 0      1 2 3 1 0 0
 3 4 5 <|> 2 1 0  ->  3 4 5 2 1 0
 5 6 7     3 2 1      5 6 7 3 2 1

Joins two matrices vertically.

 1 2 3     1 0 0      1 2 3
 3 4 5 <-> 2 1 0  ->  3 4 5
 5 6 7     3 2 1      5 6 7
                      1 0 0
                      2 1 0
                      3 2 1

Scales a matrix by the given factor.

 scale s == map (*s)

Matrix properties

Check whether the matrix is an identity matrix.

 1 0 0
 0 1 0
 0 0 1 (True)

Check whether the matrix consists of all zeros.

 isZero == all (== 0)

Checks whether the matrix is a diagonal matrix.

 4 0 0 0
 0 7 0 0
 0 0 3 0
 0 0 0 9 (True)

Checks whether the matrix is empty.

 isEmpty m = numCols == 0 || numRows == 0

Checks whether the matrix is a square matrix.

 isSquare == uncurry (==) . dimensions