-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | High performance, regular, shape polymorphic parallel arrays.
--
-- Repa provides high performance, regular, multi-dimensional, shape
-- polymorphic parallel arrays. All numeric data is stored unboxed.
-- Functions written with the Repa combinators are automatically parallel
-- provided you supply +RTS -Nwhatever on the command line when running
-- the program.
@package repa
@version 3.1.3.2
-- | Class of types that can be used as array shapes and indices.
module Data.Array.Repa.Shape
-- | Class of types that can be used as array shapes and indices.
class Eq sh => Shape sh
rank :: Shape sh => sh -> Int
zeroDim :: Shape sh => sh
unitDim :: Shape sh => sh
intersectDim :: Shape sh => sh -> sh -> sh
addDim :: Shape sh => sh -> sh -> sh
size :: Shape sh => sh -> Int
sizeIsValid :: Shape sh => sh -> Bool
toIndex :: Shape sh => sh -> sh -> Int
fromIndex :: Shape sh => sh -> Int -> sh
inShapeRange :: Shape sh => sh -> sh -> sh -> Bool
listOfShape :: Shape sh => sh -> [Int]
shapeOfList :: Shape sh => [Int] -> sh
deepSeq :: Shape sh => sh -> a -> a
-- | Check whether an index is a part of a given shape.
inShape :: Shape sh => sh -> sh -> Bool
-- | Nicely format a shape as a string
showShape :: Shape sh => sh -> String
module Data.Array.Repa.Repr.Hint
-- | Hints that evaluating this array is only a small amount of work. It
-- will be evaluated sequentially in the main thread, instead of in
-- parallel on the gang. This avoids the associated scheduling overhead.
data S r1
-- | Arrays with a representation tag, shape, and element type. Use one of
-- the type tags like D, U and so on for r,
-- one of DIM1, DIM2 ... for sh.
-- | Wrap an array with a smallness hint.
hintSmall :: Array r1 sh e -> Array (S r1) sh e
instance Read (Array r1 sh e) => Read (Array (S r1) sh e)
instance Show (Array r1 sh e) => Show (Array (S r1) sh e)
instance (Shape sh, FillRange r1 r2 sh e) => FillRange (S r1) r2 sh e
instance (Shape sh, Fill r1 r2 sh e) => Fill (S r1) r2 sh e
instance Repr r1 a => Repr (S r1) a
module Data.Array.Repa.Repr.Undefined
-- | An array with undefined elements.
--
--
-- - This is normally used as the last representation in a partitioned
-- array, as the previous partitions are expected to provide full
-- coverage.
--
data X
-- | Arrays with a representation tag, shape, and element type. Use one of
-- the type tags like D, U and so on for r,
-- one of DIM1, DIM2 ... for sh.
instance Read sh => Read (Array X sh e)
instance Show sh => Show (Array X sh e)
instance (Shape sh, Fillable r2 e, Num e) => Fill X r2 sh e
instance Repr X e
-- | Index types.
module Data.Array.Repa.Index
-- | An index of dimension zero
data Z
Z :: Z
-- | Our index type, used for both shapes and indices.
data (:.) tail head
(:.) :: !tail -> !head -> :. tail head
type DIM0 = Z
type DIM1 = DIM0 :. Int
type DIM2 = DIM1 :. Int
type DIM3 = DIM2 :. Int
type DIM4 = DIM3 :. Int
type DIM5 = DIM4 :. Int
-- | Helper for index construction.
--
-- Use this instead of explicit constructors like (Z :. (x ::
-- Int)). The this is sometimes needed to ensure that x is
-- constrained to be in Int.
ix1 :: Int -> DIM1
ix2 :: Int -> Int -> DIM2
ix3 :: Int -> Int -> Int -> DIM3
ix4 :: Int -> Int -> Int -> Int -> DIM4
ix5 :: Int -> Int -> Int -> Int -> Int -> DIM5
instance Show Z
instance Read Z
instance Eq Z
instance Ord Z
instance (Show tail, Show head) => Show (tail :. head)
instance (Read tail, Read head) => Read (tail :. head)
instance (Eq tail, Eq head) => Eq (tail :. head)
instance (Ord tail, Ord head) => Ord (tail :. head)
instance Shape sh => Shape (sh :. Int)
instance Shape Z
-- | Index space transformation between arrays and slices.
module Data.Array.Repa.Slice
-- | Select all indices at a certain position.
data All
All :: All
-- | Place holder for any possible shape.
data Any sh
Any :: Any sh
-- | Map a type of the index in the full shape, to the type of the index in
-- the slice.
-- | Map the type of an index in the slice, to the type of the index in the
-- full shape.
-- | Class of index types that can map to slices.
class Slice ss
sliceOfFull :: Slice ss => ss -> FullShape ss -> SliceShape ss
fullOfSlice :: Slice ss => ss -> SliceShape ss -> FullShape ss
instance Slice sl => Slice (sl :. All)
instance Slice sl => Slice (sl :. Int)
instance Slice (Any sh)
instance Slice Z
-- | Gang Primitives.
module Data.Array.Repa.Eval.Gang
-- | This globally shared gang is auto-initialised at startup and shared by
-- all Repa computations.
--
-- In a data parallel setting, it does not help to have multiple gangs
-- running at the same time. This is because a single data parallel
-- computation should already be able to keep all threads busy. If we had
-- multiple gangs running at the same time, then the system as a whole
-- would run slower as the gangs would contend for cache and thrash the
-- scheduler.
--
-- If, due to laziness or otherwise, you try to start multiple parallel
-- Repa computations at the same time, then you will get the following
-- warning on stderr at runtime:
--
--
-- Data.Array.Repa: Performing nested parallel computation sequentially.
-- You've probably called the compute or copy function while another
-- instance was already running. This can happen if the second version
-- was suspended due to lazy evaluation. Use deepSeqArray to ensure that
-- each array is fully evaluated before you compute the next one.
--
theGang :: Gang
-- | A Gang is a group of threads that execute arbitrary work
-- requests.
data Gang
-- | Fork a Gang with the given number of threads (at least 1).
forkGang :: Int -> IO Gang
-- | O(1). Yield the number of threads in the Gang.
gangSize :: Gang -> Int
-- | Issue work requests for the Gang and wait until they complete.
--
-- If the gang is already busy then print a warning to stderr and
-- just run the actions sequentially in the requesting thread.
gangIO :: Gang -> (Int -> IO ()) -> IO ()
-- | Same as gangIO but in the ST monad.
gangST :: Gang -> (Int -> ST s ()) -> ST s ()
instance Show Gang
module Data.Array.Repa.Repr.Delayed
-- | Delayed arrays are represented as functions from the index to element
-- value.
--
-- Every time you index into a delayed array the element at that position
-- is recomputed.
data D
-- | Arrays with a representation tag, shape, and element type. Use one of
-- the type tags like D, U and so on for r,
-- one of DIM1, DIM2 ... for sh.
-- | O(1). Wrap a function as a delayed array.
fromFunction :: sh -> (sh -> a) -> Array D sh a
-- | O(1). Produce the extent of an array, and a function to retrieve an
-- arbitrary element.
toFunction :: (Shape sh, Repr r1 a) => Array r1 sh a -> (sh, sh -> a)
-- | O(1). Delay an array. This wraps the internal representation to be a
-- function from indices to elements, so consumers don't need to worry
-- about what the previous representation was.
delay :: (Shape sh, Repr r e) => Array r sh e -> Array D sh e
instance (Fillable r2 e, Elt e) => FillRange D r2 DIM2 e
instance (Fillable r2 e, Shape sh) => Fill D r2 sh e
instance Repr D a
module Data.Array.Repa.Operators.Traversal
-- | Unstructured traversal.
traverse, unsafeTraverse :: (Shape sh, Shape sh', Repr r a) => Array r sh a -> (sh -> sh') -> ((sh -> a) -> sh' -> b) -> Array D sh' b
-- | Unstructured traversal over two arrays at once.
traverse2, unsafeTraverse2 :: (Shape sh, Shape sh', Shape sh'', Repr r1 a, Repr r2 b) => Array r1 sh a -> Array r2 sh' b -> (sh -> sh' -> sh'') -> ((sh -> a) -> (sh' -> b) -> (sh'' -> c)) -> Array D sh'' c
-- | Unstructured traversal over three arrays at once.
traverse3, unsafeTraverse3 :: (Shape sh1, Shape sh2, Shape sh3, Shape sh4, Repr r1 a, Repr r2 b, Repr r3 c) => Array r1 sh1 a -> Array r2 sh2 b -> Array r3 sh3 c -> (sh1 -> sh2 -> sh3 -> sh4) -> ((sh1 -> a) -> (sh2 -> b) -> (sh3 -> c) -> sh4 -> d) -> Array D sh4 d
-- | Unstructured traversal over four arrays at once.
traverse4, unsafeTraverse4 :: (Shape sh1, Shape sh2, Shape sh3, Shape sh4, Shape sh5, Repr r1 a, Repr r2 b, Repr r3 c, Repr r4 d) => Array r1 sh1 a -> Array r2 sh2 b -> Array r3 sh3 c -> Array r4 sh4 d -> (sh1 -> sh2 -> sh3 -> sh4 -> sh5) -> ((sh1 -> a) -> (sh2 -> b) -> (sh3 -> c) -> (sh4 -> d) -> sh5 -> e) -> Array D sh5 e
module Data.Array.Repa.Operators.IndexSpace
-- | Impose a new shape on the elements of an array. The new extent must be
-- the same size as the original, else error.
reshape :: (Shape sh2, Shape sh1, Repr r1 e) => sh2 -> Array r1 sh1 e -> Array D sh2 e
-- | Append two arrays.
append, ++ :: (Shape sh, Repr r1 e, Repr r2 e) => Array r1 (sh :. Int) e -> Array r2 (sh :. Int) e -> Array D (sh :. Int) e
-- | Transpose the lowest two dimensions of an array. Transposing an array
-- twice yields the original.
transpose :: (Shape sh, Repr r e) => Array r ((sh :. Int) :. Int) e -> Array D ((sh :. Int) :. Int) e
-- | Extract a sub-range of elements from an array.
extract :: (Shape sh, Repr r e) => sh -> sh -> Array r sh e -> Array D sh e
-- | Backwards permutation of an array's elements. The result array has the
-- same extent as the original.
backpermute, unsafeBackpermute :: (Shape sh1, Shape sh2, Repr r e) => sh2 -> (sh2 -> sh1) -> Array r sh1 e -> Array D sh2 e
-- | Default backwards permutation of an array's elements. If the function
-- returns Nothing then the value at that index is taken from the
-- default array (arrDft)
backpermuteDft, unsafeBackpermuteDft :: (Shape sh1, Shape sh2, Repr r0 e, Repr r1 e) => Array r0 sh2 e -> (sh2 -> Maybe sh1) -> Array r1 sh1 e -> Array D sh2 e
-- | Extend an array, according to a given slice specification.
--
-- For example, to replicate the rows of an array use the following:
--
--
-- extend arr (Any :. (5::Int) :. All)
--
extend, unsafeExtend :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl), Repr r e) => sl -> Array r (SliceShape sl) e -> Array D (FullShape sl) e
-- | Take a slice from an array, according to a given specification.
--
-- For example, to take a row from a matrix use the following:
--
--
-- slice arr (Any :. (5::Int) :. All)
--
--
-- To take a column use:
--
--
-- slice arr (Any :. (5::Int))
--
slice, unsafeSlice :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl), Repr r e) => Array r (FullShape sl) e -> sl -> Array D (SliceShape sl) e
-- | Functions without sanity or bounds checks.
module Data.Array.Repa.Unsafe
-- | Backwards permutation of an array's elements. The result array has the
-- same extent as the original.
unsafeBackpermute :: (Shape sh1, Shape sh2, Repr r e) => sh2 -> (sh2 -> sh1) -> Array r sh1 e -> Array D sh2 e
-- | Default backwards permutation of an array's elements. If the function
-- returns Nothing then the value at that index is taken from the
-- default array (arrDft)
unsafeBackpermuteDft :: (Shape sh1, Shape sh2, Repr r0 e, Repr r1 e) => Array r0 sh2 e -> (sh2 -> Maybe sh1) -> Array r1 sh1 e -> Array D sh2 e
-- | Take a slice from an array, according to a given specification.
--
-- For example, to take a row from a matrix use the following:
--
--
-- slice arr (Any :. (5::Int) :. All)
--
--
-- To take a column use:
--
--
-- slice arr (Any :. (5::Int))
--
unsafeSlice :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl), Repr r e) => Array r (FullShape sl) e -> sl -> Array D (SliceShape sl) e
-- | Extend an array, according to a given slice specification.
--
-- For example, to replicate the rows of an array use the following:
--
--
-- extend arr (Any :. (5::Int) :. All)
--
unsafeExtend :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl), Repr r e) => sl -> Array r (SliceShape sl) e -> Array D (FullShape sl) e
-- | Unstructured traversal.
unsafeTraverse :: (Shape sh, Shape sh', Repr r a) => Array r sh a -> (sh -> sh') -> ((sh -> a) -> sh' -> b) -> Array D sh' b
-- | Unstructured traversal over two arrays at once.
unsafeTraverse2 :: (Shape sh, Shape sh', Shape sh'', Repr r1 a, Repr r2 b) => Array r1 sh a -> Array r2 sh' b -> (sh -> sh' -> sh'') -> ((sh -> a) -> (sh' -> b) -> (sh'' -> c)) -> Array D sh'' c
-- | Unstructured traversal over three arrays at once.
unsafeTraverse3 :: (Shape sh1, Shape sh2, Shape sh3, Shape sh4, Repr r1 a, Repr r2 b, Repr r3 c) => Array r1 sh1 a -> Array r2 sh2 b -> Array r3 sh3 c -> (sh1 -> sh2 -> sh3 -> sh4) -> ((sh1 -> a) -> (sh2 -> b) -> (sh3 -> c) -> sh4 -> d) -> Array D sh4 d
-- | Unstructured traversal over four arrays at once.
unsafeTraverse4 :: (Shape sh1, Shape sh2, Shape sh3, Shape sh4, Shape sh5, Repr r1 a, Repr r2 b, Repr r3 c, Repr r4 d) => Array r1 sh1 a -> Array r2 sh2 b -> Array r3 sh3 c -> Array r4 sh4 d -> (sh1 -> sh2 -> sh3 -> sh4 -> sh5) -> ((sh1 -> a) -> (sh2 -> b) -> (sh3 -> c) -> (sh4 -> d) -> sh5 -> e) -> Array D sh5 e
module Data.Array.Repa.Operators.Interleave
-- | Interleave the elements of two arrays. All the input arrays must have
-- the same extent, else error. The lowest dimension of the result
-- array is twice the size of the inputs.
--
--
-- interleave2 a1 a2 b1 b2 => a1 b1 a2 b2
-- a3 a4 b3 b4 a3 b3 a4 b4
--
interleave2 :: (Shape sh, Repr r1 a, Repr r2 a) => Array r1 (sh :. Int) a -> Array r2 (sh :. Int) a -> Array D (sh :. Int) a
-- | Interleave the elements of three arrays.
interleave3 :: (Shape sh, Repr r1 a, Repr r2 a, Repr r3 a) => Array r1 (sh :. Int) a -> Array r2 (sh :. Int) a -> Array r3 (sh :. Int) a -> Array D (sh :. Int) a
-- | Interleave the elements of four arrays.
interleave4 :: (Shape sh, Repr r1 a, Repr r2 a, Repr r3 a, Repr r4 a) => Array r1 (sh :. Int) a -> Array r2 (sh :. Int) a -> Array r3 (sh :. Int) a -> Array r4 (sh :. Int) a -> Array D (sh :. Int) a
module Data.Array.Repa.Repr.ByteString
-- | Strict ByteStrings arrays are represented as ForeignPtr buffers of
-- Word8
data B
-- | Arrays with a representation tag, shape, and element type. Use one of
-- the type tags like D, U and so on for r,
-- one of DIM1, DIM2 ... for sh.
-- | O(1). Wrap a ByteString as an array.
fromByteString :: Shape sh => sh -> ByteString -> Array B sh Word8
-- | O(1). Unpack a ByteString from an array.
toByteString :: Array B sh Word8 -> ByteString
instance Read sh => Read (Array B sh Word8)
instance Show sh => Show (Array B sh Word8)
instance Repr B Word8
module Data.Array.Repa.Repr.Cursored
-- | Cursored Arrays. These are produced by Repa's stencil functions, and
-- help the fusion framework to share index compuations between array
-- elements.
--
-- The basic idea is described in ``Efficient Parallel Stencil
-- Convolution'', Ben Lippmeier and Gabriele Keller, Haskell 2011 --
-- though the underlying array representation has changed since this
-- paper was published.
data C
-- | Arrays with a representation tag, shape, and element type. Use one of
-- the type tags like D, U and so on for r,
-- one of DIM1, DIM2 ... for sh.
-- | Define a new cursored array.
makeCursored :: sh -> (sh -> cursor) -> (sh -> cursor -> cursor) -> (cursor -> e) -> Array C sh e
instance (Fillable r2 e, Elt e) => FillRange C r2 DIM2 e
instance (Fillable r2 e, Elt e) => Fill C r2 DIM2 e
instance Repr C a
module Data.Array.Repa.Repr.ForeignPtr
-- | Arrays represented as foreign buffers in the C heap.
data F
-- | Arrays with a representation tag, shape, and element type. Use one of
-- the type tags like D, U and so on for r,
-- one of DIM1, DIM2 ... for sh.
-- | O(1). Wrap a ForeignPtr as an array.
fromForeignPtr :: Shape sh => sh -> ForeignPtr e -> Array F sh e
-- | O(1). Unpack a ForeignPtr from an array.
toForeignPtr :: Array F sh e -> ForeignPtr e
-- | Compute an array sequentially and write the elements into a foreign
-- buffer without intermediate copying. If you want to copy a
-- pre-existing manifest array to a foreign buffer then delay it
-- first.
computeIntoS :: Fill r1 F sh e => ForeignPtr e -> Array r1 sh e -> IO ()
-- | Compute an array in parallel and write the elements into a foreign
-- buffer without intermediate copying. If you want to copy a
-- pre-existing manifest array to a foreign buffer then delay it
-- first.
computeIntoP :: Fill r1 F sh e => ForeignPtr e -> Array r1 sh e -> IO ()
instance Storable e => Fillable F e
instance Storable a => Repr F a
-- | Low level interface to parallel array filling operators.
module Data.Array.Repa.Eval
-- | Element types that can be used with the blockwise filling functions.
--
-- This class is mainly used to define the touch method. This is
-- used internally in the imeplementation of Repa to prevent let-binding
-- from being floated inappropriately by the GHC simplifier. Doing a
-- seq sometimes isn't enough, because the GHC simplifier can
-- erase these, and still move around the bindings.
class Elt a
touch :: Elt a => a -> IO ()
zero :: Elt a => a
one :: Elt a => a
-- | Class of manifest array representations that can be filled in parallel
-- and then frozen into immutable Repa arrays.
class Fillable r e where data family MArr r e
newMArr :: Fillable r e => Int -> IO (MArr r e)
unsafeWriteMArr :: Fillable r e => MArr r e -> Int -> e -> IO ()
unsafeFreezeMArr :: Fillable r e => sh -> MArr r e -> IO (Array r sh e)
deepSeqMArr :: Fillable r e => MArr r e -> a -> a
touchMArr :: Fillable r e => MArr r e -> IO ()
-- | Compute all elements defined by an array and write them to a fillable
-- representation.
--
-- Note that instances require that the source array to have a delayed
-- representation such as D or C. If you want to use a
-- pre-existing manifest array as the source then delay it
-- first.
class (Shape sh, Repr r1 e, Fillable r2 e) => Fill r1 r2 sh e
fillS :: Fill r1 r2 sh e => Array r1 sh e -> MArr r2 e -> IO ()
fillP :: Fill r1 r2 sh e => Array r1 sh e -> MArr r2 e -> IO ()
-- | Compute a range of elements defined by an array and write them to a
-- fillable representation.
class (Shape sh, Repr r1 e, Fillable r2 e) => FillRange r1 r2 sh e
fillRangeS :: FillRange r1 r2 sh e => Array r1 sh e -> MArr r2 e -> sh -> sh -> IO ()
fillRangeP :: FillRange r1 r2 sh e => Array r1 sh e -> MArr r2 e -> sh -> sh -> IO ()
-- | O(n). Construct a manifest array from a list.
fromList :: (Shape sh, Fillable r e) => sh -> [e] -> Array r sh e
-- | Sequential computation of array elements.
computeS :: Fill r1 r2 sh e => Array r1 sh e -> Array r2 sh e
-- | Parallel computation of array elements.
--
--
-- - The source array must have a delayed representation like D,
-- C or P, and the result a manifest representation
-- like U or F.
-- - If you want to copy data between manifest representations then use
-- copyP instead.
-- - If you want to convert a manifest array back to a delayed
-- representation then use delay instead.
--
computeP :: (Shape sh, Fill r1 r2 sh e, Repr r2 e, Monad m) => Array r1 sh e -> m (Array r2 sh e)
-- | Suspended parallel computation of array elements.
--
-- This version creates a thunk that will evaluate the array on demand.
-- If you force it when another parallel computation is already running
-- then you will get a runtime warning and evaluation will be sequential.
-- Use deepSeqArray and now to ensure that each array is
-- evaluated before proceeding to the next one.
--
-- If unsure then just use the monadic version computeP. This one
-- ensures that each array is fully evaluated before continuing.
suspendedComputeP :: Fill r1 r2 sh e => Array r1 sh e -> Array r2 sh e
-- | Sequential copying of arrays.
copyS :: (Repr r1 e, Fill D r2 sh e) => Array r1 sh e -> Array r2 sh e
-- | Parallel copying of arrays.
--
--
-- - This is a wrapper that delays an array before calling
-- computeP.
-- - You can use it to copy manifest arrays between
-- representations.
--
copyP :: (Shape sh, Fill D r2 sh e, Repr r1 e, Repr r2 e, Monad m) => Array r1 sh e -> m (Array r2 sh e)
-- | Suspended parallel copy of array elements.
suspendedCopyP :: (Repr r1 e, Fill D r2 sh e) => Array r1 sh e -> Array r2 sh e
-- | Monadic version of deepSeqArray.
--
-- Forces an suspended array computation to be completed at this point in
-- a monadic computation.
--
--
-- do let arr2 = suspendedComputeP arr1
-- ...
-- arr3 <- now $ arr2
-- ...
--
now :: (Shape sh, Repr r e, Monad m) => Array r sh e -> m (Array r sh e)
-- | Fill something sequentially.
--
--
-- - The array is filled linearly from start to finish.
--
fillChunkedS :: Int -> (Int -> a -> IO ()) -> (Int -> a) -> IO ()
-- | Fill something in parallel.
--
--
-- - The array is split into linear chunks and each thread fills one
-- chunk.
--
fillChunkedP :: Int -> (Int -> a -> IO ()) -> (Int -> a) -> IO ()
-- | Fill something in parallel, using a separate IO action for each
-- thread.
fillChunkedIOP :: Int -> (Int -> a -> IO ()) -> (Int -> IO (Int -> IO a)) -> IO ()
-- | Fill a block in a rank-2 array in parallel.
--
--
-- - Blockwise filling can be more cache-efficient than linear filling
-- for rank-2 arrays.
-- - Coordinates given are of the filled edges of the block.
-- - We divide the block into columns, and give one column to each
-- thread.
-- - Each column is filled in row major order from top to bottom.
--
fillBlock2P :: Elt a => (Int -> a -> IO ()) -> (DIM2 -> a) -> Int# -> Int# -> Int# -> Int# -> Int# -> IO ()
-- | Fill a block in a rank-2 array sequentially.
--
--
-- - Blockwise filling can be more cache-efficient than linear filling
-- for rank-2 arrays.
-- - Coordinates given are of the filled edges of the block.
-- - The block is filled in row major order from top to bottom.
--
fillBlock2S :: Elt a => (Int -> a -> IO ()) -> (DIM2 -> a) -> Int# -> Int# -> Int# -> Int# -> Int# -> IO ()
-- | Fill a block in a rank-2 array, sequentially.
--
--
-- - Blockwise filling can be more cache-efficient than linear filling
-- for rank-2 arrays.
-- - Using cursor functions can help to expose inter-element indexing
-- computations to the GHC and LLVM optimisers.
-- - Coordinates given are of the filled edges of the block.
-- - The block is filled in row major order from top to bottom.
--
fillCursoredBlock2S :: Elt a => (Int -> a -> IO ()) -> (DIM2 -> cursor) -> (DIM2 -> cursor -> cursor) -> (cursor -> a) -> Int# -> Int# -> Int# -> Int# -> Int# -> IO ()
-- | Fill a block in a rank-2 array in parallel.
--
--
-- - Blockwise filling can be more cache-efficient than linear filling
-- for rank-2 arrays.
-- - Using cursor functions can help to expose inter-element indexing
-- computations to the GHC and LLVM optimisers.
-- - Coordinates given are of the filled edges of the block.
-- - We divide the block into columns, and give one column to each
-- thread.
-- - Each column is filled in row major order from top to bottom.
--
fillCursoredBlock2P :: Elt a => (Int -> a -> IO ()) -> (DIM2 -> cursor) -> (DIM2 -> cursor -> cursor) -> (cursor -> a) -> Int# -> Int# -> Int# -> Int# -> Int# -> IO ()
-- | Select indices matching a predicate.
--
--
-- - This primitive can be useful for writing filtering functions.
--
selectChunkedS :: Shape sh => (sh -> a -> IO ()) -> (sh -> Bool) -> (sh -> a) -> sh -> IO Int
-- | Select indices matching a predicate, in parallel.
--
--
-- - This primitive can be useful for writing filtering functions.
-- - The array is split into linear chunks, with one chunk being given
-- to each thread.
-- - The number of elements in the result array depends on how many
-- threads you're running the program with.
--
selectChunkedP :: Unbox a => (Int -> Bool) -> (Int -> a) -> Int -> IO [IOVector a]
module Data.Array.Repa.Repr.Partitioned
-- | Partitioned arrays. The last partition takes priority
--
-- These are produced by Repa's support functions and allow arrays to be
-- defined using a different element function for each partition.
--
-- The basic idea is described in ``Efficient Parallel Stencil
-- Convolution'', Ben Lippmeier and Gabriele Keller, Haskell 2011 --
-- though the underlying array representation has changed since this
-- paper was published.
data P r1 r2
-- | Arrays with a representation tag, shape, and element type. Use one of
-- the type tags like D, U and so on for r,
-- one of DIM1, DIM2 ... for sh.
data Range sh
Range :: !sh -> !sh -> (sh -> Bool) -> Range sh
-- | Check whether an index is within the given range.
inRange :: Range sh -> sh -> Bool
instance (FillRange r1 r3 sh e, Fill r2 r3 sh e, Fillable r3 e) => Fill (P r1 r2) r3 sh e
instance (Repr r1 e, Repr r2 e) => Repr (P r1 r2) e
-- | Functions specialised for arrays of dimension 2.
module Data.Array.Repa.Specialised.Dim2
-- | Check if an index lies inside the given extent. As opposed to
-- inRange from Data.Array.Repa.Index, this is a
-- short-circuited test that checks that lowest dimension first.
isInside2 :: DIM2 -> DIM2 -> Bool
-- | Check if an index lies outside the given extent. As opposed to
-- inRange from Data.Array.Repa.Index, this is a
-- short-circuited test that checks the lowest dimension first.
isOutside2 :: DIM2 -> DIM2 -> Bool
-- | Given the extent of an array, clamp the components of an index so they
-- lie within the given array. Outlying indices are clamped to the index
-- of the nearest border element.
clampToBorder2 :: DIM2 -> DIM2 -> DIM2
-- | Make a 2D partitioned array from two others, one to produce the
-- elements in the internal region, and one to produce elements in the
-- border region. The two arrays must have the same extent. The border
-- must be the same width on all sides.
makeBordered2 :: (Repr r1 a, Repr r2 a) => DIM2 -> Int -> Array r1 DIM2 a -> Array r2 DIM2 a -> Array (P r1 (P r2 (P r2 (P r2 (P r2 X))))) DIM2 a
module Data.Array.Repa.Repr.Unboxed
-- | Unboxed arrays are represented as unboxed vectors.
--
-- The implementation uses Data.Vector.Unboxed which is based on
-- type families and picks an efficient, specialised representation for
-- every element type. In particular, unboxed vectors of pairs are
-- represented as pairs of unboxed vectors. This is the most efficient
-- representation for numerical data.
data U
class (Vector Vector a, MVector MVector a) => Unbox a
-- | Arrays with a representation tag, shape, and element type. Use one of
-- the type tags like D, U and so on for r,
-- one of DIM1, DIM2 ... for sh.
-- | Sequential computation of array elements..
--
--
-- - This is an alias for computeS with a more specific
-- type.
--
computeUnboxedS :: Fill r1 U sh e => Array r1 sh e -> Array U sh e
-- | Parallel computation of array elements.
--
--
-- - This is an alias for computeP with a more specific
-- type.
--
computeUnboxedP :: (Fill r1 U sh e, Monad m, Unbox e) => Array r1 sh e -> m (Array U sh e)
-- | O(n). Convert a list to an unboxed vector array.
--
--
-- - This is an alias for fromList with a more specific
-- type.
--
fromListUnboxed :: (Shape sh, Unbox a) => sh -> [a] -> Array U sh a
-- | O(1). Wrap an unboxed vector as an array.
fromUnboxed :: (Shape sh, Unbox e) => sh -> Vector e -> Array U sh e
-- | O(1). Unpack an unboxed vector from an array.
toUnboxed :: Unbox e => Array U sh e -> Vector e
-- | O(1). Zip some unboxed arrays. The shapes must be identical else
-- error.
zip :: (Shape sh, Unbox a, Unbox b) => Array U sh a -> Array U sh b -> Array U sh (a, b)
-- | O(1). Zip some unboxed arrays. The shapes must be identical else
-- error.
zip3 :: (Shape sh, Unbox a, Unbox b, Unbox c) => Array U sh a -> Array U sh b -> Array U sh c -> Array U sh (a, b, c)
-- | O(1). Zip some unboxed arrays. The shapes must be identical else
-- error.
zip4 :: (Shape sh, Unbox a, Unbox b, Unbox c, Unbox d) => Array U sh a -> Array U sh b -> Array U sh c -> Array U sh d -> Array U sh (a, b, c, d)
-- | O(1). Zip some unboxed arrays. The shapes must be identical else
-- error.
zip5 :: (Shape sh, Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Array U sh a -> Array U sh b -> Array U sh c -> Array U sh d -> Array U sh e -> Array U sh (a, b, c, d, e)
-- | O(1). Zip some unboxed arrays. The shapes must be identical else
-- error.
zip6 :: (Shape sh, Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => Array U sh a -> Array U sh b -> Array U sh c -> Array U sh d -> Array U sh e -> Array U sh f -> Array U sh (a, b, c, d, e, f)
-- | O(1). Unzip an unboxed array.
unzip :: (Unbox a, Unbox b) => Array U sh (a, b) -> (Array U sh a, Array U sh b)
-- | O(1). Unzip an unboxed array.
unzip3 :: (Unbox a, Unbox b, Unbox c) => Array U sh (a, b, c) -> (Array U sh a, Array U sh b, Array U sh c)
-- | O(1). Unzip an unboxed array.
unzip4 :: (Unbox a, Unbox b, Unbox c, Unbox d) => Array U sh (a, b, c, d) -> (Array U sh a, Array U sh b, Array U sh c, Array U sh d)
-- | O(1). Unzip an unboxed array.
unzip5 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e) => Array U sh (a, b, c, d, e) -> (Array U sh a, Array U sh b, Array U sh c, Array U sh d, Array U sh e)
-- | O(1). Unzip an unboxed array.
unzip6 :: (Unbox a, Unbox b, Unbox c, Unbox d, Unbox e, Unbox f) => Array U sh (a, b, c, d, e, f) -> (Array U sh a, Array U sh b, Array U sh c, Array U sh d, Array U sh e, Array U sh f)
instance (Read sh, Read e, Unbox e) => Read (Array U sh e)
instance (Show sh, Show e, Unbox e) => Show (Array U sh e)
instance Unbox e => Fillable U e
instance Unbox a => Repr U a
module Data.Array.Repa.Operators.Mapping
-- | Apply a worker function to each element of an array, yielding a new
-- array with the same extent.
map :: (Shape sh, Repr r a) => (a -> b) -> Array r sh a -> Array D sh b
-- | Combine two arrays, element-wise, with a binary operator. If the
-- extent of the two array arguments differ, then the resulting array's
-- extent is their intersection.
zipWith :: (Shape sh, Repr r1 a, Repr r2 b) => (a -> b -> c) -> Array r1 sh a -> Array r2 sh b -> Array D sh c
(+^) :: (Num c, Shape sh, Repr r2 c, Repr r1 c) => Array r1 sh c -> Array r2 sh c -> Array D sh c
(-^) :: (Num c, Shape sh, Repr r2 c, Repr r1 c) => Array r1 sh c -> Array r2 sh c -> Array D sh c
(*^) :: (Num c, Shape sh, Repr r2 c, Repr r1 c) => Array r1 sh c -> Array r2 sh c -> Array D sh c
(/^) :: (Fractional c, Shape sh, Repr r2 c, Repr r1 c) => Array r1 sh c -> Array r2 sh c -> Array D sh c
-- | Combining versions of map and zipWith that preserve
-- the representation of cursored and partitioned arrays.
--
-- For cursored (C) arrays, the cursoring of the source array is
-- preserved.
--
-- For partitioned (P) arrays, the worker function is fused with
-- each array partition separately, instead of treating the whole array
-- as a single bulk object.
--
-- Preserving the cursored and/or paritioned representation of an array
-- is will make follow-on computation more efficient than if the array
-- was converted to a vanilla Delayed (D) array as with plain
-- map and zipWith.
--
-- If the source array is not cursored or partitioned then cmap
-- and czipWith are identical to the plain functions.
class Combine r1 a r2 b | r1 -> r2
cmap :: (Combine r1 a r2 b, Shape sh) => (a -> b) -> Array r1 sh a -> Array r2 sh b
czipWith :: (Combine r1 a r2 b, Shape sh, Repr r c) => (c -> a -> b) -> Array r sh c -> Array r1 sh a -> Array r2 sh b
instance Combine X a X b
instance Unbox a => Combine U a D b
instance Combine r1 a r2 b => Combine (S r1) a (S r2) b
instance (Combine r11 a r21 b, Combine r12 a r22 b) => Combine (P r11 r12) a (P r21 r22) b
instance Storable a => Combine F a D b
instance Combine D a D b
instance Combine C a C b
instance Combine B Word8 D b
module Data.Array.Repa.Operators.Selection
-- | Produce an array by applying a predicate to a range of integers. If
-- the predicate matches, then use the second function to generate the
-- element.
--
--
-- - This is a low-level function helpful for writing filtering
-- operations on arrays.
-- - Use the integer as the index into the array you're filtering.
--
selectP :: (Unbox a, Monad m) => (Int -> Bool) -> (Int -> a) -> Int -> m (Array U DIM1 a)
module Data.Array.Repa.Operators.Reduction
-- | Sequential reduction of the innermost dimension of an arbitrary rank
-- array.
--
-- Combine this with transpose to fold any other dimension.
foldS :: (Shape sh, Elt a, Unbox a, Repr r a) => (a -> a -> a) -> a -> Array r (sh :. Int) a -> Array U sh a
-- | Parallel reduction of the innermost dimension of an arbitray rank
-- array.
--
-- The first argument needs to be an associative sequential operator. The
-- starting element must be neutral with respect to the operator, for
-- example 0 is neutral with respect to (+) as 0 +
-- a = a. These restrictions are required to support parallel
-- evaluation, as the starting element may be used multiple times
-- depending on the number of threads.
foldP :: (Shape sh, Elt a, Unbox a, Repr r a, Monad m) => (a -> a -> a) -> a -> Array r (sh :. Int) a -> m (Array U sh a)
-- | Sequential reduction of an array of arbitrary rank to a single scalar
-- value.
foldAllS :: (Shape sh, Elt a, Unbox a, Repr r a) => (a -> a -> a) -> a -> Array r sh a -> a
-- | Parallel reduction of an array of arbitrary rank to a single scalar
-- value.
--
-- The first argument needs to be an associative sequential operator. The
-- starting element must be neutral with respect to the operator, for
-- example 0 is neutral with respect to (+) as 0 +
-- a = a. These restrictions are required to support parallel
-- evaluation, as the starting element may be used multiple times
-- depending on the number of threads.
foldAllP :: (Shape sh, Elt a, Unbox a, Repr r a, Monad m) => (a -> a -> a) -> a -> Array r sh a -> m a
-- | Sequential sum the innermost dimension of an array.
sumS :: (Shape sh, Num a, Elt a, Unbox a, Repr r a) => Array r (sh :. Int) a -> Array U sh a
-- | Parallel sum the innermost dimension of an array.
sumP :: (Shape sh, Num a, Elt a, Unbox a, Repr r a, Monad m) => Array r (sh :. Int) a -> m (Array U sh a)
-- | Sequential sum of all the elements of an array.
sumAllS :: (Shape sh, Elt a, Unbox a, Num a, Repr r a) => Array r sh a -> a
-- | Parallel sum all the elements of an array.
sumAllP :: (Shape sh, Elt a, Unbox a, Num a, Repr r a, Monad m) => Array r sh a -> m a
-- | Check whether two arrays have the same shape and contain equal
-- elements, sequentially.
equalsS :: (Shape sh, Repr r1 e, Repr r2 e, Eq e) => Array r1 sh e -> Array r2 sh e -> Bool
-- | Check whether two arrays have the same shape and contain equal
-- elements, in parallel.
equalsP :: (Shape sh, Repr r1 e, Repr r2 e, Eq e, Monad m) => Array r1 sh e -> Array r2 sh e -> m Bool
instance (Shape sh, Repr r e, Eq e) => Eq (Array r sh e)
module Data.Array.Repa.Repr.Vector
-- | Arrays represented as boxed vectors.
--
-- This representation should only be used when your element type doesn't
-- have an Unbox instsance. If it does, then use the Unboxed
-- U representation will be faster.
data V
-- | Arrays with a representation tag, shape, and element type. Use one of
-- the type tags like D, U and so on for r,
-- one of DIM1, DIM2 ... for sh.
-- | Sequential computation of array elements.
--
--
-- - This is an alias for compute with a more specific
-- type.
--
computeVectorS :: Fill r1 V sh e => Array r1 sh e -> Array V sh e
-- | Parallel computation of array elements.
computeVectorP :: (Fill r1 V sh e, Monad m) => Array r1 sh e -> m (Array V sh e)
-- | O(n). Convert a list to a boxed vector array.
--
--
-- - This is an alias for fromList with a more specific
-- type.
--
fromListVector :: Shape sh => sh -> [a] -> Array V sh a
-- | O(1). Wrap a boxed vector as an array.
fromVector :: Shape sh => sh -> Vector e -> Array V sh e
-- | O(1). Unpack a boxed vector from an array.
toVector :: Array V sh e -> Vector e
instance (Read sh, Read e) => Read (Array V sh e)
instance (Show sh, Show e) => Show (Array V sh e)
instance Fillable V e
instance Repr V a
-- | Repa arrays are wrappers around a linear structure that holds the
-- element data. The representation tag determines what structure holds
-- the data.
--
-- Delayed Representations (functions that compute elements)
--
--
-- - D -- Functions from indices to elements.
-- - C -- Cursor functions.
--
--
-- Manifest Representations (real data)
--
--
-- - U -- Adaptive unboxed vectors.
-- - V -- Boxed vectors.
-- - B -- Strict ByteStrings.
-- - F -- Foreign memory buffers.
--
--
-- Meta Representations
--
--
-- - P -- Arrays that are partitioned into several
-- representations.
-- - S -- Hints that computing this array is a small amount of
-- work that should not be done in parallel.
-- - X -- Arrays whose elements are all undefined.
--
--
-- Array fusion is achieved via the delayed (D) and cursored
-- (C) representations. At compile time, the GHC simplifier
-- combines the functions contained within D and C arrays
-- without needing to create manifest intermediate arrays.
--
-- Advice for writing fast code:
--
--
-- - Repa does not support nested parallellism. This means that you
-- cannot map a parallel worker function across an array and then
-- call computeP to evaluate it, or pass a parallel worker to
-- parallel reductions such as foldP. If you do then you will get
-- a run-time warning and the code will run very slowly.
-- - Arrays of type (Array D sh a) or (Array C sh a)
-- are not real arrays. They are represented as functions that
-- compute each element on demand. You need to use computeS,
-- computeP, computeUnboxedP and so on to actually evaluate
-- the elements.
-- - Add INLINE pragmas to all leaf-functions in your code,
-- expecially ones that compute numeric results. Non-inlined lazy
-- function calls can cost upwards of 50 cycles each, while each numeric
-- operator only costs one (or less). Inlining leaf functions also
-- ensures they are specialised at the appropriate numeric types.
-- - Add bang patterns to all function arguments, and all fields of
-- your data types. In a high-performance Haskell program, the cost of
-- lazy evaluation can easily dominate the run time if not handled
-- correctly. You don't want to rely on the strictness analyser in
-- numeric code because if it does not return a perfect result then the
-- performance of your program will be awful. This is less of a problem
-- for general Haskell code, and in a different context relying on
-- strictness analysis is fine.
-- - Scheduling a parallel computation takes about 200us on an OSX
-- machine. You should switch to sequential evaluation functions like
-- computeS and foldS for small arrays in inner loops, and
-- at the bottom of a divide-and-conquer algorithm. Consider using a
-- computeP that evaluates an array defined using computeS
-- or foldS for each element.
-- - Compile the modules that use Repa with the following flags:
-- -Odph -rtsopts -threaded -fno-liberate-case
-- -funfolding-use-threshold1000 -funfolding-keeness-factor1000
-- -fllvm -optlo-O3 You don't want the liberate-case transform
-- because it tends to duplicate too much intermediate code, and is not
-- needed if you use bang patterns as per point 4. The unfolding flags
-- tell the inliner to not to fool around with heuristics, and just
-- inline everything. If the binaries become too big then split the array
-- part of your program into separate modules and only compile those with
-- the unfolding flags.
-- - Repa writes to the GHC eventlog at the start and end of each
-- parallel computation. Use threadscope to see what your program is
-- doing.
-- - When you're sure your program works, switch to the unsafe versions
-- of functions like traverse. These don't do bounds checks.
--
module Data.Array.Repa
-- | Arrays with a representation tag, shape, and element type. Use one of
-- the type tags like D, U and so on for r,
-- one of DIM1, DIM2 ... for sh.
-- | Class of array representations that we can read elements from.
class Repr r e where index arr ix = arr `linearIndex` toIndex (extent arr) ix unsafeIndex arr ix = arr `unsafeLinearIndex` toIndex (extent arr) ix unsafeLinearIndex = linearIndex
extent :: (Repr r e, Shape sh) => Array r sh e -> sh
index, unsafeIndex :: (Repr r e, Shape sh) => Array r sh e -> sh -> e
linearIndex, unsafeLinearIndex :: (Repr r e, Shape sh) => Array r sh e -> Int -> e
deepSeqArray :: (Repr r e, Shape sh) => Array r sh e -> b -> b
-- | O(1). Alias for index
(!) :: (Repr r e, Shape sh) => Array r sh e -> sh -> e
-- | O(n). Convert an array to a list.
toList :: (Shape sh, Repr r e) => Array r sh e -> [e]
-- | Apply deepSeqArray to up to four arrays.
deepSeqArrays :: (Shape sh, Repr r e) => [Array r sh e] -> b -> b
-- | Parallel computation of array elements.
--
--
-- - The source array must have a delayed representation like D,
-- C or P, and the result a manifest representation
-- like U or F.
-- - If you want to copy data between manifest representations then use
-- copyP instead.
-- - If you want to convert a manifest array back to a delayed
-- representation then use delay instead.
--
computeP :: (Shape sh, Fill r1 r2 sh e, Repr r2 e, Monad m) => Array r1 sh e -> m (Array r2 sh e)
-- | Sequential computation of array elements.
computeS :: Fill r1 r2 sh e => Array r1 sh e -> Array r2 sh e
-- | Parallel copying of arrays.
--
--
-- - This is a wrapper that delays an array before calling
-- computeP.
-- - You can use it to copy manifest arrays between
-- representations.
--
copyP :: (Shape sh, Fill D r2 sh e, Repr r1 e, Repr r2 e, Monad m) => Array r1 sh e -> m (Array r2 sh e)
-- | Sequential copying of arrays.
copyS :: (Repr r1 e, Fill D r2 sh e) => Array r1 sh e -> Array r2 sh e
-- | Delayed arrays are represented as functions from the index to element
-- value.
--
-- Every time you index into a delayed array the element at that position
-- is recomputed.
data D
-- | O(1). Wrap a function as a delayed array.
fromFunction :: sh -> (sh -> a) -> Array D sh a
-- | O(1). Produce the extent of an array, and a function to retrieve an
-- arbitrary element.
toFunction :: (Shape sh, Repr r1 a) => Array r1 sh a -> (sh, sh -> a)
-- | O(1). Delay an array. This wraps the internal representation to be a
-- function from indices to elements, so consumers don't need to worry
-- about what the previous representation was.
delay :: (Shape sh, Repr r e) => Array r sh e -> Array D sh e
-- | Unboxed arrays are represented as unboxed vectors.
--
-- The implementation uses Data.Vector.Unboxed which is based on
-- type families and picks an efficient, specialised representation for
-- every element type. In particular, unboxed vectors of pairs are
-- represented as pairs of unboxed vectors. This is the most efficient
-- representation for numerical data.
data U
-- | Parallel computation of array elements.
--
--
-- - This is an alias for computeP with a more specific
-- type.
--
computeUnboxedP :: (Fill r1 U sh e, Monad m, Unbox e) => Array r1 sh e -> m (Array U sh e)
-- | Sequential computation of array elements..
--
--
-- - This is an alias for computeS with a more specific
-- type.
--
computeUnboxedS :: Fill r1 U sh e => Array r1 sh e -> Array U sh e
-- | O(n). Convert a list to an unboxed vector array.
--
--
-- - This is an alias for fromList with a more specific
-- type.
--
fromListUnboxed :: (Shape sh, Unbox a) => sh -> [a] -> Array U sh a
-- | O(1). Wrap an unboxed vector as an array.
fromUnboxed :: (Shape sh, Unbox e) => sh -> Vector e -> Array U sh e
-- | O(1). Unpack an unboxed vector from an array.
toUnboxed :: Unbox e => Array U sh e -> Vector e
-- | Impose a new shape on the elements of an array. The new extent must be
-- the same size as the original, else error.
reshape :: (Shape sh2, Shape sh1, Repr r1 e) => sh2 -> Array r1 sh1 e -> Array D sh2 e
-- | Append two arrays.
append, ++ :: (Shape sh, Repr r1 e, Repr r2 e) => Array r1 (sh :. Int) e -> Array r2 (sh :. Int) e -> Array D (sh :. Int) e
-- | Extract a sub-range of elements from an array.
extract :: (Shape sh, Repr r e) => sh -> sh -> Array r sh e -> Array D sh e
-- | Transpose the lowest two dimensions of an array. Transposing an array
-- twice yields the original.
transpose :: (Shape sh, Repr r e) => Array r ((sh :. Int) :. Int) e -> Array D ((sh :. Int) :. Int) e
-- | Backwards permutation of an array's elements. The result array has the
-- same extent as the original.
backpermute :: (Shape sh1, Shape sh2, Repr r e) => sh2 -> (sh2 -> sh1) -> Array r sh1 e -> Array D sh2 e
-- | Default backwards permutation of an array's elements. If the function
-- returns Nothing then the value at that index is taken from the
-- default array (arrDft)
backpermuteDft :: (Shape sh1, Shape sh2, Repr r0 e, Repr r1 e) => Array r0 sh2 e -> (sh2 -> Maybe sh1) -> Array r1 sh1 e -> Array D sh2 e
-- | Take a slice from an array, according to a given specification.
--
-- For example, to take a row from a matrix use the following:
--
--
-- slice arr (Any :. (5::Int) :. All)
--
--
-- To take a column use:
--
--
-- slice arr (Any :. (5::Int))
--
slice :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl), Repr r e) => Array r (FullShape sl) e -> sl -> Array D (SliceShape sl) e
-- | Extend an array, according to a given slice specification.
--
-- For example, to replicate the rows of an array use the following:
--
--
-- extend arr (Any :. (5::Int) :. All)
--
extend :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl), Repr r e) => sl -> Array r (SliceShape sl) e -> Array D (FullShape sl) e
-- | Apply a worker function to each element of an array, yielding a new
-- array with the same extent.
map :: (Shape sh, Repr r a) => (a -> b) -> Array r sh a -> Array D sh b
-- | Combine two arrays, element-wise, with a binary operator. If the
-- extent of the two array arguments differ, then the resulting array's
-- extent is their intersection.
zipWith :: (Shape sh, Repr r1 a, Repr r2 b) => (a -> b -> c) -> Array r1 sh a -> Array r2 sh b -> Array D sh c
(+^) :: (Num c, Shape sh, Repr r2 c, Repr r1 c) => Array r1 sh c -> Array r2 sh c -> Array D sh c
(-^) :: (Num c, Shape sh, Repr r2 c, Repr r1 c) => Array r1 sh c -> Array r2 sh c -> Array D sh c
(*^) :: (Num c, Shape sh, Repr r2 c, Repr r1 c) => Array r1 sh c -> Array r2 sh c -> Array D sh c
(/^) :: (Fractional c, Shape sh, Repr r2 c, Repr r1 c) => Array r1 sh c -> Array r2 sh c -> Array D sh c
-- | Combining versions of map and zipWith that preserve
-- the representation of cursored and partitioned arrays.
--
-- For cursored (C) arrays, the cursoring of the source array is
-- preserved.
--
-- For partitioned (P) arrays, the worker function is fused with
-- each array partition separately, instead of treating the whole array
-- as a single bulk object.
--
-- Preserving the cursored and/or paritioned representation of an array
-- is will make follow-on computation more efficient than if the array
-- was converted to a vanilla Delayed (D) array as with plain
-- map and zipWith.
--
-- If the source array is not cursored or partitioned then cmap
-- and czipWith are identical to the plain functions.
class Combine r1 a r2 b | r1 -> r2
cmap :: (Combine r1 a r2 b, Shape sh) => (a -> b) -> Array r1 sh a -> Array r2 sh b
czipWith :: (Combine r1 a r2 b, Shape sh, Repr r c) => (c -> a -> b) -> Array r sh c -> Array r1 sh a -> Array r2 sh b
-- | Unstructured traversal.
traverse :: (Shape sh, Shape sh', Repr r a) => Array r sh a -> (sh -> sh') -> ((sh -> a) -> sh' -> b) -> Array D sh' b
-- | Unstructured traversal over two arrays at once.
traverse2 :: (Shape sh, Shape sh', Shape sh'', Repr r1 a, Repr r2 b) => Array r1 sh a -> Array r2 sh' b -> (sh -> sh' -> sh'') -> ((sh -> a) -> (sh' -> b) -> (sh'' -> c)) -> Array D sh'' c
-- | Unstructured traversal over three arrays at once.
traverse3 :: (Shape sh1, Shape sh2, Shape sh3, Shape sh4, Repr r1 a, Repr r2 b, Repr r3 c) => Array r1 sh1 a -> Array r2 sh2 b -> Array r3 sh3 c -> (sh1 -> sh2 -> sh3 -> sh4) -> ((sh1 -> a) -> (sh2 -> b) -> (sh3 -> c) -> sh4 -> d) -> Array D sh4 d
-- | Unstructured traversal over four arrays at once.
traverse4 :: (Shape sh1, Shape sh2, Shape sh3, Shape sh4, Shape sh5, Repr r1 a, Repr r2 b, Repr r3 c, Repr r4 d) => Array r1 sh1 a -> Array r2 sh2 b -> Array r3 sh3 c -> Array r4 sh4 d -> (sh1 -> sh2 -> sh3 -> sh4 -> sh5) -> ((sh1 -> a) -> (sh2 -> b) -> (sh3 -> c) -> (sh4 -> d) -> sh5 -> e) -> Array D sh5 e
-- | Interleave the elements of two arrays. All the input arrays must have
-- the same extent, else error. The lowest dimension of the result
-- array is twice the size of the inputs.
--
--
-- interleave2 a1 a2 b1 b2 => a1 b1 a2 b2
-- a3 a4 b3 b4 a3 b3 a4 b4
--
interleave2 :: (Shape sh, Repr r1 a, Repr r2 a) => Array r1 (sh :. Int) a -> Array r2 (sh :. Int) a -> Array D (sh :. Int) a
-- | Interleave the elements of three arrays.
interleave3 :: (Shape sh, Repr r1 a, Repr r2 a, Repr r3 a) => Array r1 (sh :. Int) a -> Array r2 (sh :. Int) a -> Array r3 (sh :. Int) a -> Array D (sh :. Int) a
-- | Interleave the elements of four arrays.
interleave4 :: (Shape sh, Repr r1 a, Repr r2 a, Repr r3 a, Repr r4 a) => Array r1 (sh :. Int) a -> Array r2 (sh :. Int) a -> Array r3 (sh :. Int) a -> Array r4 (sh :. Int) a -> Array D (sh :. Int) a
-- | Parallel reduction of the innermost dimension of an arbitray rank
-- array.
--
-- The first argument needs to be an associative sequential operator. The
-- starting element must be neutral with respect to the operator, for
-- example 0 is neutral with respect to (+) as 0 +
-- a = a. These restrictions are required to support parallel
-- evaluation, as the starting element may be used multiple times
-- depending on the number of threads.
foldP :: (Shape sh, Elt a, Unbox a, Repr r a, Monad m) => (a -> a -> a) -> a -> Array r (sh :. Int) a -> m (Array U sh a)
-- | Sequential reduction of the innermost dimension of an arbitrary rank
-- array.
--
-- Combine this with transpose to fold any other dimension.
foldS :: (Shape sh, Elt a, Unbox a, Repr r a) => (a -> a -> a) -> a -> Array r (sh :. Int) a -> Array U sh a
-- | Parallel reduction of an array of arbitrary rank to a single scalar
-- value.
--
-- The first argument needs to be an associative sequential operator. The
-- starting element must be neutral with respect to the operator, for
-- example 0 is neutral with respect to (+) as 0 +
-- a = a. These restrictions are required to support parallel
-- evaluation, as the starting element may be used multiple times
-- depending on the number of threads.
foldAllP :: (Shape sh, Elt a, Unbox a, Repr r a, Monad m) => (a -> a -> a) -> a -> Array r sh a -> m a
-- | Sequential reduction of an array of arbitrary rank to a single scalar
-- value.
foldAllS :: (Shape sh, Elt a, Unbox a, Repr r a) => (a -> a -> a) -> a -> Array r sh a -> a
-- | Parallel sum the innermost dimension of an array.
sumP :: (Shape sh, Num a, Elt a, Unbox a, Repr r a, Monad m) => Array r (sh :. Int) a -> m (Array U sh a)
-- | Sequential sum the innermost dimension of an array.
sumS :: (Shape sh, Num a, Elt a, Unbox a, Repr r a) => Array r (sh :. Int) a -> Array U sh a
-- | Parallel sum all the elements of an array.
sumAllP :: (Shape sh, Elt a, Unbox a, Num a, Repr r a, Monad m) => Array r sh a -> m a
-- | Sequential sum of all the elements of an array.
sumAllS :: (Shape sh, Elt a, Unbox a, Num a, Repr r a) => Array r sh a -> a
-- | Check whether two arrays have the same shape and contain equal
-- elements, in parallel.
equalsP :: (Shape sh, Repr r1 e, Repr r2 e, Eq e, Monad m) => Array r1 sh e -> Array r2 sh e -> m Bool
-- | Check whether two arrays have the same shape and contain equal
-- elements, sequentially.
equalsS :: (Shape sh, Repr r1 e, Repr r2 e, Eq e) => Array r1 sh e -> Array r2 sh e -> Bool
-- | Produce an array by applying a predicate to a range of integers. If
-- the predicate matches, then use the second function to generate the
-- element.
--
--
-- - This is a low-level function helpful for writing filtering
-- operations on arrays.
-- - Use the integer as the index into the array you're filtering.
--
selectP :: (Unbox a, Monad m) => (Int -> Bool) -> (Int -> a) -> Int -> m (Array U DIM1 a)
-- | Efficient computation of stencil based convolutions.
module Data.Array.Repa.Stencil
-- | Represents a convolution stencil that we can apply to array. Only
-- statically known stencils are supported right now.
data Stencil sh a
-- | Static stencils are used when the coefficients are fixed, and known at
-- compile time.
StencilStatic :: !sh -> !a -> !sh -> a -> a -> a -> Stencil sh a
stencilExtent :: Stencil sh a -> !sh
stencilZero :: Stencil sh a -> !a
stencilAcc :: Stencil sh a -> !sh -> a -> a -> a
-- | How to handle the case when the stencil lies partly outside the array.
data Boundary a
-- | Treat points outside as having a constant value.
BoundConst :: a -> Boundary a
-- | Clamp points outside to the same value as the edge pixel.
BoundClamp :: Boundary a
-- | Make a stencil from a function yielding coefficients at each index.
makeStencil :: Num a => sh -> (sh -> Maybe a) -> Stencil sh a
module Data.Array.Repa.Stencil.Dim2
-- | Wrapper for makeStencil that requires a DIM2 stencil.
makeStencil2 :: Num a => Int -> Int -> (DIM2 -> Maybe a) -> Stencil DIM2 a
-- | QuasiQuoter for producing a static stencil defintion.
--
-- A definition like
--
--
-- [stencil2| 0 1 0
-- 1 0 1
-- 0 1 0 |]
--
--
-- Is converted to:
--
--
-- makeStencil2 (Z:.3:.3)
-- (\ix -> case ix of
-- Z :. -1 :. 0 -> Just 1
-- Z :. 0 :. -1 -> Just 1
-- Z :. 0 :. 1 -> Just 1
-- Z :. 1 :. 0 -> Just 1
-- _ -> Nothing)
--
stencil2 :: QuasiQuoter
type PC5 = P C (P (S D) (P (S D) (P (S D) (P (S D) X))))
-- | Apply a stencil to every element of a 2D array.
mapStencil2 :: Repr r a => Boundary a -> Stencil DIM2 a -> Array r DIM2 a -> Array PC5 DIM2 a
-- | Like mapStencil2 but with the parameters flipped.
forStencil2 :: Repr r a => Boundary a -> Array r DIM2 a -> Stencil DIM2 a -> Array PC5 DIM2 a