[Haskell-cafe] maps over arrays that provide the position index for the array and accelerate libraries?
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.
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,
> On arrays in Data.Array.IArray:
> imap :: (IArray a e, IArray a e', Ix i) => (i -> e -> e') -> a i e -> a i
> 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?
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe