Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused by traverse #57

Closed
kozross opened this issue Nov 27, 2018 · 1 comment
Closed

Confused by traverse #57

kozross opened this issue Nov 27, 2018 · 1 comment
Labels

Comments

@kozross
Copy link

kozross commented Nov 27, 2018

I'm not sure I understand how this function would actually be used. I vaguely get that this is designed to be a version of makeArray that's augmented by having access to another auxiliary array that it can make use of, but I have no idea how you are meant to make use of that array. I'm particularly confused by the second argument. Would you be able to explain, or perhaps give an example?

@lehins
Copy link
Owner

lehins commented Nov 27, 2018

This sort of questions aren't meant to be submitted as github issues. There is gitter and of course stackoverflow. See a similar answer I made on another ticket: #46 (comment) I'll still answer it though.

traverse in massiv was inspired by traverse function in Repa library, with a slight modification. Here is an example of how to write transpose with it:

λ> arr = makeArrayR P Seq (5 :. 4) (toLinearIndex (5 :. 4))
λ> arr
(Array P Seq (5 :. 4)
  [ [ 0,1,2,3 ]
  , [ 4,5,6,7 ]
  , [ 8,9,10,11 ]
  , [ 12,13,14,15 ]
  , [ 16,17,18,19 ]
  ])
λ> traverse (4 :. 5) (\ f (i :. j) -> f (j :. i)) arr
(Array D Seq (4 :. 5)
  [ [ 0,4,8,12,16 ]
  , [ 1,5,9,13,17 ]
  , [ 2,6,10,14,18 ]
  , [ 3,7,11,15,19 ]
  ])

With all honesty this function brings more confusion than usefulness, so if you still don't get it, don't worry about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants