Copyright  (c) Christopher Chalmers 

License  BSD3 
Maintainer  Christopher Chalmers 
Stability  provisional 
Portability  nonportable 
Safe Haskell  None 
Language  Haskell2010 
Unboxed multidimensional arrays.
 type UArray = Array Vector
 class (Vector Vector a, MVector MVector a) => Unbox a
 class (Eq1 f, Additive f, Traversable f) => Shape f
 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 :: (Unbox a, Unbox b) => IndexedLens (Layout f) (UArray f a) (UArray f b) (Vector a) (Vector b)
 values :: (Shape f, Unbox a, Unbox b) => IndexedTraversal (f Int) (UArray f a) (UArray f b) a b
 values' :: (Shape f, Unbox a, Unbox b) => IndexedTraversal (f Int) (UArray f a) (UArray f b) a b
 valuesBetween :: (Shape f, Unbox a) => f Int > f Int > IndexedTraversal' (f Int) (UArray f a) a
 flat :: Unbox b => Iso (UArray V1 a) (UArray V1 b) (Vector a) (Vector b)
 fromList :: Unbox a => [a] > UArray V1 a
 fromListInto :: (Shape f, Unbox a) => Layout f > [a] > Maybe (UArray f a)
 fromListInto_ :: (Shape f, Unbox a) => Layout f > [a] > UArray f a
 fromVectorInto :: (Shape f, Unbox a) => Layout f > Vector a > Maybe (UArray f a)
 fromVectorInto_ :: (Shape f, Unbox a) => Layout f > Vector a > UArray f a
 replicate :: (Shape f, Unbox a) => f Int > a > UArray f a
 generate :: (Shape f, Unbox a) => Layout f > (f Int > a) > UArray f a
 linearGenerate :: (Shape f, Unbox a) => Layout f > (Int > a) > UArray f a
 create :: Unbox a => (forall s. ST s (UMArray f s a)) > UArray f a
 replicateM :: (Monad m, Shape f, Unbox a) => Layout f > m a > m (UArray f a)
 generateM :: (Monad m, Shape f, Unbox a) => Layout f > (f Int > m a) > m (UArray f a)
 linearGenerateM :: (Monad m, Shape f, Unbox a) => Layout f > (Int > m a) > m (UArray f a)
 empty :: (Unbox a, Additive f) => UArray f a
 null :: Foldable f => UArray f a > Bool
 (!) :: (Shape f, Unbox a) => UArray f a > f Int > a
 (!?) :: (Shape f, Unbox a) => UArray f a > f Int > Maybe a
 unsafeIndex :: (Shape f, Unbox a) => UArray f a > f Int > a
 linearIndex :: Unbox a => UArray f a > Int > a
 unsafeLinearIndex :: Unbox a => UArray f a > Int > a
 indexM :: (Shape f, Unbox a, Monad m) => UArray f a > f Int > m a
 unsafeIndexM :: (Shape f, Unbox a, Monad m) => UArray f a > f Int > m a
 linearIndexM :: (Shape f, Unbox a, Monad m) => UArray f a > Int > m a
 unsafeLinearIndexM :: (Unbox a, Monad m) => UArray f a > Int > m a
 (//) :: (Unbox a, Shape f) => UArray f a > [(f Int, a)] > UArray f a
 accum :: (Shape f, Unbox a) => (a > b > a) > UArray f a > [(f Int, b)] > UArray f a
 map :: (Unbox a, Unbox b) => (a > b) > UArray f a > UArray f b
 imap :: (Shape f, Unbox a, Unbox b) => (f Int > a > b) > UArray f a > UArray f b
 zip :: (Shape f, Unbox a, Unbox b) => UArray f a > UArray f b > UArray f (a, b)
 zip3 :: (Shape f, Unbox a, Unbox b, Unbox c) => UArray f a > UArray f b > UArray f c > UArray f (a, b, c)
 zipWith :: (Shape f, Unbox a, Unbox b, Unbox c) => (a > b > c) > UArray f a > UArray f b > UArray f c
 zipWith3 :: (Shape f, Unbox a, Unbox b, Unbox c, Unbox d) => (a > b > c > d) > UArray f a > UArray f b > UArray f c > UArray f d
 izipWith :: (Shape f, Unbox a, Unbox b, Unbox c) => (f Int > a > b > c) > UArray f a > UArray f b > UArray f c
 izipWith3 :: (Shape f, Unbox a, Unbox b, Unbox c, Unbox d) => (f Int > a > b > c > d) > UArray f a > UArray f b > UArray f c > UArray f d
 ixRow :: Unbox a => Int > IndexedTraversal' Int (UArray V2 a) (Vector a)
 rows :: (Unbox a, Unbox b) => IndexedTraversal Int (UArray V2 a) (UArray V2 b) (Vector a) (Vector b)
 ixColumn :: Unbox a => Int > IndexedTraversal' Int (UArray V2 a) (Vector a)
 columns :: (Unbox a, Unbox b) => IndexedTraversal Int (UArray V2 a) (UArray V2 b) (Vector a) (Vector b)
 ixPlane :: Unbox a => ALens' (V3 Int) (V2 Int) > Int > IndexedTraversal' Int (UArray V3 a) (UArray V2 a)
 planes :: (Unbox a, Unbox b) => ALens' (V3 Int) (V2 Int) > IndexedTraversal Int (UArray V3 a) (UArray V3 b) (UArray V2 a) (UArray V2 b)
 flattenPlane :: (Unbox a, Unbox b) => ALens' (V3 Int) (V2 Int) > (Vector a > b) > UArray V3 a > UArray V2 b
 unsafeOrdinals :: (Unbox a, Shape f) => [f Int] > IndexedTraversal' (f Int) (UArray f a) a
 type UMArray = MArray MVector
 thaw :: (PrimMonad m, Unbox a) => UArray f a > m (UMArray f (PrimState m) a)
 freeze :: (PrimMonad m, Unbox a) => UMArray f (PrimState m) a > m (UArray f a)
 unsafeThaw :: (PrimMonad m, Unbox a) => UArray f a > m (UMArray f (PrimState m) a)
 unsafeFreeze :: (PrimMonad m, Unbox a) => UMArray f (PrimState m) a > m (UArray f a)
 data Delayed f a
 delayed :: (Unbox a, Unbox b, Shape f, Shape k) => Iso (UArray f a) (UArray k b) (Delayed f a) (Delayed k b)
 seqDelayed :: (Unbox a, Unbox b, Shape f, Shape k) => Iso (UArray f a) (UArray k b) (Delayed f a) (Delayed k b)
 delay :: (Unbox a, Shape f) => UArray f a > Delayed f a
 manifest :: (Unbox a, Shape f) => Delayed f a > UArray f a
 seqManifest :: (Unbox a, Shape f) => Delayed f a > UArray 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
UArray types
class (Vector Vector a, MVector MVector a) => Unbox a #
Unbox Bool  
Unbox Char  
Unbox Double  
Unbox Float  
Unbox Int  
Unbox Int8  
Unbox Int16  
Unbox Int32  
Unbox Int64  
Unbox Word  
Unbox Word8  
Unbox Word16  
Unbox Word32  
Unbox Word64  
Unbox ()  
(RealFloat a, Unbox a) => Unbox (Complex a)  
Unbox a => Unbox (Quaternion a)  
Unbox a => Unbox (Plucker a)  
Unbox a => Unbox (V4 a)  
Unbox a => Unbox (V3 a)  
Unbox a => Unbox (V2 a)  
Unbox a => Unbox (V1 a)  
Unbox (V0 a)  
(Unbox a, Unbox b) => Unbox (a, b)  
(Unbox a, Unbox b, Unbox c) => Unbox (a, b, c)  
(Dim k n, Unbox a) => Unbox (V k n a)  
(Unbox a, Unbox b, Unbox c, Unbox d) => Unbox (a, b, c, d)  
(Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Unbox (a, b, c, d, e)  
(Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => Unbox (a, b, c, d, e, f)  
class (Eq1 f, Additive f, Traversable f) => Shape f Source #
Class for types that can be converted to and from linear indexes.
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.
layout :: Lens' a (Layout f) Source #
Lens onto the Layout
of something.
layout :: a ~ f Int => (Layout f > g (Layout f)) > a > g a Source #
Lens onto the Layout
of something.
(~) * 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 #  
(~) * i Int => HasLayout V0 (V0 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 :: (Unbox a, Unbox b) => IndexedLens (Layout f) (UArray f a) (UArray f b) (Vector a) (Vector b) Source #
Traversals
values :: (Shape f, Unbox a, Unbox b) => IndexedTraversal (f Int) (UArray f a) (UArray f b) a b Source #
Same as values
but restrictive in the vector type.
values' :: (Shape f, Unbox a, Unbox b) => IndexedTraversal (f Int) (UArray f a) (UArray f b) a b Source #
Same as values
but restrictive in the vector type.
valuesBetween :: (Shape f, Unbox a) => f Int > f Int > IndexedTraversal' (f Int) (UArray f a) a Source #
Same as values
but restrictive in the vector type.
Construction
Flat arrays
From lists
fromListInto :: (Shape f, Unbox a) => Layout f > [a] > Maybe (UArray f a) Source #
O(n) Convert the first n
elements of a list to an UArrayith the
given shape. Returns Nothing
if there are not enough elements in
the list.
fromListInto_ :: (Shape f, Unbox a) => Layout f > [a] > UArray f a Source #
O(n) Convert the first n
elements of a list to an UArrayith the
given shape. Throw an error if the list is not long enough.
From vectors
Initialisation
replicate :: (Shape f, Unbox a) => f Int > a > UArray f a Source #
O(n) UArray of the given shape with the same value in each position.
generate :: (Shape f, Unbox a) => Layout f > (f Int > a) > UArray f a Source #
O(n) Construct an array of the given shape by applying the function to each index.
linearGenerate :: (Shape f, Unbox a) => Layout f > (Int > a) > UArray f a Source #
O(n) Construct an array of the given shape by applying the function to each index.
Monadic initialisation
create :: Unbox a => (forall s. ST s (UMArray f s a)) > UArray f a Source #
Execute the monadic action and freeze the resulting array.
replicateM :: (Monad m, Shape f, Unbox a) => Layout f > m a > m (UArray 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, Unbox a) => Layout f > (f Int > m a) > m (UArray 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, Unbox a) => Layout f > (Int > m a) > m (UArray 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, Unbox a) => UArray f a > f Int > a Source #
Index an element of an array. Throws IndexOutOfBounds
if the
index is out of bounds.
unsafeIndex :: (Shape f, Unbox a) => UArray f a > f Int > a Source #
Index an element of an array without bounds checking.
linearIndex :: Unbox a => UArray f a > Int > a Source #
Index an element of an array while ignoring its shape.
unsafeLinearIndex :: Unbox a => UArray f a > Int > a Source #
Index an element of an array while ignoring its shape, without bounds checking.
Monadic indexing
indexM :: (Shape f, Unbox a, Monad m) => UArray 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, Unbox a, Monad m) => UArray 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, Unbox a, Monad m) => UArray f a > Int > m a Source #
O(1) Indexing in a monad. Throws an error if the index is out of range.
unsafeLinearIndexM :: (Unbox a, Monad m) => UArray 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
(//) :: (Unbox a, Shape f) => UArray f a > [(f Int, a)] > UArray f a Source #
For each pair (i,a) from the list, replace the array element at position i by a.
Accumulations
:: (Shape f, Unbox a)  
=> (a > b > a)  accumulating function 
> UArray f a  initial array 
> [(f Int, b)]  list of index/value pairs (of length 
> UArray 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 :: (Unbox a, Unbox b) => (a > b) > UArray f a > UArray f b Source #
O(n) Map a function over an array
imap :: (Shape f, Unbox a, Unbox b) => (f Int > a > b) > UArray f a > UArray f b Source #
O(n) Apply a function to every element of a vector and its index
Zipping
Tuples
zip :: (Shape f, Unbox a, Unbox b) => UArray f a > UArray f b > UArray 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, Unbox a, Unbox b, Unbox c) => UArray f a > UArray f b > UArray f c > UArray 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, Unbox a, Unbox b, Unbox c) => (a > b > c) > UArray f a > UArray f b > UArray 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, Unbox a, Unbox b, Unbox c, Unbox d) => (a > b > c > d) > UArray f a > UArray f b > UArray f c > UArray 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, Unbox a, Unbox b, Unbox c) => (f Int > a > b > c) > UArray f a > UArray f b > UArray 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, Unbox a, Unbox b, Unbox c, Unbox d) => (f Int > a > b > c > d) > UArray f a > UArray f b > UArray f c > UArray 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 :: Unbox a => Int > IndexedTraversal' Int (UArray V2 a) (Vector a) Source #
Affine traversal over a single row in a matrix.
>>>
traverseOf_ rows print $ m & ixRow 1 . each +~ 2
[1,2,3] [6,7,8]
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 .~ V.fromList [0,1]
[1,2,3] [0,1,6]
>>>
traverseOf_ rows print $ m & ixRow 1 .~ V.fromList [0..100]
[1,2,3] [0,1,2]
rows :: (Unbox a, Unbox b) => IndexedTraversal Int (UArray V2 a) (UArray V2 b) (Vector a) (Vector b) Source #
Indexed traversal over the rows of a matrix. Each row is an
efficient slice
of the original vector.
>>>
traverseOf_ rows print m
[1,2,3] [4,5,6]
ixColumn :: Unbox a => Int > IndexedTraversal' Int (UArray V2 a) (Vector a) Source #
Affine traversal over a single column in a matrix.
>>>
traverseOf_ rows print $ m & ixColumn 2 . each *~ 10
[1,2,30] [4,5,60]
columns :: (Unbox a, Unbox b) => IndexedTraversal Int (UArray V2 a) (UArray V2 b) (Vector a) (Vector b) Source #
Indexed traversal over the columns of a matrix. Unlike rows
, each
column is a new separate vector.
>>>
traverseOf_ columns print m
[1,4] [2,5] [3,6]
>>>
traverseOf_ rows print $ m & columns . indices odd . each .~ 0
[1,0,3] [4,0,6]
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 :: Unbox a => ALens' (V3 Int) (V2 Int) > Int > IndexedTraversal' Int (UArray V3 a) (UArray V2 a) Source #
planes :: (Unbox a, Unbox b) => ALens' (V3 Int) (V2 Int) > IndexedTraversal Int (UArray V3 a) (UArray V3 b) (UArray V2 a) (UArray V2 b) Source #
flattenPlane :: (Unbox a, Unbox b) => ALens' (V3 Int) (V2 Int) > (Vector a > b) > UArray V3 a > UArray V2 b Source #
Flatten a plane by reducing a vector in the third dimension to a single value.
Ordinals
unsafeOrdinals :: (Unbox a, Shape f) => [f Int] > IndexedTraversal' (f Int) (UArray f a) a Source #
This Traversal
should not have any duplicates in the list of
indices.
Mutable
thaw :: (PrimMonad m, Unbox a) => UArray f a > m (UMArray f (PrimState m) a) Source #
O(n) Yield an immutable copy of the mutable array.
freeze :: (PrimMonad m, Unbox a) => UMArray f (PrimState m) a > m (UArray f a) Source #
O(n) Yield a mutable copy of the immutable vector.
unsafeThaw :: (PrimMonad m, Unbox a) => UArray f a > m (UMArray 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, Unbox a) => UMArray f (PrimState m) a > m (UArray 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.
Shape f => HasLayout f (Delayed f a) Source #  The 
Functor (Delayed f) Source #  
Shape f => Foldable (Delayed f) Source # 

Shape f => Traversable (Delayed f) Source #  
Shape f => Metric (Delayed f) Source #  
Shape f => Additive (Delayed f) Source #  
Shape f => Apply (Delayed f) Source #  
FunctorWithIndex (f Int) (Delayed f) Source #  
Shape f => FoldableWithIndex (f Int) (Delayed f) Source # 

Shape f => TraversableWithIndex (f Int) (Delayed f) Source #  
(Shape f, Show1 f, Show a) => Show (Delayed f a) Source #  
Shape f => Ixed (Delayed f a) Source #  
Shape f => AsEmpty (Delayed f a) Source #  
Shape f => Each (Delayed f a) (Delayed f b) a b Source #  
type Index (Delayed f a) Source #  
type IxValue (Delayed f a) Source #  
Generating delayed
delayed :: (Unbox a, Unbox b, Shape f, Shape k) => Iso (UArray f a) (UArray k b) (Delayed f a) (Delayed k b) Source #
Isomorphism between an array and its delayed representation. Conversion to the array is done in parallel.
seqDelayed :: (Unbox a, Unbox b, Shape f, Shape k) => Iso (UArray f a) (UArray k b) (Delayed f a) (Delayed k b) Source #
Isomorphism between an array and its delayed representation. Conversion to the array is done in sequence.
delay :: (Unbox a, Shape f) => UArray f a > Delayed f a Source #
Turn a material array into a delayed one with the same shape.
manifest :: (Unbox a, Shape f) => Delayed f a > UArray f a Source #
Parallel manifestation of a delayed array into a material one.
seqManifest :: (Unbox a, Shape f) => Delayed f a > UArray 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.
seqAffirm :: (Shape f, Unbox a) => Delayed f a > Delayed f a Source #
seqManifest
an array to a UArray
and delay again.
Focused
A delayed representation of an array with a focus on a single
element. This element is the target of extract
.
Shape f => HasLayout f (Focused f a) Source #  The 
Functor (Focused f) Source #  
Shape f => Foldable (Focused f) Source #  
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 #  
Shape f => FunctorWithIndex (f Int) (Focused f) Source #  Index relative to focus. 
Shape f => FoldableWithIndex (f Int) (Focused f) Source #  Index relative to focus. 
Shape f => TraversableWithIndex (f Int) (Focused f) Source #  Index relative to focus. 
(Shape f, Show1 f, Show a) => Show (Focused f a) Source #  
Shape f => Ixed (Focused f a) Source #  Index relative to focus. 
type Index (Focused f a) Source #  
type IxValue (Focused f a) Source #  
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.