Perform an arbitrary transformation of a stencil. This stencil
modifier can be used for example to turn a vector stencil into a
matrix stencil implement, or transpose a matrix stencil. It is really
easy to get this wrong, so be extremely careful.
Examples
Convert a 1D stencil into a row or column 2D stencil:
>>> import Data.Massiv.Array
>>> import Data.Massiv.Array.Unsafe
>>> let arr = compute $ iterateN 3 succ 0 :: Array P Ix2 Int
>>> arr
Array P Seq (Sz (3 :. 3))
[ [ 1, 2, 3 ]
, [ 4, 5, 6 ]
, [ 7, 8, 9 ]
]
>>> let rowStencil = unsafeTransformStencil (\(Sz n) -> Sz (1 :. n)) (0 :.) $ \ f uget getVal (i :. j) -> f (uget . (i :.)) (getVal . (i :.)) j
>>> applyStencil noPadding (rowStencil (sumStencil (Sz1 3))) arr
Array DW Seq (Sz (3 :. 1))
[ [ 6 ]
, [ 15 ]
, [ 24 ]
]
>>> let columnStencil = unsafeTransformStencil (\(Sz n) -> Sz (n :. 1)) (:. 0) $ \ f uget getVal (i :. j) -> f (uget . (:. j)) (getVal . (:. j)) i
>>> applyStencil noPadding (columnStencil (sumStencil (Sz1 3))) arr
Array DW Seq (Sz (1 :. 3))
[ [ 12, 15, 18 ]
]