Skip to content

Instantly share code, notes, and snippets.

@apriori
Created July 31, 2013 20:37
Show Gist options
  • Save apriori/6125930 to your computer and use it in GitHub Desktop.
Save apriori/6125930 to your computer and use it in GitHub Desktop.
sfold :: (Shape ix, Elt a) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Array ix a) -> Exp a
sfold f i a = let
iteratefunc :: (Elt a) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Exp a
iteratefunc !f !i !ar =
((size ar) ==* 0) ? (i,
let
hd = A.take (constant 1) ar A.!! 0
tl = A.tail ar
in
f hd (iteratefunc f i tl))
in
iteratefunc f i (flatten a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment