dense-0.1.0.0: Mutable and immutable dense multidimensional arrays

Copyright(c) Christopher Chalmers
LicenseBSD3
MaintainerChristopher Chalmers
Stabilityprovisional
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Dense.Base

Contents

Description

Base module for multidimensional arrays. This module exports the constructors for the Array data type.

Also, to prevent this module becomming too large, only the data types and the functions nessesary for the instances are defined here. All other functions are defined in Data.Dense.Generic.

Synopsis

Array types

data Array v f a Source #

An Array is a vector with a shape.

Constructors

Array !(Layout f) !(v a) 

Instances

Shape f => HasLayout f (Array v f a) Source #

The size of the layout must remain the same or an error is thrown.

Methods

layout :: Lens' (Array v f a) (Layout f) Source #

(Boxed v, Shape f) => FunctorWithIndex (f Int) (Array v f) Source # 

Methods

imap :: (f Int -> a -> b) -> Array v f a -> Array v f b #

imapped :: (Indexable (f Int) p, Settable f) => p a (f b) -> Array v f a -> f (Array v f b) #

(Boxed v, Shape f) => FoldableWithIndex (f Int) (Array v f) Source # 

Methods

ifoldMap :: Monoid m => (f Int -> a -> m) -> Array v f a -> m #

ifolded :: (Indexable (f Int) p, Contravariant f, Applicative f) => p a (f a) -> Array v f a -> f (Array v f a) #

ifoldr :: (f Int -> a -> b -> b) -> b -> Array v f a -> b #

ifoldl :: (f Int -> b -> a -> b) -> b -> Array v f a -> b #

ifoldr' :: (f Int -> a -> b -> b) -> b -> Array v f a -> b #

ifoldl' :: (f Int -> b -> a -> b) -> b -> Array v f a -> b #

(Boxed v, Shape f) => TraversableWithIndex (f Int) (Array v f) Source # 

Methods

itraverse :: Applicative f => (f Int -> a -> f b) -> Array v f a -> f (Array v f b) #

itraversed :: (Indexable (f Int) p, Applicative f) => p a (f b) -> Array v f a -> f (Array v f b) #

Boxed v => Functor (Array v f) Source # 

Methods

fmap :: (a -> b) -> Array v f a -> Array v f b #

(<$) :: a -> Array v f b -> Array v f a #

Boxed v => Foldable (Array v f) Source # 

Methods

fold :: Monoid m => Array v f m -> m #

foldMap :: Monoid m => (a -> m) -> Array v f a -> m #

foldr :: (a -> b -> b) -> b -> Array v f a -> b #

foldr' :: (a -> b -> b) -> b -> Array v f a -> b #

foldl :: (b -> a -> b) -> b -> Array v f a -> b #

foldl' :: (b -> a -> b) -> b -> Array v f a -> b #

foldr1 :: (a -> a -> a) -> Array v f a -> a #

foldl1 :: (a -> a -> a) -> Array v f a -> a #

toList :: Array v f a -> [a] #

null :: Array v f a -> Bool #

length :: Array v f a -> Int #

elem :: Eq a => a -> Array v f a -> Bool #

maximum :: Ord a => Array v f a -> a #

minimum :: Ord a => Array v f a -> a #

sum :: Num a => Array v f a -> a #

product :: Num a => Array v f a -> a #

Boxed v => Traversable (Array v f) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Array v f a -> f (Array v f b) #

sequenceA :: Applicative f => Array v f (f a) -> f (Array v f a) #

mapM :: Monad m => (a -> m b) -> Array v f a -> m (Array v f b) #

sequence :: Monad m => Array v f (m a) -> m (Array v f a) #

(Boxed v, Eq1 f) => Eq1 (Array v f) Source # 

Methods

liftEq :: (a -> b -> Bool) -> Array v f a -> Array v f b -> Bool #

(Boxed v, Read1 f) => Read1 (Array v f) Source # 

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Array v f a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Array v f a] #

(Boxed v, Shape f, Serial1 f) => Serial1 (Array v f) Source # 

