[Haskell-cafe] Reshaping arrays in accelerate
trevor.mcdonell at gmail.com
Thu Jun 27 14:35:38 UTC 2019
The `reshape` operation in Accelerate just changes the extent of an array
without changing the underlying data.
But, for example, the following will select only the the given (by index)
rows of a matrix:
selectRows :: Elt e => Acc (Vector Int) -> Acc (Matrix e) -> Acc (Matrix e)
selectRows rs xs =
let Z :. rows = unlift (shape rs)
cols = indexHead (shape xs)
generate (index2 rows cols) (\ix -> let Z :. r :. c = unlift ix
in xs ! index2 (rs!!r) c)
We could generalise this to other dimensions as well; I'd probably use
lenses for that.
I'm not really sure if this fits what you're looking for, so I'd be
interested to hear more about what you're trying to achieve. In general I'm
happy to add common utility functions like this to the API; you're welcome
to make feature requests via the GitHub issue tracker as well:
On Wed, 26 Jun 2019 at 13:25, Lana Black <lanablack at amok.cc> wrote:
> Hello cafe,
> Is there a generic way to reshape an array in accelerate assuming the
> number of dimensions remains constant? For example, given a matrix, is
> there a way to add or, more importantly, remove several rows or columns?
> It seems to me that the API is lacking in this case, but I hope I'm wrong.
> Thank you.
> : https://hackage.haskell.org/package/accelerate-188.8.131.52/
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe