repa-2.0.2.1: High performance, regular, shape polymorphic parallel arrays.

Data.Array.Repa.Stencil

Contents

Description

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.

Synopsis

Documentation

data Stencil sh a Source

Represents a convolution stencil that we can apply to array. Only statically known stencils are supported right now.

Constructors

StencilStatic

Static stencils are used when the coefficients are fixed, and known at compile time.

Fields

stencilExtent :: !sh
 
stencilZero :: !a
 
stencilAcc :: !(sh -> a -> a -> a)
 

data Boundary a Source

How to handle the case when the stencil lies partly outside the array.

Constructors

BoundConst a

Treat points outside as having a constant value.

BoundClamp

Clamp points outside to the same value as the edge pixel.

Instances

Show a => Show (Boundary a) 

Stencil creation.

makeStencilSource

Arguments

:: (Elt a, Num a) 
=> sh

Extent of stencil.

-> (sh -> Maybe a)

Get the coefficient at this index.

-> Stencil sh a 

Make a stencil from a function yielding coefficients at each index.

makeStencil2Source

Arguments

:: (Elt a, Num a) 
=> Int 
-> Int

extent of stencil

-> (DIM2 -> Maybe a)

Get the coefficient at this index.

-> Stencil DIM2 a 

Wrapper for makeStencil that requires a DIM2 stencil.

Stencil operators.

mapStencil2 :: Elt a => Boundary a -> Stencil DIM2 a -> Array DIM2 a -> Array DIM2 aSource

Apply a stencil to every element of a 2D array. The array must be manifest else error.

forStencil2 :: Elt a => Boundary a -> Array DIM2 a -> Stencil DIM2 a -> Array DIM2 aSource

Like mapStencil2 but with the parameters flipped.

mapStencilFrom2Source

Arguments

:: (Elt a, Elt b) 
=> Boundary a

How to handle the boundary of the array.

-> Stencil DIM2 a

Stencil to apply.

-> Array DIM2 b

Array to apply stencil to.

-> (b -> a)

Apply this function to values read from the array before transforming them with the stencil.

-> Array DIM2 a 

Apply a stencil to every element of a 2D array. The array must be manifest else error.

forStencilFrom2 :: (Elt a, Elt b) => Boundary a -> Array DIM2 b -> (b -> a) -> Stencil DIM2 a -> Array DIM2 aSource

Like mapStencilFrom2 but with the parameters flipped.

stencil2 :: QuasiQuoterSource

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)