yarr-1.4.0.2: Yet another array library

Safe HaskellNone
LanguageHaskell98

Data.Yarr.Convolution

Contents

Synopsis

Convoluted representation

data CV Source #

Convolution fused representation internally keeps 2 element getters:

  • slow border get, which checks every index from applied stencil to lay inside extent of underlying source array.
  • fast center get, which doesn't worry about bound checks

and center Block.

Instances

Shape sh => USource CV CVL sh a Source # 

Methods

index :: UArray CV CVL sh a -> sh -> IO a Source #

linearIndex :: UArray CV CVL sh a -> Int -> IO a Source #

Shape sh => Regular CV CVL sh a Source # 

Associated Types

data UArray CV CVL sh a :: * Source #

Methods

extent :: UArray CV CVL sh a -> sh Source #

touchArray :: UArray CV CVL sh a -> IO () Source #

force :: UArray CV CVL sh a -> IO () Source #

Shape sh => DefaultFusion CV CV CVL sh Source # 

Methods

dmap :: (USource CV CVL sh a, USource CV CVL sh b) => (a -> b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

dmapM :: (USource CV CVL sh a, USource CV CVL sh b) => (a -> IO b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

dzip2 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (a -> b -> c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

dzip2M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (a -> b -> IO c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

dzip3 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (a -> b -> c -> d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

dzip3M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (a -> b -> c -> IO d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

dzip :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => Fun n a b -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

dzipM :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => Fun n a (IO b) -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

Shape sh => DefaultIFusion CV CVL CV CVL sh Source # 

Methods

imap :: (USource CV CVL sh a, USource CV CVL sh b) => (sh -> a -> b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

imapM :: (USource CV CVL sh a, USource CV CVL sh b) => (sh -> a -> IO b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

izip2 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (sh -> a -> b -> c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

izip2M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (sh -> a -> b -> IO c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

izip3 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (sh -> a -> b -> c -> d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

izip3M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (sh -> a -> b -> c -> IO d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

izip :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => (sh -> Fun n a b) -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

izipM :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => (sh -> Fun n a (IO b)) -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

Shape sh => IFusion CV CVL CV CVL sh Source # 

Methods

fimap :: (USource CV CVL sh a, USource CV CVL sh b) => (sh -> a -> b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

fimapM :: (USource CV CVL sh a, USource CV CVL sh b) => (sh -> a -> IO b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

fizip2 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (sh -> a -> b -> c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

fizip2M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (sh -> a -> b -> IO c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

fizip3 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (sh -> a -> b -> c -> d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

fizip3M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (sh -> a -> b -> c -> IO d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

fizip :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => (sh -> Fun n a b) -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

fizipM :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => (sh -> Fun n a (IO b)) -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

Shape sh => NFData (UArray CV CVL sh a) Source # 

Methods

rnf :: UArray CV CVL sh a -> () #

data UArray CV CVL Source # 
data UArray CV CVL = Convoluted {}

data CVL Source #

ConVolution Load type is specialized to load convoluted arrays.

It loads center with centerGet and borders outside the center with borderGet separately.

It is even able to distribute quite expensive border loads evenly between available threads while parallel load.

Element-wise Loading convoluted arrays wasn't inlined propely with unrolled Filling (unrolledFill, dim2BlockFill). However, with simple fill performance was OK.

For details see http://stackoverflow.com/questions/14748900/ghc-doesnt-perform-2-stage-partial-application-inlining

ALMOST SOLVED: you just need to support unrolled filling function with INLINE pragma, see https://github.com/leventov/yarr/blob/master/tests/blur.hs, ffill function.

Instances

Shape sh => PreferredWorkIndex CVL sh sh Source # 
Shape sh => USource CV CVL sh a Source # 

Methods

index :: UArray CV CVL sh a -> sh -> IO a Source #

linearIndex :: UArray CV CVL sh a -> Int -> IO a Source #

Shape sh => Regular CV CVL sh a Source # 

Associated Types

data UArray CV CVL sh a :: * Source #

Methods

extent :: UArray CV CVL sh a -> sh Source #

touchArray :: UArray CV CVL sh a -> IO () Source #

force :: UArray CV CVL sh a -> IO () Source #

Shape sh => DefaultFusion CV CV CVL sh Source # 

Methods

dmap :: (USource CV CVL sh a, USource CV CVL sh b) => (a -> b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

dmapM :: (USource CV CVL sh a, USource CV CVL sh b) => (a -> IO b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

dzip2 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (a -> b -> c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

dzip2M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (a -> b -> IO c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

dzip3 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (a -> b -> c -> d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

dzip3M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (a -> b -> c -> IO d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

dzip :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => Fun n a b -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

dzipM :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => Fun n a (IO b) -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

Shape sh => DefaultIFusion CV CVL CV CVL sh Source # 

Methods

imap :: (USource CV CVL sh a, USource CV CVL sh b) => (sh -> a -> b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

imapM :: (USource CV CVL sh a, USource CV CVL sh b) => (sh -> a -> IO b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

izip2 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (sh -> a -> b -> c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

izip2M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (sh -> a -> b -> IO c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

izip3 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (sh -> a -> b -> c -> d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

izip3M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (sh -> a -> b -> c -> IO d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

izip :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => (sh -> Fun n a b) -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

izipM :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => (sh -> Fun n a (IO b)) -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

Shape sh => IFusion CV CVL CV CVL sh Source # 

Methods

fimap :: (USource CV CVL sh a, USource CV CVL sh b) => (sh -> a -> b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

fimapM :: (USource CV CVL sh a, USource CV CVL sh b) => (sh -> a -> IO b) -> UArray CV CVL sh a -> UArray CV CVL sh b Source #

fizip2 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (sh -> a -> b -> c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

fizip2M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c) => (sh -> a -> b -> IO c) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c Source #

fizip3 :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (sh -> a -> b -> c -> d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

fizip3M :: (USource CV CVL sh a, USource CV CVL sh b, USource CV CVL sh c, USource CV CVL sh d) => (sh -> a -> b -> c -> IO d) -> UArray CV CVL sh a -> UArray CV CVL sh b -> UArray CV CVL sh c -> UArray CV CVL sh d Source #

fizip :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => (sh -> Fun n a b) -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

fizipM :: (USource CV CVL sh a, USource CV CVL sh b, Arity n, (* ~ n) (S n0)) => (sh -> Fun n a (IO b)) -> VecList n (UArray CV CVL sh a) -> UArray CV CVL sh b Source #

Shape sh => NFData (UArray CV CVL sh a) Source # 

Methods

rnf :: UArray CV CVL sh a -> () #

data UArray CV CVL Source # 
data UArray CV CVL = Convoluted {}
type LoadIndex CVL tl sh Source # 
type LoadIndex CVL tl sh = sh

justCenter :: Shape sh => UArray CV CVL sh a -> UArray D SH sh a Source #

Retreives fast center get from convoluted array and wraps it into Delayed array.

Remember that array indexing in Yarr is always zero-based, so indices in result array are shifted by top-level corner offset of given convoluted array.

There is also Convoluted UArray family constructor, which isn't presented in the docs because Haddock doesn't support associated family constructors.

See source of Data.Yarr.Convolution.Repr module.

Static stencils

Dim1 stencils

data Dim1Stencil size a b c Source #

Generalized static Dim1 stencil.

Constructors

Dim1Stencil 

Fields

dim1St :: QuasiQuoter Source #

QuasiQuoter for producing typical numeric convolving Dim1 stencil, which effectively skips unnecessary multiplications.

[dim1St| 1 4 6 4 1 |]

Produces

Dim1Stencil
    n5
    (VecList
       [\ acc a -> return (acc + a),
        \ acc a -> (return $ (acc + (4 * a))),
        \ acc a -> (return $ (acc + (6 * a))),
        \ acc a -> (return $ (acc + (4 * a))),
        \ acc a -> return (acc + a)])
    (\ acc a reduce -> reduce acc a)
    (return 0)
 

dConvolveDim1WithStaticStencil Source #

Arguments

:: (StencilOffsets s so eo, USource r l Dim1 a) 
=> Dim1Stencil s a b c

Convolution stencil

-> UArray r l Dim1 a

Source array

-> UArray CV CVL Dim1 c

Fused convolved result array

Curried version of convolveDim1WithStaticStencil with border get clamping indices out of bounds to 0 or (extent source).

convolveDim1WithStaticStencil Source #

Arguments

:: (USource r l Dim1 a, StencilOffsets s so eo) 
=> (UArray r l Dim1 a -> Dim1 -> Dim1 -> IO a)

(Source array -> Extent of this array -> Index (may be out of bounds) -> Result value): Border index (to treat indices near to bounds)

-> Dim1Stencil s a b c

Convolution stencil

-> UArray r l Dim1 a

Source array

-> UArray CV CVL Dim1 c

Fused convolved result array

Convolves Dim1 array with static stencil.

Dim2 stencils

data Dim2Stencil sx sy a b c Source #

Generalized static Dim2 stencil.

Constructors

Dim2Stencil 

Fields

dim2St :: QuasiQuoter Source #

Most useful Dim2 stencil producer.

Typing

[dim2St| 1   2   1
         0   0   0
        -1  -2  -1 |]

Results to

Dim2Stencil
 n3
 n3
 (VecList
    [VecList
       [\ acc a -> return (acc + a),
        \ acc a -> (return $ (acc + (2 * a))),
        \ acc a -> return (acc + a)],
     VecList
       [\ acc _ -> return acc,
        \ acc _ -> return acc,
        \ acc _ -> return acc],
     VecList
       [\ acc a -> return (acc - a),
        \ acc a -> (return $ (acc + (-2 * a))),
        \ acc a -> return (acc - a)]])
 (\ acc a reduce -> reducej acc a)
 (return 0)

dim2OutClamp :: USource r l Dim2 a => UArray r l Dim2 a -> Dim2 -> Dim2 -> IO a Source #

Clamps Dim2 index out of bounds to the nearest one inside bounds.

dConvolveShDim2WithStaticStencil Source #

Arguments

:: (StencilOffsets sx sox eox, StencilOffsets sy soy eoy, USource r SH Dim2 a) 
=> Dim2Stencil sx sy a b c

Convolution stencil

-> UArray r SH Dim2 a

Source array

-> UArray CV CVL Dim2 c

Fused convolved result array

Defined as dConvolveShDim2WithStaticStencil = convolveShDim2WithStaticStencil dim2OutClamp

Example:

let gradientX =
        dConvolveLinearDim2WithStaticStencil
            [dim2St| -1  0  1
                     -2  0  2
                     -1  0  1 |]
            image
 

convolveShDim2WithStaticStencil Source #

Arguments

:: (USource r SH Dim2 a, StencilOffsets sx sox eox, StencilOffsets sy soy eoy) 
=> (UArray r SH Dim2 a -> Dim2 -> Dim2 -> IO a)

(Source array -> Extent of this array -> Index (may be out of bounds) -> Result value): Border index (to treat indices near to bounds)

-> Dim2Stencil sx sy a b c

Convolution stencil

-> UArray r SH Dim2 a

Source array

-> UArray CV CVL Dim2 c

Fused convolved result array

Convolves Dim2 array with SHaped load type with static stencil.

dConvolveLinearDim2WithStaticStencil Source #

Arguments

:: (StencilOffsets sx sox eox, StencilOffsets sy soy eoy, USource r L Dim2 a) 
=> Dim2Stencil sx sy a b c

Convolution stencil

-> UArray r L Dim2 a

Source array

-> UArray CV CVL Dim2 c

Fused convolved result array

Analog of dConvolveShDim2WithStaticStencil to convolve arrays with Linear load index.

convolveLinearDim2WithStaticStencil Source #

Arguments

:: (StencilOffsets sx sox eox, StencilOffsets sy soy eoy, USource r L Dim2 a) 
=> (UArray r L Dim2 a -> Dim2 -> Dim2 -> IO a)

(Source array -> Extent of this array -> Index (may be out of bounds) -> Result value): Border index (to treat indices near to bounds)

-> Dim2Stencil sx sy a b c

Convolution stencil

-> UArray r L Dim2 a

Source array

-> UArray CV CVL Dim2 c

Fused convolved result array

Analog of convolveShDim2WithStaticStencil to convolve arrays with Linear load index.