Copyright  (c) Christopher Chalmers 

License  BSD3 
Maintainer  Christopher Chalmers 
Stability  provisional 
Portability  nonportable 
Safe Haskell  None 
Language  Haskell2010 
This module provides generic functions over multidimensional arrays.
Synopsis
 data Array v f a
 class (Eq1 f, Additive f, Traversable f) => Shape f where
 shapeToIndex :: Layout f > f Int > Int
 shapeFromIndex :: Layout f > Int > f Int
 shapeIntersect :: Layout f > Layout f > Layout f
 unsafeShapeStep :: Layout f > f Int > f Int
 shapeStep :: Layout f > f Int > Maybe (f Int)
 shapeStepBetween :: f Int > Layout f > f Int > Maybe (f Int)
 shapeInRange :: Layout f > f Int > Bool
 shapeSize :: Layout f > Int
 type BArray = Array Vector
 type UArray = Array Vector
 type SArray = Array Vector
 type PArray = Array Vector
 class Shape f => HasLayout f a  a > f where
 type Layout f = f Int
 extent :: HasLayout f a => a > f Int
 size :: HasLayout f a => a > Int
 indexes :: HasLayout f a => IndexedFold Int a (f Int)
 indexesFrom :: HasLayout f a => f Int > IndexedFold Int a (f Int)
 indexesBetween :: HasLayout f a => f Int > f Int > IndexedFold Int a (f Int)
 vector :: (Vector v a, Vector w b) => IndexedLens (Layout f) (Array v f a) (Array w f b) (v a) (w b)
 values :: (Shape f, Vector v a, Vector w b) => IndexedTraversal (f Int) (Array v f a) (Array w f b) a b
 values' :: (Shape f, Vector v a, Vector v b) => IndexedTraversal (f Int) (Array v f a) (Array v f b) a b
 valuesBetween :: (Shape f, Vector v a) => f Int > f Int > IndexedTraversal' (f Int) (Array v f a) a
 flat :: Vector w b => Iso (Array v V1 a) (Array w V1 b) (v a) (w b)
 fromList :: Vector v a => [a] > Array v V1 a
 fromListInto :: (Shape f, Vector v a) => Layout f > [a] > Maybe (Array v f a)
 fromListInto_ :: (Shape f, Vector v a) => Layout f > [a] > Array v f a
 fromVectorInto :: (Shape f, Vector v a) => Layout f > v a > Maybe (Array v f a)
 fromVectorInto_ :: (Shape f, Vector v a) => Layout f > v a > Array v f a
 replicate :: (Shape f, Vector v a) => f Int > a > Array v f a
 generate :: (Shape f, Vector v a) => Layout f > (f Int > a) > Array v f a
 linearGenerate :: (Shape f, Vector v a) => Layout f > (Int > a) > Array v f a
 create :: Vector v a => (forall s. ST s (MArray (Mutable v) f s a)) > Array v f a
 createT :: (Vector v a, Traversable t) => (forall s. ST s (t (MArray (Mutable v) f s a))) > t (Array v f a)
 replicateM :: (Monad m, Shape f, Vector v a) => Layout f > m a > m (Array v f a)
 generateM :: (Monad m, Shape f, Vector v a) => Layout f > (f Int > m a) > m (Array v f a)
 linearGenerateM :: (Monad m, Shape f, Vector v a) => Layout f > (Int > m a) > m (Array v f a)
 empty :: (Vector v a, Additive f) => Array v f a
 null :: Foldable f => Array v f a > Bool
 (!) :: (Shape f, Vector v a) => Array v f a > f Int > a
 (!?) :: (Shape f, Vector v a) => Array v f a > f Int > Maybe a
 unsafeIndex :: (Shape f, Vector v a) => Array v f a > f Int > a
 linearIndex :: Vector v a => Array v f a > Int > a
 unsafeLinearIndex :: Vector v a => Array v f a > Int > a
 indexM :: (Shape f, Vector v a, Monad m) => Array v f a > f Int > m a
 unsafeIndexM :: (Shape f, Vector v a, Monad m) => Array v f a > f Int > m a
 linearIndexM :: (Shape f, Vector v a, Monad m) => Array v f a > Int > m a
 unsafeLinearIndexM :: (Vector v a, Monad m) => Array v f a > Int > m a
 (//) :: (Vector v a, Shape f) => Array v f a > [(f Int, a)] > Array v f a
 accum :: (Shape f, Vector v a) => (a > b > a) > Array v f a > [(f Int, b)] > Array v f a
 map :: (Vector v a, Vector v b) => (a > b) > Array v f a > Array v f b
 imap :: (Shape f, Vector v a, Vector v b) => (f Int > a > b) > Array v f a > Array v f b
 zip :: (Shape f, Vector v a, Vector v b, Vector v (a, b)) => Array v f a > Array v f b > Array v f (a, b)
 zip3 :: (Shape f, Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => Array v f a > Array v f b > Array v f c > Array v f (a, b, c)
 zipWith :: (Shape f, Vector v a, Vector v b, Vector v c) => (a > b > c) > Array v f a > Array v f b > Array v f c
 zipWith3 :: (Shape f, Vector v a, Vector v b, Vector v c, Vector v d) => (a > b > c > d) > Array v f a > Array v f b > Array v f c > Array v f d
 izipWith :: (Shape f, Vector v a, Vector v b, Vector v c) => (f Int > a > b > c) > Array v f a > Array v f b > Array v f c
 izipWith3 :: (Shape f, Vector v a, Vector v b, Vector v c, Vector v d) => (f Int > a > b > c > d) > Array v f a > Array v f b > Array v f c > Array v f d
 ixRow :: Vector v a => Int > IndexedTraversal' Int (Array v V2 a) (v a)
 rows :: (Vector v a, Vector w b) => IndexedTraversal Int (Array v V2 a) (Array w V2 b) (v a) (w b)
 ixColumn :: Vector v a => Int > IndexedTraversal' Int (Array v V2 a) (v a)
 columns :: (Vector v a, Vector w b) => IndexedTraversal Int (Array v V2 a) (Array w V2 b) (v a) (w b)
 ixPlane :: Vector v a => ALens' (V3 Int) (V2 Int) > Int > IndexedTraversal' Int (Array v V3 a) (Array v V2 a)
 planes :: (Vector v a, Vector w b) => ALens' (V3 Int) (V2 Int) > IndexedTraversal Int (Array v V3 a) (Array w V3 b) (Array v V2 a) (Array w V2 b)
 flattenPlane :: (Vector v a, Vector w b) => ALens' (V3 Int) (V2 Int) > (v a > b) > Array v V3 a > Array w V2 b
 unsafeOrdinals :: (Vector v a, Shape f) => [f Int] > IndexedTraversal' (f Int) (Array v f a) a
 data MArray v l s a
 type BMArray = MArray MVector
 type UMArray = MArray MVector
 type SMArray = MArray MVector
 type PMArray = MArray MVector
 thaw :: (PrimMonad m, Vector v a) => Array v f a > m (MArray (Mutable v) f (PrimState m) a)
 freeze :: (PrimMonad m, Vector v a) => MArray (Mutable v) f (PrimState m) a > m (Array v f a)
 unsafeThaw :: (PrimMonad m, Vector v a) => Array v f a > m (MArray (Mutable v) f (PrimState m) a)
 unsafeFreeze :: (PrimMonad m, Vector v a) => MArray (Mutable v) f (PrimState m) a > m (Array v f a)
 data Delayed f a
 delayed :: (Vector v a, Vector w b, Shape f, Shape g) => Iso (Array v f a) (Array w g b) (Delayed f a) (Delayed g b)
 seqDelayed :: (Vector v a, Vector w b, Shape f, Shape g) => Iso (Array v f a) (Array w g b) (Delayed f a) (Delayed g b)
 delay :: (Vector v a, Shape f) => Array v f a > Delayed f a
 manifest :: (Vector v a, Shape f) => Delayed f a > Array v f a
 seqManifest :: (Vector v a, Shape f) => Delayed f a > Array v f a
 genDelayed :: Layout f > (f Int > a) > Delayed f a
 indexDelayed :: Shape f => Delayed f a > f Int > a
 affirm :: (Shape f, Unbox a) => Delayed f a > Delayed f a
 seqAffirm :: (Shape f, Unbox a) => Delayed f a > Delayed f a
 data Focused f a
 focusOn :: f Int > Delayed f a > Focused f a
 unfocus :: Focused f a > Delayed f a
 unfocused :: IndexedLens (f Int) (Focused f a) (Focused f b) (Delayed f a) (Delayed f b)
 extendFocus :: Shape f => (Focused f a > b) > Delayed f a > Delayed f b
 locale :: ComonadStore s w => Lens' (w a) s
 shiftFocus :: Applicative f => f Int > Focused f a > Focused f a
 data Boundary
 peekB :: Shape f => Boundary > f Int > Focused f a > a
 peeksB :: Shape f => Boundary > (f Int > f Int) > Focused f a > a
 peekRelativeB :: Shape f => Boundary > f Int > Focused f a > a
 streamGenerate :: (Monad m, Shape f) => Layout f > (f Int > a) > Stream m a
 streamGenerateM :: (Monad m, Shape f) => Layout f > (f Int > m a) > Stream m a
 streamIndexes :: (Monad m, Shape f) => Layout f > Stream m (f Int)
 bundleGenerate :: (Monad m, Shape f) => Layout f > (f Int > a) > MBundle m v a
 bundleGenerateM :: (Monad m, Shape f) => Layout f > (f Int > m a) > MBundle m v a
 bundleIndexes :: (Monad m, Shape f) => Layout f > MBundle m v (f Int)
Array types
An Array
is a vector with a shape.
Instances
Shape f => HasLayout f (Array v f a) Source #  The 
(Boxed v, Shape f) => FunctorWithIndex (f Int) (Array v f) Source #  
(Boxed v, Shape f) => FoldableWithIndex (f Int) (Array v f) Source #  
Defined in Data.Dense.Base ifoldMap :: Monoid m => (f Int > a > m) > Array v f a > m # ifolded :: IndexedFold (f Int) (Array v f a) 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 #  
Defined in Data.Dense.Base itraverse :: Applicative f0 => (f Int > a > f0 b) > Array v f a > f0 (Array v f b) # itraversed :: IndexedTraversal (f Int) (Array v f a) (Array v f b) a b #  
Boxed v => Functor (Array v f) Source #  
Boxed v => Foldable (Array v f) Source #  
Defined in Data.Dense.Base fold :: Monoid m => Array v f m > m # foldMap :: Monoid m => (a > m) > Array v f a > 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] # 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 #  
Boxed v => Traversable (Array v f) Source #  
(Boxed v, Eq1 f) => Eq1 (Array v f) Source #  
(Boxed v, Read1 f) => Read1 (Array v f) Source #  
Defined in Data.Dense.Base  
(Boxed v, Shape f, Serial1 f) => Serial1 (Array v f) Source #  
Defined in Data.Dense.Base 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 
Defined in Data.Dense.Base 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 () #  
(Vector v a, Eq1 f, Eq a) => Eq (Array v f a) Source #  
(Typeable f, Typeable v, Typeable a, Data (f Int), Data (v a)) => Data (Array v f a) Source #  
Defined in Data.Dense.Base 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 :: forall r r'. (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 #  
(Vector v a, Show1 f, Show a) => Show (Array v f a) Source #  
(Vector v a, Shape f, Binary (f Int), Binary a) => Binary (Array v f a) Source #  
(Vector v a, Shape f, Serial1 f, Serial a) => Serial (Array v f a) Source #  
Defined in Data.Dense.Base  
(Vector v a, Shape f, Serialize (f Int), Serialize a) => Serialize (Array v f a) Source #  
(NFData (f Int), NFData (v a)) => NFData (Array v f a) Source #  
Defined in Data.Dense.Base  
(Vector v a, Foldable f, Hashable a) => Hashable (Array v f a) Source #  
Defined in Data.Dense.Base  
(Shape f, Vector v a) => Ixed (Array v f a) Source #  
Defined in Data.Dense.Base  
(Shape f, Vector v a) => AsEmpty (Array v f a) Source #  
Defined in Data.Dense.Base  
(Vector v a, Vector v b) => Each (Array v f a) (Array v f b) a b Source #  
type Mutable (Array v f) Source #  
Defined in Data.Dense.Base  
type Index (Array v f a) Source #  
Defined in Data.Dense.Base  
type IxValue (Array v f a) Source #  
Defined in Data.Dense.Base 
class (Eq1 f, Additive f, Traversable f) => Shape f where Source #
Class for types that can be converted to and from linear indexes.
Nothing
shapeToIndex :: Layout f > f Int > Int Source #
Convert a shape to its linear index using the Layout
.
shapeFromIndex :: Layout f > Int > f Int Source #
Convert a linear index to a shape the Layout
.
shapeIntersect :: Layout f > Layout f > Layout f Source #
Calculate the intersection of two shapes.
unsafeShapeStep :: Layout f > f Int > f Int Source #
Increment a shape by one. It is assumed that the provided index
is inRange
.
shapeStep :: Layout f > f Int > Maybe (f Int) Source #
Increment a shape by one. It is assumed that the provided index
is inRange
.
shapeStepBetween :: f Int > Layout f > f Int > Maybe (f Int) Source #
Increment a shape by one between the two bounds
shapeInRange :: Layout f > f Int > Bool Source #
inRange ex i
checks i < ex
for every coordinate of f
.
shapeSize :: Layout f > Int Source #
The number of elements in a shape.
Instances
Layout of an array
class Shape f => HasLayout f a  a > f where Source #
Class of things that have a Layout
. This means we can use the
same functions for the various different arrays in the library.
Nothing
Instances
i ~ Int => HasLayout V0 (V0 i) Source #  
i ~ Int => HasLayout V4 (V4 i) Source #  
i ~ Int => HasLayout V3 (V3 i) Source #  
i ~ Int => HasLayout V2 (V2 i) Source #  
i ~ Int => HasLayout V1 (V1 i) Source #  
Shape f => HasLayout f (Focused f a) Source #  The 
Shape f => HasLayout f (Delayed f a) Source #  The 
Shape f => HasLayout f (Array v f a) Source #  The 
Shape f => HasLayout f (MArray v f s a) Source #  
type Layout f = f Int Source #
A Layout
is the full size of an array. This alias is used to help
distinguish between the layout of an array and an index (usually
just l Int
) in a type signature.
Extracting size
Folds over indexes
indexes :: HasLayout f a => IndexedFold Int a (f Int) Source #
Indexed fold for all the indexes in the layout.
indexesFrom :: HasLayout f a => f Int > IndexedFold Int a (f Int) Source #
Indexed fold starting starting from some point, where the index is the linear index for the original layout.
indexesBetween :: HasLayout f a => f Int > f Int > IndexedFold Int a (f Int) Source #
Indexed fold between the two indexes where the index is the linear index for the original layout.
Underlying vector
vector :: (Vector v a, Vector w b) => IndexedLens (Layout f) (Array v f a) (Array w f b) (v a) (w b) Source #
Traversals
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.
values' :: (Shape f, Vector v a, Vector v b) => IndexedTraversal (f Int) (Array v f a) (Array v f b) a b Source #
Same as values
but restrictive in the vector type.
valuesBetween :: (Shape f, Vector v a) => f Int > f Int > IndexedTraversal' (f Int) (Array v f a) a Source #
Traverse over the values
between two indexes.
Construction
Flat arrays
flat :: Vector w b => Iso (Array v V1 a) (Array w V1 b) (v a) (w b) Source #
1D arrays are just vectors. You are free to change the length of
the vector when going over
this Iso
(unlike linear
).
Note that V1
arrays are an instance of Vector
so you can use
any of the functions in Data.Vector.Generic on them without
needing to convert.
From lists
fromListInto :: (Shape f, Vector v a) => Layout f > [a] > Maybe (Array v f a) Source #
O(n) Convert the first n
elements of a list to an Array with the
given shape. Returns Nothing
if there are not enough elements in
the list.
fromListInto_ :: (Shape f, Vector v a) => Layout f > [a] > Array v f a Source #
O(n) Convert the first n
elements of a list to an Array with the
given shape. Throw an error if the list is not long enough.
From vectors
Initialisation
replicate :: (Shape f, Vector v a) => f Int > a > Array v f a Source #
O(n) Array of the given shape with the same value in each position.
generate :: (Shape f, Vector v a) => Layout f > (f Int > a) > Array v f a Source #
O(n) Construct an array of the given shape by applying the function to each index.
linearGenerate :: (Shape f, Vector v a) => Layout f > (Int > a) > Array v f a Source #
O(n) Construct an array of the given shape by applying the function to each index.
Monadic initialisation
create :: Vector v a => (forall s. ST s (MArray (Mutable v) f s a)) > Array v f a Source #
Execute the monadic action and freeze the resulting array.
createT :: (Vector v a, Traversable t) => (forall s. ST s (t (MArray (Mutable v) f s a))) > t (Array v f a) Source #
Execute the monadic action and freeze the resulting array.
replicateM :: (Monad m, Shape f, Vector v a) => Layout f > m a > m (Array v f a) Source #
O(n) Construct an array of the given shape by filling each position with the monadic value.
generateM :: (Monad m, Shape f, Vector v a) => Layout f > (f Int > m a) > m (Array v f a) Source #
O(n) Construct an array of the given shape by applying the monadic function to each index.
linearGenerateM :: (Monad m, Shape f, Vector v a) => Layout f > (Int > m a) > m (Array v f a) Source #
O(n) Construct an array of the given shape by applying the monadic function to each index.
Functions on arrays
Empty arrays
Indexing
(!) :: (Shape f, Vector v a) => Array v f a > f Int > a Source #
Index an element of an array. Throws IndexOutOfBounds
if the
index is out of bounds.
unsafeIndex :: (Shape f, Vector v a) => Array v f a > f Int > a Source #
Index an element of an array without bounds checking.
linearIndex :: Vector v a => Array v f a > Int > a Source #
Index an element of an array while ignoring its shape.
unsafeLinearIndex :: Vector v a => Array v f a > Int > a Source #
Index an element of an array while ignoring its shape, without bounds checking.
Monadic indexing
indexM :: (Shape f, Vector v a, Monad m) => Array v f a > f Int > m a Source #
O(1) Indexing in a monad.
The monad allows operations to be strict in the vector when necessary. Suppose vector copying is implemented like this:
copy mv v = ... write mv i (v ! i) ...
For lazy vectors, v ! i
would not be evaluated which means that
mv
would unnecessarily retain a reference to v
in each element
written.
With indexM
, copying can be implemented like this instead:
copy mv v = ... do x < indexM v i write mv i x
Here, no references to v
are retained because indexing (but not
the elements) is evaluated eagerly.
Throws an error if the index is out of range.
unsafeIndexM :: (Shape f, Vector v a, Monad m) => Array v f a > f Int > m a Source #
O(1) Indexing in a monad without bounds checks. See indexM
for an
explanation of why this is useful.
linearIndexM :: (Shape f, Vector v a, Monad m) => Array v f a > Int > m a Source #
O(1) Indexing in a monad. Throws an error if the index is out of range.
unsafeLinearIndexM :: (Vector v a, Monad m) => Array v f a > Int > m a Source #
O(1) Indexing in a monad without bounds checks. See indexM
for an
explanation of why this is useful.
Modifying arrays
Bulk updates
(//) :: (Vector v a, Shape f) => Array v f a > [(f Int, a)] > Array v f a Source #
For each pair (i,a) from the list, replace the array element at position i by a.
Accumulations
:: (Shape f, Vector v a)  
=> (a > b > a)  accumulating function 
> Array v f a  initial array 
> [(f Int, b)]  list of index/value pairs (of length 
> Array v f a 
O(m+n) For each pair (i,b)
from the list, replace the array element
a
at position i
by f a b
.
Mapping
map :: (Vector v a, Vector v b) => (a > b) > Array v f a > Array v f b Source #
O(n) Map a function over an array
imap :: (Shape f, Vector v a, Vector v b) => (f Int > a > b) > Array v f a > Array v f b Source #
O(n) Apply a function to every element of a vector and its index
Zipping
Tuples
zip :: (Shape f, Vector v a, Vector v b, Vector v (a, b)) => Array v f a > Array v f b > Array v f (a, b) Source #
Zip two arrays element wise. If the array's don't have the same shape, the new array with be the intersection of the two shapes.
zip3 :: (Shape f, Vector v a, Vector v b, Vector v c, Vector v (a, b, c)) => Array v f a > Array v f b > Array v f c > Array v f (a, b, c) Source #
Zip three arrays element wise. If the array's don't have the same shape, the new array with be the intersection of the two shapes.
Zip with function
zipWith :: (Shape f, Vector v a, Vector v b, Vector v c) => (a > b > c) > Array v f a > Array v f b > Array v f c Source #
Zip two arrays using the given function. If the array's don't have the same shape, the new array with be the intersection of the two shapes.
zipWith3 :: (Shape f, Vector v a, Vector v b, Vector v c, Vector v d) => (a > b > c > d) > Array v f a > Array v f b > Array v f c > Array v f d Source #
Zip three arrays using the given function. If the array's don't have the same shape, the new array with be the intersection of the two shapes.
izipWith :: (Shape f, Vector v a, Vector v b, Vector v c) => (f Int > a > b > c) > Array v f a > Array v f b > Array v f c Source #
Zip two arrays using the given function with access to the index. If the array's don't have the same shape, the new array with be the intersection of the two shapes.
izipWith3 :: (Shape f, Vector v a, Vector v b, Vector v c, Vector v d) => (f Int > a > b > c > d) > Array v f a > Array v f b > Array v f c > Array v f d Source #
Zip two arrays using the given function with access to the index. If the array's don't have the same shape, the new array with be the intersection of the two shapes.
Slices
Matrix
ixRow :: Vector v a => Int > IndexedTraversal' Int (Array v V2 a) (v a) Source #
Affine traversal over a single row in a matrix.
>>>
traverseOf_ rows print $ m & ixRow 1 . each *~ 2
[a,b,c,d] [e * 2,f * 2,g * 2,h * 2] [i,j,k,l]
The row vector should remain the same size to satisfy traversal laws but give reasonable behaviour if the size differs:
>>>
traverseOf_ rows print $ m & ixRow 1 .~ B.fromList [0,1]
[a,b,c,d] [0,1,g,h] [i,j,k,l]
>>>
traverseOf_ rows print $ m & ixRow 1 .~ B.fromList [0..100]
[a,b,c,d] [0,1,2,3] [i,j,k,l]
rows :: (Vector v a, Vector w b) => IndexedTraversal Int (Array v V2 a) (Array w V2 b) (v a) (w b) Source #
Indexed traversal over the rows of a matrix. Each row is an
efficient slice
of the original vector.
>>>
traverseOf_ rows print m
[a,b,c,d] [e,f,g,h] [i,j,k,l]
ixColumn :: Vector v a => Int > IndexedTraversal' Int (Array v V2 a) (v a) Source #
Affine traversal over a single column in a matrix.
>>>
traverseOf_ rows print $ m & ixColumn 2 . each +~ 1
[a,b,c + 1,d] [e,f,g + 1,h] [i,j,k + 1,l]
columns :: (Vector v a, Vector w b) => IndexedTraversal Int (Array v V2 a) (Array w V2 b) (v a) (w b) Source #
Indexed traversal over the columns of a matrix. Unlike rows
, each
column is a new separate vector.
>>>
traverseOf_ columns print m
[a,e,i] [b,f,j] [c,g,k] [d,h,l]
>>>
traverseOf_ rows print $ m & columns . indices odd . each .~ 0
[a,0,c,0] [e,0,g,0] [i,0,k,0]
The vectors should be the same size to be a valid traversal. If the vectors are different sizes, the number of rows in the new array will be the length of the smallest vector.
3D
ixPlane :: Vector v a => ALens' (V3 Int) (V2 Int) > Int > IndexedTraversal' Int (Array v V3 a) (Array v V2 a) Source #
planes :: (Vector v a, Vector w b) => ALens' (V3 Int) (V2 Int) > IndexedTraversal Int (Array v V3 a) (Array w V3 b) (Array v V2 a) (Array w V2 b) Source #
flattenPlane :: (Vector v a, Vector w b) => ALens' (V3 Int) (V2 Int) > (v a > b) > Array v V3 a > Array w V2 b Source #
Flatten a plane by reducing a vector in the third dimension to a single value.
Ordinals
unsafeOrdinals :: (Vector v a, Shape f) => [f Int] > IndexedTraversal' (f Int) (Array v f a) a Source #
This Traversal
should not have any duplicates in the list of
indices.
Mutable
A mutable array with a shape.
Instances
thaw :: (PrimMonad m, Vector v a) => Array v f a > m (MArray (Mutable v) f (PrimState m) a) Source #
O(n) Yield an immutable copy of the mutable array.
freeze :: (PrimMonad m, Vector v a) => MArray (Mutable v) f (PrimState m) a > m (Array v f a) Source #
O(n) Yield a mutable copy of the immutable vector.
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
A delayed representation of an array. This useful for mapping over an array in parallel.
Instances
Shape f => HasLayout f (Delayed f a) Source #  The 
Functor (Delayed f) Source #  
Shape f => Foldable (Delayed f) Source # 

Defined in Data.Dense.Base fold :: Monoid m => Delayed f m > m # foldMap :: Monoid m => (a > m) > Delayed f a > 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] # 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 #  
Shape f => Traversable (Delayed f) Source #  
Shape f => Apply (Delayed f) Source #  
Shape f => Metric (Delayed f) Source #  
Defined in Data.Dense.Base  
Shape f => Additive (Delayed f) Source #  
Defined in Data.Dense.Base 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 #  
FunctorWithIndex (f Int) (Delayed f) Source #  
Shape f => FoldableWithIndex (f Int) (Delayed f) Source # 

Defined in Data.Dense.Base ifoldMap :: Monoid m => (f Int > a > m) > Delayed f a > m # ifolded :: IndexedFold (f Int) (Delayed f a) 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 #  
Defined in Data.Dense.Base itraverse :: Applicative f0 => (f Int > a > f0 b) > Delayed f a > f0 (Delayed f b) # itraversed :: IndexedTraversal (f Int) (Delayed f a) (Delayed f b) a b #  
(Shape f, Show1 f, Show a) => Show (Delayed f a) Source #  
Shape f => Ixed (Delayed f a) Source #  
Defined in Data.Dense.Base  
Shape f => AsEmpty (Delayed f a) Source #  
Defined in Data.Dense.Base  
Shape f => Each (Delayed f a) (Delayed f b) a b Source #  
type Index (Delayed f a) Source #  
Defined in Data.Dense.Base  
type IxValue (Delayed f a) Source #  
Defined in Data.Dense.Base 
Generating delayed
delayed :: (Vector v a, Vector w b, Shape f, Shape g) => Iso (Array v f a) (Array w g b) (Delayed f a) (Delayed g b) Source #
Isomorphism between an array and its delayed representation. Conversion to the array is done in parallel.
seqDelayed :: (Vector v a, Vector w b, Shape f, Shape g) => Iso (Array v f a) (Array w g b) (Delayed f a) (Delayed g b) Source #
Isomorphism between an array and its delayed representation. Conversion to the array is done in parallel.
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.
seqManifest :: (Vector v a, Shape f) => Delayed f a > Array v f a Source #
Sequential manifestation of a delayed array.
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.
affirm :: (Shape f, Unbox a) => Delayed f a > Delayed f a Source #
manifest
an array to a UArray
and delay again. See
Data.Dense.Boxed or Data.Dense.Storable to affirm
for other
types of arrays.
seqAffirm :: (Shape f, Unbox a) => Delayed f a > Delayed f a Source #
seqManifest
an array to a UArray
and delay again. See
Data.Dense.Boxed or Data.Dense.Storable to affirm
for other
types of arrays.
Focused
A delayed representation of an array with a focus on a single
element. This element is the target of extract
.
Instances
Shape f => HasLayout f (Focused f a) Source #  The 
Functor (Focused f) Source #  
Shape f => Foldable (Focused f) Source #  
Defined in Data.Dense.Base fold :: Monoid m => Focused f m > m # foldMap :: Monoid m => (a > m) > Focused f a > 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] # 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 #  
Shape f => Traversable (Focused f) Source #  
Shape f => Comonad (Focused f) Source #  
Shape f => Extend (Focused f) Source #  
Shape f => ComonadStore (f Int) (Focused f) Source #  
Defined in Data.Dense.Base  
Shape f => FunctorWithIndex (f Int) (Focused f) Source #  Index relative to focus. 
Shape f => FoldableWithIndex (f Int) (Focused f) Source #  Index relative to focus. 
Defined in Data.Dense.Base ifoldMap :: Monoid m => (f Int > a > m) > Focused f a > m # ifolded :: IndexedFold (f Int) (Focused f a) 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. 
Defined in Data.Dense.Base itraverse :: Applicative f0 => (f Int > a > f0 b) > Focused f a > f0 (Focused f b) # itraversed :: IndexedTraversal (f Int) (Focused f a) (Focused f b) a b #  
(Shape f, Show1 f, Show a) => Show (Focused f a) Source #  
Shape f => Ixed (Focused f a) Source #  Index relative to focus. 
Defined in Data.Dense.Base  
type Index (Focused f a) Source #  
Defined in Data.Dense.Base  
type IxValue (Focused f a) Source #  
Defined in Data.Dense.Base 
Generating focused
focusOn :: f Int > Delayed f a > Focused f a Source #
Focus on a particular element of a delayed array.
unfocused :: IndexedLens (f Int) (Focused f a) (Focused f b) (Delayed f a) (Delayed f b) Source #
Indexed lens onto the delayed array, indexed at the focus.
Focus location
locale :: ComonadStore s w => Lens' (w a) s Source #
Lens onto the position of a ComonadStore
.
locale
::Lens'
(Focused
l a) (lInt
)
shiftFocus :: Applicative f => f Int > Focused f a > Focused f a Source #
Focus on a neighbouring element, relative to the current focus.
Boundary
The boundary condition used for indexing relative elements in a
Focused
.
Clamp  clamp coordinates to the extent of the array 
Mirror  mirror coordinates beyond the array extent 
Wrap  wrap coordinates around on each dimension 
peekB :: Shape f => Boundary > f Int > Focused f a > a Source #
Index a focused using a Boundary
condition.
peeksB :: Shape f => Boundary > (f Int > f Int) > Focused f a > a Source #
Index an element by applying a function the current position, using a boundary condition.
peekRelativeB :: Shape f => Boundary > f Int > Focused f a > a Source #
Index an element relative to the current focus using a Boundary
condition.
Fusion
Streams
streamGenerate :: (Monad m, Shape f) => Layout f > (f Int > a) > Stream m a Source #
Generate a stream from a Layout'
s indices.
streamGenerateM :: (Monad m, Shape f) => Layout f > (f Int > m a) > Stream m a Source #
Generate a stream from a Layout'
s indices.
streamIndexes :: (Monad m, Shape f) => Layout f > Stream m (f Int) Source #
Make a stream of the indexes of a Layout
.
Bundles
bundleGenerate :: (Monad m, Shape f) => Layout f > (f Int > a) > MBundle m v a Source #
Generate a bundle from Layout
indices.