Safe Haskell | Trustworthy |
---|
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 returnNothing
. Integer
- Uses boxed arrays internally.
inv
will always returnNothing
. Double
andFloat
- 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 ofOrd
for the component type, therefor it is currently not possible to calculate the inverse of a complex matrix (on my to do list).
- data family Matrix e
- class (Eq e, Num e) => MatrixElement e where
- matrix :: (Int, Int) -> ((Int, Int) -> e) -> Matrix e
- select :: ((Int, Int) -> Bool) -> Matrix e -> [e]
- at :: Matrix e -> (Int, Int) -> e
- row :: Int -> Matrix e -> [e]
- col :: Int -> Matrix e -> [e]
- dimensions :: Matrix e -> (Int, Int)
- numRows :: Matrix e -> Int
- numCols :: Matrix e -> Int
- fromList :: [[e]] -> Matrix e
- toList :: Matrix e -> [[e]]
- unit :: Int -> Matrix e
- zero :: Int -> Matrix e
- diag :: [e] -> Matrix e
- empty :: Matrix e
- minus :: Matrix e -> Matrix e -> Matrix e
- plus :: Matrix e -> Matrix e -> Matrix e
- times :: Matrix e -> Matrix e -> Matrix e
- inv :: Matrix e -> Maybe (Matrix e)
- det :: Matrix e -> e
- transpose :: Matrix e -> Matrix e
- rank :: Matrix e -> e
- trace :: Matrix e -> [e]
- map :: MatrixElement f => (e -> f) -> Matrix e -> Matrix f
- all :: (e -> Bool) -> Matrix e -> Bool
- any :: (e -> Bool) -> Matrix e -> Bool
- mapWithIndex :: MatrixElement f => ((Int, Int) -> e -> f) -> Matrix e -> Matrix f
- allWithIndex :: ((Int, Int) -> e -> Bool) -> Matrix e -> Bool
- anyWithIndex :: ((Int, Int) -> e -> Bool) -> Matrix e -> Bool
- (<|>) :: MatrixElement e => Matrix e -> Matrix e -> Matrix e
- (<->) :: MatrixElement e => Matrix e -> Matrix e -> Matrix e
- scale :: MatrixElement e => Matrix e -> e -> Matrix e
- isUnit :: MatrixElement e => Matrix e -> Bool
- isZero :: MatrixElement e => Matrix e -> Bool
- isDiagonal :: MatrixElement e => Matrix e -> Bool
- isEmpty :: MatrixElement e => Matrix e -> Bool
- isSquare :: MatrixElement e => Matrix e -> Bool
Documentation
class (Eq e, Num e) => MatrixElement e whereSource
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
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
transpose :: Matrix e -> Matrix 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
MatrixElement Double | |
MatrixElement Float | |
MatrixElement Int | |
MatrixElement Integer | |
(Show a, Integral a) => MatrixElement (Ratio a) | |
(Show a, RealFloat a) => MatrixElement (Complex a) |
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)
scale :: MatrixElement e => Matrix e -> e -> Matrix eSource
Matrix properties
Check whether the matrix is an identity matrix.
1 0 0 0 1 0 0 0 1 (True)
isUnit :: MatrixElement e => Matrix e -> BoolSource
Check whether the matrix consists of all zeros.
isZero == all (== 0)
isZero :: MatrixElement e => Matrix e -> BoolSource
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)
isDiagonal :: MatrixElement e => Matrix e -> BoolSource
Checks whether the matrix is empty.
isEmpty m = numCols == 0 || numRows == 0
isEmpty :: MatrixElement e => Matrix e -> BoolSource
Checks whether the matrix is a square matrix.
isSquare == uncurry (==) . dimensions
isSquare :: MatrixElement e => Matrix e -> BoolSource