matrices-0.4.5: native matrix based on vector

Data.Matrix.Dense.Generic

Synopsis

Immutable Matrix

data Matrix v a Source #

Row-major matrix supporting efficient slice

Constructors

 Matrix !Int !Int !Int !Int !(v a)

Instances

Accessors

length information

dim :: Matrix m v a => m v a -> (Int, Int) Source #

rows :: Matrix m v a => m v a -> Int Source #

Derived methods

Return the number of rows

cols :: Matrix m v a => m v a -> Int Source #

Return the number of columns

Indexing

unsafeIndex :: Matrix m v a => m v a -> (Int, Int) -> a Source #

(!) :: Matrix m v a => m v a -> (Int, Int) -> a Source #

Indexing

takeRow :: Matrix m v a => m v a -> Int -> v a Source #

Extract a row.

takeColumn :: Matrix m v a => m v a -> Int -> v a Source #

Extract a row.

takeDiag :: Matrix m v a => m v a -> v a Source #

Extract the diagonal. Default algorithm is O(min(m,n) * O(unsafeIndex)).

Construction

unsafeFromVector :: Matrix m v a => (Int, Int) -> v a -> m v a Source #

fromVector :: Matrix m v a => (Int, Int) -> v a -> m v a Source #

Arguments

 :: Matrix m v a => Int number of columns -> [a] row list -> m v a

O(m*n) Matrix construction

fromLists :: Matrix m v a => [[a]] -> m v a Source #

O(m*n) Create matrix from list of lists, it doesn't check if the list of list is a valid matrix

fromRows :: Matrix m v a => [v a] -> m v a Source #

O(m*n) Create matrix from rows

fromColumns :: Vector v a => [v a] -> Matrix v a Source #

O(m*n) Create matrix from columns

empty :: Matrix m v a => m v a Source #

Conversions

flatten :: Matrix m v a => m v a -> v a Source #

Default algorithm is O((m*n) * O(unsafeIndex)).

toRows :: Matrix m v a => m v a -> [v a] Source #

O(m) Return the rows

toColumns :: Matrix m v a => m v a -> [v a] Source #

O(m*n) Return the columns

toList :: Matrix m v a => m v a -> [a] Source #

O(m*n) Create a list by concatenating rows

toLists :: Matrix m v a => m v a -> [[a]] Source #

O(m*n) List of lists

Different matrix types

convert :: (Vector v a, Vector w a) => Matrix v a -> Matrix w a Source #

O(m*n) Convert different matrix type

tr :: Vector v a => Matrix v a -> Matrix v a Source #

O(m*n) Matrix transpose

Arguments

 :: Vector v a => (Int, Int) upper left corner of the submatrix -> (Int, Int) bottom right corner of the submatrix -> Matrix v a -> Matrix v a

O(1) Extract sub matrix

ident :: (Num a, Vector v a) => Int -> Matrix v a Source #

O(m*n) Create an identity matrix

Arguments

 :: (Num a, Vector v a, Foldable t) => t a diagonal -> Matrix v a

O(m*n) Create a square matrix with given diagonal, other entries default to 0

Arguments

 :: (Vector v a, Foldable t) => a default value -> (Int, Int) -> t a diagonal -> Matrix v a

O(m*n) Create a rectangular matrix with default values and given diagonal

Arguments

 :: Vector v a => a default value -> [[Matrix v a]] -> Matrix v a

isSymmetric :: (Eq a, Vector v a) => Matrix v a -> Bool Source #

force :: Vector v a => Matrix v a -> Matrix v a Source #

foldl :: Vector v b => (a -> b -> a) -> a -> Matrix v b -> a Source #

Mapping

map :: (Vector v a, Vector v b) => (a -> b) -> Matrix v a -> Matrix v b Source #

imap :: (Vector v a, Vector v b) => ((Int, Int) -> a -> b) -> Matrix v a -> Matrix v b Source #

mapM :: (Vector v a, Vector v b, Monad m) => (a -> m b) -> Matrix v a -> m (Matrix v b) Source #

imapM :: (Vector v a, Vector v b, Monad m) => ((Int, Int) -> a -> m b) -> Matrix v a -> m (Matrix v b) Source #

O(m*n) Apply the monadic action to every element and its index, yielding a matrix of results.

mapM_ :: (Vector v a, Monad m) => (a -> m b) -> Matrix v a -> m () Source #

imapM_ :: (Vector v a, Monad m) => ((Int, Int) -> a -> m b) -> Matrix v a -> m () Source #

O(m*n) Apply the monadic action to every element and its index, ignoring the results.

