Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nneitzke
Created June 5, 2011 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nneitzke/1009061 to your computer and use it in GitHub Desktop.
Save nneitzke/1009061 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment