<div dir="ltr"><div>This will do it.</div><div><br></div><div><div>imap :: (Shape ix, Elt a, Elt b)</div><div> => (Exp ix -> Exp a -> Exp b)</div><div> -> Acc (Array ix a)</div><div> -> Acc (Array ix b)</div><div>imap f xs = A.zipWith f (A.generate (shape xs) id) xs</div></div><div><br></div><div><br></div><div>I'll add this and similar functions for zipWithN to the Accelerate prelude.</div><div><br></div><div><br></div><div>Cheers,</div><div>-Trev</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, 9 Feb 2016 at 06:26 Rob Stewart <<a href="mailto:robstewart57@gmail.com">robstewart57@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In vector library there's this useful function:<br>
<br>
imap :: (Int -> a -> b) -> Vector a -> Vector b<br>
<br>
And in Data.Map there's this similar function:<br>
<br>
mapWithKey :: (k -> a -> b) -> Map k a -> Map k b<br>
<br>
I'm looking for something similar in the array and accelerate libraries, i.e.<br>
<br>
On arrays in Data.Array.IArray:<br>
<br>
imap :: (IArray a e, IArray a e', Ix i) => (i -> e -> e') -> a i e -> a i e'<br>
<br>
And on Accelerate arrays:<br>
<br>
imap :: (Shape ix, Elt a, Elt b) => (Exp ix -> Exp a -> Exp b) -> Acc<br>
(Array ix a) -> Acc (Array ix b)<br>
<br>
Is anyone aware of such map implementations for arrays in the array<br>
and accelerate libraries, that provide your mapped function not only<br>
the element at a position, but also the index at that position?<br>
<br>
Thanks,<br>
<br>
--<br>
Rob<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div>