forM :: (Vector v a, Vector v b, Monad m) => Matrix v a -> (a -> m b) -> m (Matrix v b) Source #

forM_ :: (Vector v a, Monad m) => Matrix v a -> (a -> m b) -> m () Source #

Zipping

zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> Matrix v a -> Matrix v b -> Matrix v c Source #

zipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (a -> b -> c -> d) -> Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d Source #

zipWith4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e) => (a -> b -> c -> d -> e) -> Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d -> Matrix v e Source #

zipWith5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f) => (a -> b -> c -> d -> e -> f) -> Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d -> Matrix v e -> Matrix v f Source #

zipWith6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v g) => (a -> b -> c -> d -> e -> f -> g) -> Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d -> Matrix v e -> Matrix v f -> Matrix v g Source #

izipWith :: (Vector v a, Vector v b, Vector v c) => ((Int, Int) -> a -> b -> c) -> Matrix v a -> Matrix v b -> Matrix v c Source #

izipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => ((Int, Int) -> a -> b -> c -> d) -> Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d Source #

izipWith4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e) => ((Int, Int) -> a -> b -> c -> d -> e) -> Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d -> Matrix v e Source #

izipWith5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f) => ((Int, Int) -> a -> b -> c -> d -> e -> f) -> Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d -> Matrix v e -> Matrix v f Source #

izipWith6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v g) => ((Int, Int) -> a -> b -> c -> d -> e -> f -> g) -> Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d -> Matrix v e -> Matrix v f -> Matrix v g Source #

zip :: (Vector v a, Vector v b, Vector v (a, b)) => Matrix v a -> Matrix v b -> Matrix v (a, b) Source #

zip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => Matrix v a -> Matrix v b -> Matrix v c -> Matrix v (a, b, c) Source #

zip4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v (a, b, c, d)) => Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d -> Matrix v (a, b, c, d) Source #

zip5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v (a, b, c, d, e)) => Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d -> Matrix v e -> Matrix v (a, b, c, d, e) Source #

zip6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v (a, b, c, d, e, f)) => Matrix v a -> Matrix v b -> Matrix v c -> Matrix v d -> Matrix v e -> Matrix v f -> Matrix v (a, b, c, d, e, f) Source #

zipWithM :: (Monad m, Vector v a, Vector v b, Vector v c) => (a -> b -> m c) -> Matrix v a -> Matrix v b -> m (Matrix v c) Source #

zipWithM_ :: (Monad m, Vector v a, Vector v b) => (a -> b -> m c) -> Matrix v a -> Matrix v b -> m () Source #

Unzipping

unzip :: (Vector v a, Vector v b, Vector v (a, b)) => Matrix v (a, b) -> (Matrix v a, Matrix v b) Source #

unzip3 :: (Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => Matrix v (a, b, c) -> (Matrix v a, Matrix v b, Matrix v c) Source #

unzip4 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v (a, b, c, d)) => Matrix v (a, b, c, d) -> (Matrix v a, Matrix v b, Matrix v c, Matrix v d) Source #

unzip5 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v (a, b, c, d, e)) => Matrix v (a, b, c, d, e) -> (Matrix v a, Matrix v b, Matrix v c, Matrix v d, Matrix v e) Source #

unzip6 :: (Vector v a, Vector v b, Vector v c, Vector v d, Vector v e, Vector v f, Vector v (a, b, c, d, e, f)) => Matrix v (a, b, c, d, e, f) -> (Matrix v a, Matrix v b, Matrix v c, Matrix v d, Matrix v e, Matrix v f) Source #

sequence :: (Vector v a, Vector v (m a), Monad m) => Matrix v (m a) -> m (Matrix v a) Source #

sequence_ :: (Vector v (m a), Monad m) => Matrix v (m a) -> m () Source #

generate :: Vector v a => (Int, Int) -> ((Int, Int) -> a) -> Matrix v a Source #

Mutable matrix

thaw :: (Matrix m v a, PrimMonad s) => m v a -> s (Mutable m (Mutable v) (PrimState s) a) Source #

unsafeThaw :: (Matrix m v a, PrimMonad s) => m v a -> s (Mutable m (Mutable v) (PrimState s) a) Source #

freeze :: (Matrix m v a, PrimMonad s) => Mutable m (Mutable v) (PrimState s) a -> s (m v a) Source #

unsafeFreeze :: (Matrix m v a, PrimMonad s) => Mutable m (Mutable v) (PrimState s) a -> s (m v a) Source #

create :: Matrix m v a => (forall s. ST s (Mutable m (Mutable v) s a)) -> m v a Source #