Creating stencils from arrays

23 views
Skip to first unread message

Rob Stewart

unread,
Apr 26, 2014, 7:30:32 AM4/26/14
to haskel...@googlegroups.com
Hi,

It appears that the two ways for creating stencils is either to use
`stencil2` using quasi quotation, or `makeStencil` with a lambda
expression:
http://hackage.haskell.org/package/repa-3.2.3.3/docs/Data-Array-Repa-Stencil-Dim2.html#v:stencil2

I'd like to create stencils at runtime from arrays, e.g. creating an array from:

AUnboxed ((Z :. 3) :. 3) (fromList [1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0])

Is there a repa function for creating stencils from arrays?

fromArray :: Num a -> Array U DIM2 a -> Stencil sh a

Thanks,

--
Rob

Ben Lippmeier

unread,
Apr 29, 2014, 7:17:06 AM4/29/14
to Rob Stewart, haskel...@googlegroups.com
No. The existing compilation process requires all coefficients to be statically known. This is described in the paper "Efficient Parallel Stencil Computation in Haskell". It would be useful to support stencils with coefficients that are only available at runtime, but I haven't implemented it.

Ben.



Rob Stewart

unread,
Apr 29, 2014, 7:32:25 AM4/29/14
to Ben Lippmeier, haskel...@googlegroups.com
Hi Ben,

I had a stab at this, which is almost certainly wrong. Is it just
slightly wrong, or wrong because it is currently not possible?

--8<---------------cut here---------------start------------->8---
{-# LANGUAGE BangPatterns,LambdaCase #-}

module StencilGen where

import Data.Array.Repa hiding ((++),map)
import Data.Array.Repa.Stencil

mkStencil :: Array U DIM2 Int -> Stencil DIM2 Int
mkStencil !template = makeStencil (Z :. 3 :. 3) values
where
normalisePixel :: Int -> Maybe Int
normalisePixel i = if i == 0 then Nothing else Just i

values =
\case
Z :. -1 :. -1 -> normalisePixel $ template ! (Z :. 0 :. 0)
Z :. -1 :. 0 -> normalisePixel $ template ! (Z :. 0 :. 1)
Z :. -1 :. 1 -> normalisePixel $ template ! (Z :. 0 :. 2)
Z :. 0 :. -1 -> normalisePixel $ template ! (Z :. 1 :. 0)
Z :. 0 :. 0 -> normalisePixel $ template ! (Z :. 1 :. 1)
Z :. 0 :. 1 -> normalisePixel $ template ! (Z :. 1 :. 2)
Z :. 1 :. -1 -> normalisePixel $ template ! (Z :. 2 :. 0)
Z :. 1 :. 0 -> normalisePixel $ template ! (Z :. 2 :. 1)
Z :. 1 :. 1 -> normalisePixel $ template ! (Z :. 2 :. 2)
_ -> Nothing
--8<---------------cut here---------------end--------------->8---

Thanks,

--
Rob
Reply all
Reply to author
Forward
0 new messages