Skip to content

Instantly share code, notes, and snippets.

@apriori
Created July 31, 2013 21:46
Show Gist options
  • Save apriori/6126483 to your computer and use it in GitHub Desktop.
Save apriori/6126483 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 -> Exp a) -> Exp a -> Acc (Vector a) -> Exp a
iteratefunc f f' i ar =
((size ar) ==* 0) ? (f' i,
let
hd = A.take (constant 1) ar A.!! 0
tl = A.tail ar
in
iteratefunc f (f' . f hd) i tl)
in
iteratefunc f id i (flatten a)
main :: IO ()
main = do
let
ar = fromList (Z :. 15) [1..] :: Vector Int
expression = I.run $ unit $ sfold (+) (constant 0) (use ar)
putStrLn $ show expression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment