public
Created

  • Download Gist
gistfile1.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
slice :: (Slice sh, Shape sh, Elt a) => Int -> Int -> Array (sh :. Int) a -> Array (sh :. Int) a
slice from to array =
fromFunction (z :. (to - from + 1)) (\(z :. ix) -> array ! (z :. (ix + from)))
where (z :. _) = extent array
 
cumsum ::
(FullShape uf ~ uf,
Slice uf,
Slice (SliceShape uf),
Shape uf,
Shape (SliceShape uf),
Elt a,
Num a) =>
Array (uf :. Int) a -> Array (uf :. Int) a
cumsum array = traverse array id $ cumsum' array
where
cumsum' array f (sh :. outer) =
Repa.sumAll $
Surf.slice 0 outer $
Repa.slice array (sh :. All)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.