[Haskell-cafe] maps over arrays that provide the position index for the array and accelerate libraries?
Trevor McDonell
trevor.mcdonell at gmail.com
Tue Feb 9 17:28:55 UTC 2016
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 at 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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160209/e0c2eac3/attachment.html>
More information about the Haskell-Cafe
mailing list