-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | High performance, regular, shape polymorphic parallel arrays. -- @package repa @version 3.3.1.1 -- | 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.HintSmall -- | 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 -- | 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, LoadRange r1 sh e) => LoadRange (S r1) sh e instance (Shape sh, Load r1 sh e) => Load (S r1) sh e instance Source r1 a => Source (S r1) a -- | 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 -- | 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, Source 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 => Source r e => Array r sh e -> Array D sh e instance Elt e => LoadRange D DIM2 e instance Shape sh => Load D sh e instance Source D a module Data.Array.Repa.Operators.Traversal -- | Unstructured traversal. traverse :: (Source r a, Shape sh, Shape sh') => Array r sh a -> (sh -> sh') -> ((sh -> a) -> sh' -> b) -> Array D sh' b -- | Unstructured traversal. unsafeTraverse :: (Source r a, Shape sh, Shape sh') => Array r sh a -> (sh -> sh') -> ((sh -> a) -> sh' -> b) -> Array D sh' b -- | Unstructured traversal over two arrays at once. traverse2 :: (Source r1 a, Source r2 b, Shape sh, Shape sh', Shape sh'') => Array r1 sh a -> Array r2 sh' b -> (sh -> sh' -> sh'') -> ((sh -> a) -> (sh' -> b) -> (sh'' -> c)) -> Array D sh'' c -- | Unstructured traversal over two arrays at once. unsafeTraverse2 :: (Source r1 a, Source r2 b, Shape sh, Shape sh', Shape sh'') => 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 :: (Source r1 a, Source r2 b, Source r3 c, Shape sh1, Shape sh2, Shape sh3, Shape sh4) => 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 three arrays at once. unsafeTraverse3 :: (Source r1 a, Source r2 b, Source r3 c, Shape sh1, Shape sh2, Shape sh3, Shape sh4) => 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 :: (Source r1 a, Source r2 b, Source r3 c, Source r4 d, Shape sh1, Shape sh2, Shape sh3, Shape sh4, Shape sh5) => 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 -- | Unstructured traversal over four arrays at once. unsafeTraverse4 :: (Source r1 a, Source r2 b, Source r3 c, Source r4 d, Shape sh1, Shape sh2, Shape sh3, Shape sh4, Shape sh5) => 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 sh1, Shape sh2, Source r1 e) => sh2 -> Array r1 sh1 e -> Array D sh2 e -- | Append two arrays. append :: (Shape sh, Source r1 e, Source r2 e) => Array r1 (sh :. Int) e -> Array r2 (sh :. Int) e -> Array D (sh :. Int) e -- | Append two arrays. (++) :: (Shape sh, Source r1 e, Source 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, Source 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, Source r e) => sh -> sh -> Array r sh e -> Array D sh e -- | Backwards permutation of an array's elements. backpermute :: (Shape sh1, Shape sh2, Source r e) => sh2 -> (sh2 -> sh1) -> Array r sh1 e -> Array D sh2 e -- | Backwards permutation of an array's elements. unsafeBackpermute :: (Shape sh1, Shape sh2, Source 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, Source r1 e, Source r2 e) => Array r2 sh2 e -> (sh2 -> Maybe sh1) -> Array r1 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, Source r1 e, Source r2 e) => Array r2 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 :: (Slice sl, Shape (SliceShape sl), Shape (FullShape sl), Source r e) => sl -> Array r (SliceShape sl) e -> Array D (FullShape 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 (SliceShape sl), Shape (FullShape sl), Source 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 :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl), Source r e) => Array r (FullShape sl) e -> sl -> Array D (SliceShape 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)) --unsafeSlice :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl), Source 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. unsafeBackpermute :: (Shape sh1, Shape sh2, Source 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, Source r1 e, Source r2 e) => Array r2 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), Source 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 (SliceShape sl), Shape (FullShape sl), Source r e) => sl -> Array r (SliceShape sl) e -> Array D (FullShape sl) e -- | Unstructured traversal. unsafeTraverse :: (Source r a, Shape sh, Shape sh') => Array r sh a -> (sh -> sh') -> ((sh -> a) -> sh' -> b) -> Array D sh' b -- | Unstructured traversal over two arrays at once. unsafeTraverse2 :: (Source r1 a, Source r2 b, Shape sh, Shape sh', Shape sh'') => 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 :: (Source r1 a, Source r2 b, Source r3 c, Shape sh1, Shape sh2, Shape sh3, Shape sh4) => 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 :: (Source r1 a, Source r2 b, Source r3 c, Source r4 d, Shape sh1, Shape sh2, Shape sh3, Shape sh4, Shape sh5) => 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, Source r1 a, Source 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, Source r1 a, Source r2 a, Source 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, Source r1 a, Source r2 a, Source r3 a, Source 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 -- | 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 Source B Word8 module Data.Array.Repa.Repr.ForeignPtr -- | Arrays represented as foreign buffers in the C heap. data F -- | 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 :: (Load r1 sh e, Storable 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 :: (Load r1 sh e, Storable e) => ForeignPtr e -> Array r1 sh e -> IO () instance Storable e => Target F e instance Storable a => Source F a module Data.Array.Repa.Repr.HintInterleave -- | Hints that computing this array will be an unbalanced workload and -- evaluation should be interleaved between the processors. data I r1 -- | Wrap an array with a unbalanced-ness hint. hintInterleave :: Array r1 sh e -> Array (I r1) sh e instance Read (Array r1 sh e) => Read (Array (I r1) sh e) instance Show (Array r1 sh e) => Show (Array (I r1) sh e) instance (Shape sh, Load D sh e) => Load (I D) sh e instance Source r1 a => Source (I r1) 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 where touch = gtouch . from zero = to gzero one = to gone touch :: Elt a => a -> IO () zero :: Elt a => a one :: Elt a => a -- | Class of manifest array representations that can be constructed in -- parallel. class Target r e where data family MVec r e newMVec :: Target r e => Int -> IO (MVec r e) unsafeWriteMVec :: Target r e => MVec r e -> Int -> e -> IO () unsafeFreezeMVec :: Target r e => sh -> MVec r e -> IO (Array r sh e) deepSeqMVec :: Target r e => MVec r e -> a -> a touchMVec :: Target r e => MVec r e -> IO () -- | Compute all elements defined by an array and write them to a manifest -- target 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 (Source r1 e, Shape sh) => Load r1 sh e loadS :: (Load r1 sh e, Target r2 e) => Array r1 sh e -> MVec r2 e -> IO () loadP :: (Load r1 sh e, Target r2 e) => Array r1 sh e -> MVec r2 e -> IO () -- | Compute a range of elements defined by an array and write them to a -- fillable representation. class (Source r1 e, Shape sh) => LoadRange r1 sh e loadRangeS :: (LoadRange r1 sh e, Target r2 e) => Array r1 sh e -> MVec r2 e -> sh -> sh -> IO () loadRangeP :: (LoadRange r1 sh e, Target r2 e) => Array r1 sh e -> MVec r2 e -> sh -> sh -> IO () -- | O(n). Construct a manifest array from a list. fromList :: (Shape sh, Target r e) => sh -> [e] -> Array r sh e -- | Sequential computation of array elements. computeS :: (Load r1 sh e, Target r2 e) => Array r1 sh e -> Array r2 sh e -- | Parallel computation of array elements. -- --
-- do let arr2 = suspendedComputeP arr1 -- ... -- arr3 <- now $ arr2 -- ... --now :: (Shape sh, Source r e, Monad m) => Array r sh e -> m (Array r sh e) -- | Fill something sequentially. -- --
-- [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 :: Source r a => Boundary a -> Stencil DIM2 a -> Array r DIM2 a -> Array PC5 DIM2 a -- | Like mapStencil2 but with the parameters flipped. forStencil2 :: Source r a => Boundary a -> Array r DIM2 a -> Stencil DIM2 a -> Array PC5 DIM2 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. -- -- Elements are reduced in the order of their indices, from lowest to -- highest. Applications of the operator are associatied arbitrarily. -- --
-- >>> let c 0 x = x; c x 0 = x; c x y = y -- -- >>> let a = fromListUnboxed (Z :. 2 :. 2) [1,2,3,4] :: Array U (Z :. Int :. Int) Int -- -- >>> foldS c 0 a -- AUnboxed (Z :. 2) (fromList [2,4]) --foldS :: (Shape sh, Source r a, Elt a, Unbox 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. -- -- Elements are reduced in the order of their indices, from lowest to -- highest. Applications of the operator are associatied arbitrarily. -- --
-- >>> let c 0 x = x; c x 0 = x; c x y = y -- -- >>> let a = fromListUnboxed (Z :. 2 :. 2) [1,2,3,4] :: Array U (Z :. Int :. Int) Int -- -- >>> foldP c 0 a -- AUnboxed (Z :. 2) (fromList [2,4]) --foldP :: (Shape sh, Source r a, Elt a, Unbox 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. -- -- Elements are reduced in row-major order. Applications of the operator -- are associated arbitrarily. foldAllS :: (Shape sh, Source r a, Elt a, Unbox 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. -- -- Elements are reduced in row-major order. Applications of the operator -- are associated arbitrarily. foldAllP :: (Shape sh, Source r a, Elt a, Unbox a, Monad m) => (a -> a -> a) -> a -> Array r sh a -> m a -- | Sequential sum the innermost dimension of an array. sumS :: (Shape sh, Source r a, Num a, Elt a, Unbox a) => Array r (sh :. Int) a -> Array U sh a -- | Parallel sum the innermost dimension of an array. sumP :: (Shape sh, Source r a, Num a, Elt a, Unbox 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, Source r a, Elt a, Unbox a, Num a) => Array r sh a -> a -- | Parallel sum all the elements of an array. sumAllP :: (Shape sh, Source r a, Elt a, Unbox a, Num 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, Eq sh, Source r1 a, Source r2 a, Eq a) => Array r1 sh a -> Array r2 sh a -> Bool -- | Check whether two arrays have the same shape and contain equal -- elements, in parallel. equalsP :: (Shape sh, Eq sh, Source r1 a, Source r2 a, Eq a, Monad m) => Array r1 sh a -> Array r2 sh a -> m Bool instance (Shape sh, Eq sh, Source r a, Eq a) => Eq (Array r sh a) 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 -- | Sequential computation of array elements. -- --
-- 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), Source 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 (SliceShape sl), Shape (FullShape sl), Source 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, Source 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, Source r1 a, Source r2 b) => (a -> b -> c) -> Array r1 sh a -> Array r2 sh b -> Array D sh c (+^) :: (Source r2 c, Source r1 c, Shape sh, Num c) => Array r1 sh c -> Array r2 sh c -> Array D sh c (-^) :: (Source r2 c, Source r1 c, Shape sh, Num c) => Array r1 sh c -> Array r2 sh c -> Array D sh c (*^) :: (Source r2 c, Source r1 c, Shape sh, Num c) => Array r1 sh c -> Array r2 sh c -> Array D sh c (/^) :: (Source r2 c, Source r1 c, Shape sh, Fractional c) => Array r1 sh c -> Array r2 sh c -> Array D sh c -- | Structured 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 smap -- and szipWith are identical to the plain functions. class Structured r1 a b where type family TR r1 smap :: (Structured r1 a b, Shape sh) => (a -> b) -> Array r1 sh a -> Array (TR r1) sh b szipWith :: (Structured r1 a b, Shape sh, Source r c) => (c -> a -> b) -> Array r sh c -> Array r1 sh a -> Array (TR r1) sh b -- | Unstructured traversal. traverse :: (Source r a, Shape sh, Shape sh') => Array r sh a -> (sh -> sh') -> ((sh -> a) -> sh' -> b) -> Array D sh' b -- | Unstructured traversal over two arrays at once. traverse2 :: (Source r1 a, Source r2 b, Shape sh, Shape sh', Shape sh'') => 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 :: (Source r1 a, Source r2 b, Source r3 c, Shape sh1, Shape sh2, Shape sh3, Shape sh4) => 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 :: (Source r1 a, Source r2 b, Source r3 c, Source r4 d, Shape sh1, Shape sh2, Shape sh3, Shape sh4, Shape sh5) => 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, Source r1 a, Source 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, Source r1 a, Source r2 a, Source 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, Source r1 a, Source r2 a, Source r3 a, Source 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. -- -- Elements are reduced in the order of their indices, from lowest to -- highest. Applications of the operator are associatied arbitrarily. -- --
-- >>> let c 0 x = x; c x 0 = x; c x y = y -- -- >>> let a = fromListUnboxed (Z :. 2 :. 2) [1,2,3,4] :: Array U (Z :. Int :. Int) Int -- -- >>> foldP c 0 a -- AUnboxed (Z :. 2) (fromList [2,4]) --foldP :: (Shape sh, Source r a, Elt a, Unbox 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. -- -- Elements are reduced in the order of their indices, from lowest to -- highest. Applications of the operator are associatied arbitrarily. -- --
-- >>> let c 0 x = x; c x 0 = x; c x y = y -- -- >>> let a = fromListUnboxed (Z :. 2 :. 2) [1,2,3,4] :: Array U (Z :. Int :. Int) Int -- -- >>> foldS c 0 a -- AUnboxed (Z :. 2) (fromList [2,4]) --foldS :: (Shape sh, Source r a, Elt a, Unbox 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. -- -- Elements are reduced in row-major order. Applications of the operator -- are associated arbitrarily. foldAllP :: (Shape sh, Source r a, Elt a, Unbox 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. -- -- Elements are reduced in row-major order. Applications of the operator -- are associated arbitrarily. foldAllS :: (Shape sh, Source r a, Elt a, Unbox a) => (a -> a -> a) -> a -> Array r sh a -> a -- | Parallel sum the innermost dimension of an array. sumP :: (Shape sh, Source r a, Num a, Elt a, Unbox a, Monad m) => Array r (sh :. Int) a -> m (Array U sh a) -- | Sequential sum the innermost dimension of an array. sumS :: (Shape sh, Source r a, Num a, Elt a, Unbox a) => Array r (sh :. Int) a -> Array U sh a -- | Parallel sum all the elements of an array. sumAllP :: (Shape sh, Source r a, Elt a, Unbox a, Num a, Monad m) => Array r sh a -> m a -- | Sequential sum of all the elements of an array. sumAllS :: (Shape sh, Source r a, Elt a, Unbox a, Num a) => Array r sh a -> a -- | Check whether two arrays have the same shape and contain equal -- elements, in parallel. equalsP :: (Shape sh, Eq sh, Source r1 a, Source r2 a, Eq a, Monad m) => Array r1 sh a -> Array r2 sh a -> m Bool -- | Check whether two arrays have the same shape and contain equal -- elements, sequentially. equalsS :: (Shape sh, Eq sh, Source r1 a, Source r2 a, Eq a) => Array r1 sh a -> Array r2 sh a -> 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. -- --