robpike / ivy

ivy, an APL-like calculator
Other
1.32k stars 103 forks source link

multi-dimensional indexing question #111

Closed rsc closed 2 years ago

rsc commented 2 years ago

Originally posted by @fumin in https://github.com/robpike/ivy/issues/28#issuecomment-1120686350:

Why does (5 5 rho iota 25)[3 2; 1 2 3] return the following?

11 12
13  6
 7  8

I was expecting

11 12 13 
6 7  8

which is also what's returned by https://tryapl.org/ with the expression (5 5 ⍴ ⍳ 25)[3 2; 1 2 3].

Below is my investigation ``` (5 5 rho iota 25)[3 2; 1] 11 6 (5 5 rho iota 25)[3 2; 1 2] 11 12 6 7 (5 5 rho iota 25)[3 2; 1 2 3] 11 12 13 6 7 8 ```
rsc commented 2 years ago

Definitely a bug. Will look into a fix.

rsc commented 2 years ago

Sent #112 with a fix.

fumin commented 2 years ago

Thanks @rsc , I confirm #112 works for all the variants I can think of. It's also good to see the internals of ivy in this change in action, enlightening! : )