Slide 109
Slide 109 text
Stencils
• A stencil is a map with access to the neighbourhood around each element
- Useful in many scientific & image processing algorithms
- Boundary conditions specify how to handle out-of-bounds neighbours
laplace%::%Stencil3x3%Int%,>%Exp%Int%
laplace%((_,t,_)%
%%%%%%%%,(l,c,r)%
%%%%%%%%,(_,b,_))%=%t%+%b%+%l%+%r%,%4*c
>%let%mat%=%fromList%(Z:.3:.5)%[1..]%::%Array%DIM2%Int%
>%run%$%stencil%laplace%(Constant%0)%(use%mat)%
Array%(Z%:.%3%:.%5)%[4,3,2,1,,6,,5,0,0,0,,11,,26,,17,,18,,19,,36]
t
l c r
b