matrices-0.5.0: native matrix based on vector

Safe HaskellNone
LanguageHaskell2010

Data.Matrix.Generic

Contents

Synopsis

Immutable Matrix

data Matrix v a Source #

Row-major matrix supporting efficient slice.

Constructors

Matrix !Int !Int !Int !Int !(v a) 
Instances
Vector v a => Matrix Matrix v a Source # 
Instance details

Defined in Data.Matrix.Generic

Methods

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

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

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

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

unsafeTakeRow :: Matrix v a -> Int -> v a Source #

unsafeTakeColumn :: Matrix v a -> Int -> v a Source #

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

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

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

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

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

(Vector v a, Eq (v a)) => Eq (Matrix v a) Source # 
Instance details

Defined in Data.Matrix.Generic

Methods

(==) :: Matrix v a -> Matrix v a -> Bool #

(/=) :: Matrix v a -> Matrix v a -> Bool #

Read (v a) => Read (Matrix v a) Source # 
Instance details

Defined in Data.Matrix.Generic

Show (v a) => Show (Matrix v a) Source # 
Instance details

Defined in Data.Matrix.Generic

Methods

showsPrec :: Int -> Matrix v a -> ShowS #

show :: Matrix v a -> String #

showList :: [Matrix v a] -> ShowS #

Generic (Matrix v a) Source # 
Instance details

Defined in Data.Matrix.Generic

Associated Types

type Rep (Matrix v a) :: Type -> Type #

Methods

from :: Matrix v a -> Rep (Matrix v a) x #

to :: Rep (Matrix v a) x -> Matrix v a #

NFData (v a) => NFData (Matrix v a) Source # 
Instance details

Defined in Data.Matrix.Generic

Methods

rnf :: Matrix v a -> () #

type Mutable Matrix Source # 
Instance details

Defined in Data.Matrix.Generic

type Rep (Matrix v a) Source # 
Instance details

Defined in Data.Matrix.Generic

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 #

matrix Source #

Arguments

:: Matrix m v a 
=> Int

number of columns

-> [a]

row list

-> m v a 

O(m*n) Matrix construction

fromList :: Matrix m v a => (Int, Int) -> [a] -> m v a Source #

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

subMatrix Source #

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

diag Source #

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

diagRect Source #

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

fromBlocks Source #

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 #

Monadic mapping

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 #

Monadic Zipping

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 #

Monadic sequencing

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 #