Safe Haskell | None |
---|---|

Language | Haskell98 |

Sized matrixes.

Copyright: (c) 2013 University of Kansas License: BSD3

Maintainer: Andy Gill andygill@ku.edu Stability: unstable Portability: ghc

- newtype Matrix ix a = Matrix (Array ix a)
- type Vector ix a = Matrix (Fin ix) a
- type Vector2 ix iy a = Matrix (Fin ix, Fin iy) a
- matrix :: forall i a. (Bounded i, Ix i) => [a] -> Matrix i a
- population :: forall i a. (Bounded i, Ix i) => Matrix i a -> Int
- allIndices :: (Bounded i, Ix i) => Matrix i a -> [i]
- zeroOf :: (Bounded i, Ix i) => Matrix i a -> i
- coord :: (Bounded i, Ix i) => Matrix i i
- zipWith :: (Bounded i, Ix i) => (a -> b -> c) -> Matrix i a -> Matrix i b -> Matrix i c
- forEach :: (Bounded i, Ix i) => Matrix i a -> (i -> a -> b) -> Matrix i b
- forAll :: (Bounded i, Ix i) => (i -> a) -> Matrix i a
- mm :: (Bounded m, Ix m, Bounded n, Ix n, Bounded o, Ix o, Num a) => Matrix (m, n) a -> Matrix (n, o) a -> Matrix (m, o) a
- transpose :: (Bounded x, Ix x, Bounded y, Ix y) => Matrix (x, y) a -> Matrix (y, x) a
- identity :: (Bounded x, Ix x, Num a) => Matrix (x, x) a
- append :: (SingI left, SingI right, SingI (left + right)) => Vector left a -> Vector right a -> Vector (left + right) a
- above :: (SingI top, SingI bottom, SingI y, SingI (top + bottom)) => Vector2 top y a -> Vector2 bottom y a -> Vector2 (top + bottom) y a
- beside :: (SingI left, SingI right, SingI x, SingI (left + right)) => Vector2 x left a -> Vector2 x right a -> Vector2 x (left + right) a
- ixfmap :: (Bounded i, Ix i, Bounded j, Ix j, Functor f) => (i -> f j) -> Matrix j a -> Matrix i (f a)
- rows :: (Bounded n, Ix n, Bounded m, Ix m) => Matrix (m, n) a -> Matrix m (Matrix n a)
- columns :: (Bounded n, Ix n, Bounded m, Ix m) => Matrix (m, n) a -> Matrix n (Matrix m a)
- joinRows :: (Bounded n, Ix n, Bounded m, Ix m) => Matrix m (Matrix n a) -> Matrix (m, n) a
- joinColumns :: (Bounded n, Ix n, Bounded m, Ix m) => Matrix n (Matrix m a) -> Matrix (m, n) a
- show2D :: (Bounded n, Ix n, Bounded m, Ix m, Show a) => Matrix (m, n) a -> String
- newtype S = S String
- showAsE :: RealFloat a => Int -> a -> S
- showAsF :: RealFloat a => Int -> a -> S

# Documentation

A `Matrix`

is an array with the size determined uniquely by the
*type* of the index type, `ix`

, with every type in `ix`

used.

IArray Matrix a | |

Ix ix => Functor (Matrix ix) | |

(Bounded i, Ix i) => Applicative (Matrix i) | |

(Bounded ix, Ix ix) => Foldable (Matrix ix) | |

(Bounded ix, Ix ix) => Traversable (Matrix ix) | |

(Eq a, Ix ix) => Eq (Matrix ix a) | |

(Ord a, Ix ix) => Ord (Matrix ix a) | |

(Show a, Show ix, Bounded ix, Ix ix) => Show (Matrix ix a) | |

Typeable (* -> * -> *) Matrix |

type Vector ix a = Matrix (Fin ix) a Source

A `Vector`

is a 1D Matrix, using a TypeNat to define its length.

type Vector2 ix iy a = Matrix (Fin ix, Fin iy) a Source

A `Vector2`

is a 2D Matrix, using a TypeNat's to define its size.

matrix :: forall i a. (Bounded i, Ix i) => [a] -> Matrix i a Source

`matrix`

turns a finite list into a matrix. You often need to give the type of the result.

population :: forall i a. (Bounded i, Ix i) => Matrix i a -> Int Source

what is the population of a matrix?

allIndices :: (Bounded i, Ix i) => Matrix i a -> [i] Source

zeroOf :: (Bounded i, Ix i) => Matrix i a -> i Source

`zeroOf`

is for use to force typing issues, and is 0.

zipWith :: (Bounded i, Ix i) => (a -> b -> c) -> Matrix i a -> Matrix i b -> Matrix i c Source

Same as for lists.

forEach :: (Bounded i, Ix i) => Matrix i a -> (i -> a -> b) -> Matrix i b Source

`forEach`

takes a matrix, and calls a function for each element, to give a new matrix of the same size.

forAll :: (Bounded i, Ix i) => (i -> a) -> Matrix i a Source

`forAll`

creates a matrix out of a mapping from the coordinates.

mm :: (Bounded m, Ix m, Bounded n, Ix n, Bounded o, Ix o, Num a) => Matrix (m, n) a -> Matrix (n, o) a -> Matrix (m, o) a Source

`mm`

is the 2D matrix multiply.

transpose :: (Bounded x, Ix x, Bounded y, Ix y) => Matrix (x, y) a -> Matrix (y, x) a Source

`transpose`

a 2D matrix.

identity :: (Bounded x, Ix x, Num a) => Matrix (x, x) a Source

return the identity for a specific matrix size.

append :: (SingI left, SingI right, SingI (left + right)) => Vector left a -> Vector right a -> Vector (left + right) a Source

append to 1D vectors

above :: (SingI top, SingI bottom, SingI y, SingI (top + bottom)) => Vector2 top y a -> Vector2 bottom y a -> Vector2 (top + bottom) y a Source

stack two matrixes `above`

each other.

beside :: (SingI left, SingI right, SingI x, SingI (left + right)) => Vector2 x left a -> Vector2 x right a -> Vector2 x (left + right) a Source

stack two matrixes `beside`

each other.

ixfmap :: (Bounded i, Ix i, Bounded j, Ix j, Functor f) => (i -> f j) -> Matrix j a -> Matrix i (f a) Source

look at a matrix through a functor lens, to another matrix.

rows :: (Bounded n, Ix n, Bounded m, Ix m) => Matrix (m, n) a -> Matrix m (Matrix n a) Source

grab *part* of a matrix.
cropAt :: (Index i ~ Index ix, Bounded i, Ix i, Bounded ix, Ix ix) => Matrix ix a -> ix -> Matrix i a
cropAt m corner = ixmap ( i -> (addIndex corner (toIndex i))) m

slice a 2D matrix into rows.

columns :: (Bounded n, Ix n, Bounded m, Ix m) => Matrix (m, n) a -> Matrix n (Matrix m a) Source

slice a 2D matrix into columns.

joinRows :: (Bounded n, Ix n, Bounded m, Ix m) => Matrix m (Matrix n a) -> Matrix (m, n) a Source

join a matrix of matrixes into a single matrix.

joinColumns :: (Bounded n, Ix n, Bounded m, Ix m) => Matrix n (Matrix m a) -> Matrix (m, n) a Source

join a matrix of matrixes into a single matrix.

`S`

is shown as the contents, without the quotes.
One use is a matrix of S, so that you can do show-style functions
using fmap.