Methods

serializeWith :: MonadPut m => (a -> m ()) -> Array v f a -> m () #

deserializeWith :: MonadGet m => m a -> m (Array v f a) #

(Vector v a, (~) (* -> *) f V1) => Vector (Array v f) a Source #

1D Arrays can be used as a generic Vector.

Methods

basicUnsafeFreeze :: PrimMonad m => Mutable (Array v f) (PrimState m) a -> m (Array v f a) #

basicUnsafeThaw :: PrimMonad m => Array v f a -> m (Mutable (Array v f) (PrimState m) a) #

basicLength :: Array v f a -> Int #

basicUnsafeSlice :: Int -> Int -> Array v f a -> Array v f a #

basicUnsafeIndexM :: Monad m => Array v f a -> Int -> m a #

basicUnsafeCopy :: PrimMonad m => Mutable (Array v f) (PrimState m) a -> Array v f a -> m () #

elemseq :: Array v f a -> a -> b -> b #

(Vector v a, Eq1 f, Eq a) => Eq (Array v f a) Source # 

Methods

(==) :: Array v f a -> Array v f a -> Bool #

(/=) :: Array v f a -> Array v f a -> Bool #

(Typeable (* -> *) f, Typeable (* -> *) v, Typeable * a, Data (f Int), Data (v a)) => Data (Array v f a) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Array v f a -> c (Array v f a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Array v f a) #

toConstr :: Array v f a -> Constr #

dataTypeOf :: Array v f a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Array v f a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Array v f a)) #

