This will do it.

imap :: (Shape ix, Elt a, Elt b)
     => (Exp ix -> Exp a -> Exp b)
     -> Acc (Array ix a)
     -> Acc (Array ix b)
imap f xs = A.zipWith f (A.generate (shape xs) id) xs


I'll add this and similar functions for zipWithN to the Accelerate prelude.


Cheers,
-Trev


On Tue, 9 Feb 2016 at 06:26 Rob Stewart <robstewart57@gmail.com> wrote:
In vector library there's this useful function:

imap :: (Int -> a -> b) -> Vector a -> Vector b

And in Data.Map there's this similar function:

mapWithKey :: (k -> a -> b) -> Map k a -> Map k b

I'm looking for something similar in the array and accelerate libraries, i.e.

On arrays in Data.Array.IArray:

imap :: (IArray a e, IArray a e', Ix i) => (i -> e -> e') -> a i e -> a i e'

And on Accelerate arrays:

imap :: (Shape ix, Elt a, Elt b) => (Exp ix -> Exp a -> Exp b) -> Acc
(Array ix a) -> Acc (Array ix b)

Is anyone aware of such map implementations for arrays in the array
and accelerate libraries, that provide your mapped function not only
the element at a position, but also the index at that position?

Thanks,

--
Rob
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe