Reshaping arrays in accelerate

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Reshaping arrays in accelerate

Lana Black
Hello cafe,

Is there a generic way to reshape an array in accelerate[1] 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.

[1]: https://hackage.haskell.org/package/accelerate-1.2.0.1/
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Reshaping arrays in accelerate

Trevor McDonell
Hi Lana,

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)

  in

  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: https://github.com/AccelerateHS/accelerate/issues

Cheers,
-Trev


On Wed, 26 Jun 2019 at 13:25, Lana Black <[hidden email]> wrote:
Hello cafe,

Is there a generic way to reshape an array in accelerate[1] 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.

[1]: https://hackage.haskell.org/package/accelerate-1.2.0.1/
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.