gmapT :: (forall b. Data b => b -> b) -> Array v f a -> Array v f a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Array v f a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Array v f a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Array v f a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Array v f a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Array v f a -> m (Array v f a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Array v f a -> m (Array v f a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Array v f a -> m (Array v f a) #

(Vector v a, Read1 f, Read a) => Read (Array v f a) Source # 

Methods

readsPrec :: Int -> ReadS (Array v f a) #

readList :: ReadS [Array v f a] #

readPrec :: ReadPrec (Array v f a) #

readListPrec :: ReadPrec [Array v f a] #

(Vector v a, Show1 f, Show a) => Show (Array v f a) Source # 

Methods

showsPrec :: Int -> Array v f a -> ShowS #

show :: Array v f a -> String #

showList :: [Array v f a] -> ShowS #

(Vector v a, Shape f, Binary (f Int), Binary a) => Binary (Array v f a) Source # 

Methods

put :: Array v f a -> Put #

get :: Get (Array v f a) #

putList :: [Array v f a] -> Put #

(Vector v a, Shape f, Serial1 f, Serial a) => Serial (Array v f a) Source # 

Methods

serialize :: MonadPut m => Array v f a -> m () #

deserialize :: MonadGet m => m (Array v f a) #

(Vector v a, Shape f, Serialize (f Int), Serialize a) => Serialize (Array v f a) Source # 

Methods

put :: Putter (Array v f a) #

get :: Get (Array v f a) #

(NFData (f Int), NFData (v a)) => NFData (Array v f a) Source # 

Methods

rnf :: Array v f a -> () #

(Vector v a, Foldable f, Hashable a) => Hashable (Array v f a) Source # 

Methods

hashWithSalt :: Int -> Array v f a -> Int #

hash :: Array v f a -> Int #

(Shape f, Vector v a) => Ixed (Array v f a) Source # 

Methods

ix :: Index (Array v f a) -> Traversal' (Array v f a) (IxValue (Array v f a)) #

(Shape f, Vector v a) => AsEmpty (Array v f a) Source # 

Methods

_Empty :: Prism' (Array v f a) () #

(Vector v a, Vector v b) => Each (Array v f a) (Array v f b) a b Source # 

Methods

each :: Traversal (Array v f a) (Array v f b) a b #

type Mutable (Array v f) Source # 
type Mutable (Array v f) = MArray (Mutable v) f
type Index (Array v f a) Source # 
type Index (Array v f a) = f Int
type IxValue (Array v f a) Source # 
type IxValue (Array v f a) = a

type Boxed v = v ~ Vector Source #

The vector is the boxed vector.

Lenses

vector :: (Vector v a, Vector w b) => IndexedLens (Layout f) (Array v f a) (Array w f b) (v a) (w b) Source #

Indexed lens over the underlying vector of an array. The index is the extent of the array. You must _not_ change the length of the vector, otherwise an error will be thrown (even for V1 layouts, use flat for V1).

values :: (Shape f, Vector v a, Vector w b) => IndexedTraversal (f Int) (Array v f a) (Array w f b) a b Source #

Indexed traversal over the elements of an array. The index is the current position in the array.

Conversion to/from mutable arrays

unsafeThaw :: (PrimMonad m, Vector v a) => Array v f a -> m (MArray (Mutable v) f (PrimState m) a) Source #

O(1) Unsafely convert an immutable array to a mutable one without copying. The immutable array may not be used after this operation.

unsafeFreeze :: (PrimMonad m, Vector v a) => MArray (Mutable v) f (PrimState m) a -> m (Array v f a) Source #

O(1) Unsafe convert a mutable array to an immutable one without copying. The mutable array may not be used after this operation.

Delayed

data Delayed f a Source #

A delayed representation of an array. This useful for mapping over an array in parallel.

Constructors

Delayed !(Layout f) (f Int -> a) 

Instances

Shape f => HasLayout f (Delayed f a) Source #

The size of the layout must remain the same or an error is thrown.

Methods

layout :: Lens' (Delayed f a) (Layout f) Source #

Functor (Delayed f) Source # 

Methods

fmap :: (a -> b) -> Delayed f a -> Delayed f b #

(<$) :: a -> Delayed f b -> Delayed f a #

Shape f => Foldable (Delayed f) Source #

foldMap in parallel.

Methods

fold :: Monoid m => Delayed f m -> m #

foldMap :: Monoid m => (a -> m) -> Delayed f a -> m #

foldr :: (a -> b -> b) -> b -> Delayed f a -> b #

foldr' :: (a -> b -> b) -> b -> Delayed f a -> b #

foldl :: (b -> a -> b) -> b -> Delayed f a -> b #

foldl' :: (b -> a -> b) -> b -> Delayed f a -> b #

foldr1 :: (a -> a -> a) -> Delayed f a -> a #

foldl1 :: (a -> a -> a) -> Delayed f a -> a #

toList :: Delayed f a -> [a] #

null :: Delayed f a -> Bool #

length :: Delayed f a -> Int #

elem :: Eq a => a -> Delayed f a -> Bool #

maximum :: Ord a => Delayed f a -> a #

minimum :: Ord a => Delayed f a -> a #

sum :: Num a => Delayed f a -> a #

product :: Num a => Delayed f a -> a #

Shape f => Traversable (Delayed f) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Delayed f a -> f (Delayed f b) #

sequenceA :: Applicative f => Delayed f (f a) -> f (Delayed f a) #

mapM :: Monad m => (a -> m b) -> Delayed f a -> m (Delayed f b) #

sequence :: Monad m => Delayed f (m a) -> m (Delayed f a) #

Shape f => Metric (Delayed f) Source # 

Methods

dot :: Num a => Delayed f a -> Delayed f a -> a #

quadrance :: Num a => Delayed f a -> a #

qd :: Num a => Delayed f a -> Delayed f a -> a #

distance :: Floating a => Delayed f a -> Delayed f a -> a #

norm :: Floating a => Delayed f a -> a #

signorm :: Floating a => Delayed f a -> Delayed f a #

Shape f => Additive (Delayed f) Source # 

Methods

zero :: Num a => Delayed f a #

(^+^) :: Num a => Delayed f a -> Delayed f a -> Delayed f a #

(^-^) :: Num a => Delayed f a -> Delayed f a -> Delayed f a #

lerp :: Num a => a -> Delayed f a -> Delayed f a -> Delayed f a #

liftU2 :: (a -> a -> a) -> Delayed f a -> Delayed f a -> Delayed f a #

liftI2 :: (a -> b -> c) -> Delayed f a -> Delayed f b -> Delayed f c #

Shape f => Apply (Delayed f) Source # 

Methods

(<.>) :: Delayed f (a -> b) -> Delayed f a -> Delayed f b #

(.>) :: Delayed f a -> Delayed f b -> Delayed f b #

(<.) :: Delayed f a -> Delayed f b -> Delayed f a #

FunctorWithIndex (f Int) (Delayed f) Source # 

Methods

imap :: (f Int -> a -> b) -> Delayed f a -> Delayed f b #

imapped :: (Indexable (f Int) p, Settable f) => p a (f b) -> Delayed f a -> f (Delayed f b) #

Shape f => FoldableWithIndex (f Int) (Delayed f) Source #

ifoldMap in parallel.

Methods

ifoldMap :: Monoid m => (f Int -> a -> m) -> Delayed f a -> m #

ifolded :: (Indexable (f Int) p, Contravariant f, Applicative f) => p a (f a) -> Delayed f a -> f (Delayed f a) #

ifoldr :: (f Int -> a -> b -> b) -> b -> Delayed f a -> b #

ifoldl :: (f Int -> b -> a -> b) -> b -> Delayed f a -> b #

ifoldr' :: (f Int -> a -> b -> b) -> b -> Delayed f a -> b #

ifoldl' :: (f Int -> b -> a -> b) -> b -> Delayed f a -> b #

Shape f => TraversableWithIndex (f Int) (Delayed f) Source # 

Methods

itraverse :: Applicative f => (f Int -> a -> f b) -> Delayed f a -> f (Delayed f b) #

itraversed :: (Indexable (f Int) p, Applicative f) => p a (f b) -> Delayed f a -> f (Delayed f b) #

(Shape f, Show1 f, Show a) => Show (Delayed f a) Source # 

Methods

showsPrec :: Int -> Delayed f a -> ShowS #

show :: Delayed f a -> String #

showList :: [Delayed f a] -> ShowS #

Shape f => Ixed (Delayed f a) Source # 

Methods

ix :: Index (Delayed f a) -> Traversal' (Delayed f a) (IxValue (Delayed f a)) #

Shape f => AsEmpty (Delayed f a) Source # 

Methods

_Empty :: Prism' (Delayed f a) () #

Shape f => Each (Delayed f a) (Delayed f b) a b Source # 

Methods

each :: Traversal (Delayed f a) (Delayed f b) a b #

type Index (Delayed f a) Source # 
type Index (Delayed f a) = f Int
type IxValue (Delayed f a) Source # 
type IxValue (Delayed f a) = a

delay :: (Vector v a, Shape f) => Array v f a -> Delayed f a Source #

Turn a material array into a delayed one with the same shape.

manifest :: (Vector v a, Shape f) => Delayed f a -> Array v f a Source #

Parallel manifestation of a delayed array into a material one.

genDelayed :: Layout f -> (f Int -> a) -> Delayed f a Source #

Generate a Delayed array using the given Layout and construction function.

indexDelayed :: Shape f => Delayed f a -> f Int -> a Source #

Index a delayed array, returning a IndexOutOfBounds exception if the index is out of range.

Focused

data Focused f a Source #

A delayed representation of an array with a focus on a single element. This element is the target of extract.

Constructors

Focused !(f Int) !(Delayed f a) 

Instances

Shape f => HasLayout f (Focused f a) Source #

The size of the layout must remain the same or an error is thrown.

Methods

layout :: Lens' (Focused f a) (Layout f) Source #

Functor (Focused f) Source # 

Methods

fmap :: (a -> b) -> Focused f a -> Focused f b #

(<$) :: a -> Focused f b -> Focused f a #

Shape f => Foldable (Focused f) Source # 

Methods

fold :: Monoid m => Focused f m -> m #

foldMap :: Monoid m => (a -> m) -> Focused f a -> m #

foldr :: (a -> b -> b) -> b -> Focused f a -> b #

foldr' :: (a -> b -> b) -> b -> Focused f a -> b #

foldl :: (b -> a -> b) -> b -> Focused f a -> b #

foldl' :: (b -> a -> b) -> b -> Focused f a -> b #

foldr1 :: (a -> a -> a) -> Focused f a -> a #

foldl1 :: (a -> a -> a) -> Focused f a -> a #

toList :: Focused f a -> [a] #

null :: Focused f a -> Bool #

length :: Focused f a -> Int #

elem :: Eq a => a -> Focused f a -> Bool #

maximum :: Ord a => Focused f a -> a #

minimum :: Ord a => Focused f a -> a #

sum :: Num a => Focused f a -> a #

product :: Num a => Focused f a -> a #

Shape f => Traversable (Focused f) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Focused f a -> f (Focused f b) #

sequenceA :: Applicative f => Focused f (f a) -> f (Focused f a) #

mapM :: Monad m => (a -> m b) -> Focused f a -> m (Focused f b) #

sequence :: Monad m => Focused f (m a) -> m (Focused f a) #

Shape f => Comonad (Focused f) Source # 

Methods

extract :: Focused f a -> a #

duplicate :: Focused f a -> Focused f (Focused f a) #

extend :: (Focused f a -> b) -> Focused f a -> Focused f b #

Shape f => Extend (Focused f) Source # 

Methods

duplicated :: Focused f a -> Focused f (Focused f a) #

extended :: (Focused f a -> b) -> Focused f a -> Focused f b #

Shape f => ComonadStore (f Int) (Focused f) Source # 

Methods

pos :: Focused f a -> f Int #

peek :: f Int -> Focused f a -> a #

peeks :: (f Int -> f Int) -> Focused f a -> a #

seek :: f Int -> Focused f a -> Focused f a #

seeks :: (f Int -> f Int) -> Focused f a -> Focused f a #

experiment :: Functor f => (f Int -> f (f Int)) -> Focused f a -> f a #

Shape f => FunctorWithIndex (f Int) (Focused f) Source #

Index relative to focus.

Methods

imap :: (f Int -> a -> b) -> Focused f a -> Focused f b #

imapped :: (Indexable (f Int) p, Settable f) => p a (f b) -> Focused f a -> f (Focused f b) #

Shape f => FoldableWithIndex (f Int) (Focused f) Source #

Index relative to focus.

Methods

ifoldMap :: Monoid m => (f Int -> a -> m) -> Focused f a -> m #

ifolded :: (Indexable (f Int) p, Contravariant f, Applicative f) => p a (f a) -> Focused f a -> f (Focused f a) #

ifoldr :: (f Int -> a -> b -> b) -> b -> Focused f a -> b #

ifoldl :: (f Int -> b -> a -> b) -> b -> Focused f a -> b #

ifoldr' :: (f Int -> a -> b -> b) -> b -> Focused f a -> b #

ifoldl' :: (f Int -> b -> a -> b) -> b -> Focused f a -> b #

Shape f => TraversableWithIndex (f Int) (Focused f) Source #

Index relative to focus.

Methods

itraverse :: Applicative f => (f Int -> a -> f b) -> Focused f a -> f (Focused f b) #

itraversed :: (Indexable (f Int) p, Applicative f) => p a (f b) -> Focused f a -> f (Focused f b) #

(Shape f, Show1 f, Show a) => Show (Focused f a) Source # 

Methods

showsPrec :: Int -> Focused f a -> ShowS #

show :: Focused f a -> String #

showList :: [Focused f a] -> ShowS #

Shape f => Ixed (Focused f a) Source #

Index relative to focus.

Methods

ix :: Index (Focused f a) -> Traversal' (Focused f a) (IxValue (Focused f a)) #

type Index (Focused f a) Source # 
type Index (Focused f a) = f Int
type IxValue (Focused f a) Source # 
type IxValue (Focused f a) = a