-- 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 2.0.0.4 -- | 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 -- | 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 instance Show Z instance Eq Z instance Ord Z instance (Show tail, Show head) => Show (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 module Data.Array.Repa.Arbitrary -- | Generate an aribrary shape that does not have 0's for any component. arbitraryShape :: (Shape sh, Arbitrary sh) => Gen (sh :. Int) -- | Generate an arbitrary shape where each dimension is more than zero, -- but less than a specific value. arbitrarySmallShape :: (Shape sh, Arbitrary sh) => Int -> Gen (sh :. Int) arbitraryListOfLength :: Arbitrary a => Int -> Gen [a] -- | Create an arbitrary small array, restricting the size of each of the -- dimensions to some value. arbitrarySmallArray :: (Shape sh, Elt a, Arbitrary sh, Arbitrary a) => Int -> Gen (Array (sh :. Int) a) instance (Shape sh, Arbitrary sh) => Arbitrary (sh :. Int) instance Arbitrary Z -- | See the repa-examples package for examples. -- -- More information at http://repa.ouroborus.net. -- -- There is a draft tutorial at -- http://www.haskell.org/haskellwiki/Numeric_Haskell:_A_Repa_Tutorial module Data.Array.Repa -- | Element types that can be stored in Repa arrays. class (Show a, Unbox a) => Elt a touch :: Elt a => a -> IO () zero :: Elt a => a one :: Elt a => a -- | Repa arrays. data Array sh a Array :: sh -> [Region sh a] -> Array sh a -- | The entire extent of the array. arrayExtent :: Array sh a -> sh -- | Arrays can be partitioned into several regions. arrayRegions :: Array sh a -> [Region sh a] -- | Defines the values in a region of the array. data Region sh a Region :: Range sh -> Generator sh a -> Region sh a -- | The range of elements this region applies to. regionRange :: Region sh a -> Range sh -- | How to compute the array elements in this region. regionGenerator :: Region sh a -> Generator sh a -- | Represents a range of elements in the array. data Range sh -- | Covers the entire array. RangeAll :: Range sh -- | The union of a possibly disjoint set of rectangles. RangeRects :: (sh -> Bool) -> [Rect sh] -> Range sh rangeMatch :: Range sh -> sh -> Bool rangeRects :: Range sh -> [Rect sh] -- | A rectangle/cube of arbitrary dimension. The indices are of the -- minimum and maximim elements to fill. data Rect sh Rect :: sh -> sh -> Rect sh -- | Generates array elements for a particular region in the array. data Generator sh a -- | Elements are already computed and sitting in this vector. GenManifest :: !Vector a -> Generator sh a -- | Elements can be computed using these cursor functions. GenCursor :: (sh -> cursor) -> (sh -> cursor -> cursor) -> (cursor -> a) -> Generator sh a -- | Make a cursor to a particular element. genMakeCursor :: Generator sh a -> sh -> cursor -- | Shift the cursor by an offset, to get to another element. genShiftCursor :: Generator sh a -> sh -> cursor -> cursor -- | Load/compute the element at the given cursor. genLoadElem :: Generator sh a -> cursor -> a -- | Ensure the structure for an array is fully evaluated. As we are in a -- lazy language, applying the force function to a delayed array -- doesn't actually compute it at that point. Rather, Haskell builds a -- suspension representing the appliction of the force function -- to that array. Use deepSeqArray to ensure the array is -- actually computed at a particular point in the program. deepSeqArray :: Shape sh => Array sh a -> b -> b -- | Like deepSeqArray but seqs all the arrays in a list. This is -- specialised up to lists of 4 arrays. Using more in the list will break -- fusion. deepSeqArrays :: Shape sh => [Array sh a] -> b -> b -- | Wrap a scalar into a singleton array. singleton :: Elt a => a -> Array Z a -- | Take the scalar value from a singleton array. toScalar :: Elt a => Array Z a -> a -- | Take the extent of an array. extent :: Array sh a -> sh -- | Unpack an array into delayed form. delay :: (Shape sh, Elt a) => Array sh a -> (sh, sh -> a) -- | Force an array before passing it to a function. withManifest :: (Shape sh, Elt a) => (Array sh a -> b) -> Array sh a -> b -- | Force an array before passing it to a function. withManifest' :: (Shape sh, Elt a) => Array sh a -> (Array sh a -> b) -> b (!) :: (Shape sh, Elt a) => Array sh a -> sh -> a -- | Get an indexed element from an array. This uses the same level of -- bounds checking as your Data.Vector installation. index :: (Shape sh, Elt a) => Array sh a -> sh -> a (!?) :: (Shape sh, Elt a) => Array sh a -> sh -> Maybe a -- | Get an indexed element from an array. If the element is out of range -- then Nothing. safeIndex :: (Shape sh, Elt a) => Array sh a -> sh -> Maybe a -- | Get an indexed element from an array, without bounds checking. This -- assumes that the regions in the array give full coverage. An array -- with no regions gets zero for every element. unsafeIndex :: (Shape sh, Elt a) => Array sh a -> sh -> a -- | Create a Delayed array from a function. fromFunction :: Shape sh => sh -> (sh -> a) -> Array sh a -- | Create a Manifest array from an unboxed Vector. The -- elements are in row-major order. fromVector :: Shape sh => sh -> Vector a -> Array sh a -- | Convert a list to an array. The length of the list must be exactly the -- size of the extent given, else error. fromList :: (Shape sh, Elt a) => sh -> [a] -> Array sh a -- | Force an array, so that it becomes Manifest. The array is -- split into linear chunks and each chunk evaluated in parallel. force :: (Shape sh, Elt a) => Array sh a -> Array sh a -- | Force an array, so that it becomes Manifest. This forcing -- function is specialised for DIM2 arrays, and does blockwise filling. force2 :: Elt a => Array DIM2 a -> Array DIM2 a -- | Convert an array to an unboxed Data.Vector, forcing it if -- required. The elements come out in row-major order. toVector :: (Shape sh, Elt a) => Array sh a -> Vector a -- | Convert an array to a list, forcing it if required. toList :: (Shape sh, Elt a) => Array sh a -> [a] -- | Impose a new shape on the elements of an array. The new extent must be -- the same size as the original, else error. -- -- TODO: This only works for arrays with a single region. reshape :: (Shape sh, Shape sh', Elt a) => sh' -> Array sh a -> Array sh' a append :: (Shape sh, Elt a) => Array (sh :. Int) a -> Array (sh :. Int) a -> Array (sh :. Int) a -- | Append two arrays. (++) :: (Shape sh, Elt a) => Array (sh :. Int) a -> Array (sh :. Int) a -> Array (sh :. Int) a -- | Transpose the lowest two dimensions of an array. Transposing an array -- twice yields the original. transpose :: (Shape sh, Elt a) => Array ((sh :. Int) :. Int) a -> Array ((sh :. Int) :. Int) a -- | Extend an array, according to a given slice specification. (used to be -- called replicate). extend :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl), Elt e) => sl -> Array (SliceShape sl) e -> Array (FullShape sl) e -- | Take a slice from an array, according to a given specification. slice :: (Slice sl, Shape (FullShape sl), Shape (SliceShape sl), Elt e) => Array (FullShape sl) e -> sl -> Array (SliceShape sl) e -- | Backwards permutation of an array's elements. The result array has the -- same extent as the original. backpermute :: (Shape sh, Shape sh', Elt a) => sh' -> (sh' -> sh) -> Array sh a -> Array sh' a -- | 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 sh, Shape sh', Elt a) => Array sh' a -> (sh' -> Maybe sh) -> Array sh a -> Array sh' a -- | Apply a worker function to each element of an array, yielding a new -- array with the same extent. -- -- This is specialised for arrays of up to four regions, using more -- breaks fusion. map :: (Shape sh, Elt a, Elt b) => (a -> b) -> Array sh a -> Array 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, Elt a, Elt b, Elt c) => (a -> b -> c) -> Array sh a -> Array sh b -> Array sh c (+^) :: (Shape sh, Elt c, Num c) => Array sh c -> Array sh c -> Array sh c (-^) :: (Shape sh, Elt c, Num c) => Array sh c -> Array sh c -> Array sh c (*^) :: (Shape sh, Elt c, Num c) => Array sh c -> Array sh c -> Array sh c (/^) :: (Shape sh, Elt c, Fractional c) => Array sh c -> Array sh c -> Array sh c -- | Sequentially fold the innermost dimension of an array. Combine this -- with transpose to fold any other dimension. fold :: (Shape sh, Elt a) => (a -> a -> a) -> a -> Array (sh :. Int) a -> Array sh a -- | Sequentially fold all the elements of an array. foldAll :: (Shape sh, Elt a) => (a -> a -> a) -> a -> Array sh a -> a -- | Sum the innermost dimension of an array. sum :: (Shape sh, Elt a, Num a) => Array (sh :. Int) a -> Array sh a -- | Sum all the elements of an array. sumAll :: (Shape sh, Elt a, Num a) => Array sh a -> a -- | Unstructured traversal. traverse :: (Shape sh, Shape sh', Elt a) => Array sh a -> (sh -> sh') -> ((sh -> a) -> sh' -> b) -> Array sh' b traverse2 :: (Shape sh, Shape sh', Shape sh'', Elt a, Elt b, Elt c) => Array sh a -> Array sh' b -> (sh -> sh' -> sh'') -> ((sh -> a) -> (sh' -> b) -> (sh'' -> c)) -> Array sh'' c traverse3 :: (Shape sh1, Shape sh2, Shape sh3, Shape sh4, Elt a, Elt b, Elt c, Elt d) => Array sh1 a -> Array sh2 b -> Array sh3 c -> (sh1 -> sh2 -> sh3 -> sh4) -> ((sh1 -> a) -> (sh2 -> b) -> (sh3 -> c) -> sh4 -> d) -> Array sh4 d traverse4 :: (Shape sh1, Shape sh2, Shape sh3, Shape sh4, Shape sh5, Elt a, Elt b, Elt c, Elt d, Elt e) => Array sh1 a -> Array sh2 b -> Array sh3 c -> Array sh4 d -> (sh1 -> sh2 -> sh3 -> sh4 -> sh5) -> ((sh1 -> a) -> (sh2 -> b) -> (sh3 -> c) -> (sh4 -> d) -> sh5 -> e) -> Array sh5 e unsafeTraverse :: (Shape sh1, Shape sh, Elt a1) => Array sh1 a1 -> (sh1 -> sh) -> ((sh1 -> a1) -> sh -> a) -> Array sh a -- | Unstructured traversal over two arrays at once. unsafeTraverse2 :: (Shape sh, Shape sh', Shape sh'', Elt a, Elt b, Elt c) => Array sh a -> Array sh' b -> (sh -> sh' -> sh'') -> ((sh -> a) -> (sh' -> b) -> (sh'' -> c)) -> Array sh'' c -- | Unstructured traversal over three arrays at once. unsafeTraverse3 :: (Shape sh1, Shape sh2, Shape sh3, Shape sh4, Elt a, Elt b, Elt c, Elt d) => Array sh1 a -> Array sh2 b -> Array sh3 c -> (sh1 -> sh2 -> sh3 -> sh4) -> ((sh1 -> a) -> (sh2 -> b) -> (sh3 -> c) -> sh4 -> d) -> Array sh4 d -- | Unstructured traversal over four arrays at once. unsafeTraverse4 :: (Shape sh1, Shape sh2, Shape sh3, Shape sh4, Shape sh5, Elt a, Elt b, Elt c, Elt d, Elt e) => Array sh1 a -> Array sh2 b -> Array sh3 c -> Array sh4 d -> (sh1 -> sh2 -> sh3 -> sh4 -> sh5) -> ((sh1 -> a) -> (sh2 -> b) -> (sh3 -> c) -> (sh4 -> d) -> sh5 -> e) -> Array sh5 e -- | Interleave the elements of two arrays. All the input arrays must have -- the same extent, else error. The lowest dimenion 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, Elt a) => Array (sh :. Int) a -> Array (sh :. Int) a -> Array (sh :. Int) a -- | Interleave the elements of three arrays. interleave3 :: (Shape sh, Elt a) => Array (sh :. Int) a -> Array (sh :. Int) a -> Array (sh :. Int) a -> Array (sh :. Int) a -- | Interleave the elements of four arrays. interleave4 :: (Shape sh, Elt a) => Array (sh :. Int) a -> Array (sh :. Int) a -> Array (sh :. Int) a -> Array (sh :. Int) a -> Array (sh :. Int) a -- | 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. select :: Elt a => (Int -> Bool) -> (Int -> a) -> Int -> Array DIM1 a instance (Shape sh, Elt a, Num a) => Num (Array sh a) instance (Shape sh, Elt a, Eq a) => Eq (Array sh a) instance (Shape sh, Elt a, Show a) => Show (Array sh a) -- | 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 given two generators, one to produce -- elements in the border region, and one to produce values in the -- internal region. The border must be the same width on all sides. makeBordered2 :: Elt a => DIM2 -> Int -> Generator DIM2 a -> Generator DIM2 a -> Array DIM2 a -- | Efficient computation of stencil based convolutions. -- -- This is specialised for stencils up to 7x7. Due to limitations in the -- GHC optimiser, using larger stencils doesn't work, and will yield -- error at runtime. We can probably increase the limit if -- required -- just ask. -- -- The focus of the stencil is in the center of the 7x7 tile, which has -- coordinates (0, 0). All coefficients in the stencil must fit in the -- tile, so they can be given X,Y coordinates up to +/- 3 positions. The -- stencil can be any shape, and need not be symmetric -- provided it -- fits in the 7x7 tile. 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 :: (Elt a, Num a) => sh -> (sh -> Maybe a) -> Stencil sh a -- | Wrapper for makeStencil that requires a DIM2 stencil. makeStencil2 :: (Elt a, Num a) => Int -> Int -> (DIM2 -> Maybe a) -> Stencil DIM2 a -- | Apply a stencil to every element of a 2D array. The array must be -- manifest else error. mapStencil2 :: Elt a => Boundary a -> Stencil DIM2 a -> Array DIM2 a -> Array DIM2 a -- | Like mapStencil2 but with the parameters flipped. forStencil2 :: Elt a => Boundary a -> Array DIM2 a -> Stencil DIM2 a -> Array DIM2 a -- | Apply a stencil to every element of a 2D array. The array must be -- manifest else error. mapStencilFrom2 :: (Elt a, Elt b) => Boundary a -> Stencil DIM2 a -> Array DIM2 b -> (b -> a) -> Array DIM2 a -- | Like mapStencilFrom2 but with the parameters flipped. forStencilFrom2 :: (Elt a, Elt b) => Boundary a -> Array DIM2 b -> (b -> a) -> Stencil DIM2 a -> Array 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 module Data.Array.Repa.Properties -- | QuickCheck properties for Data.Array.Repa.Index. props_DataArrayRepaIndex :: [(String, Property)] -- | QuickCheck properties for Data.Array.Repa and its children. props_DataArrayRepa :: [(String, Property)]