Speed up applying the permutation in sort-axis example#930
Conversation
Speed it up by avoiding bounds checking when looking up the pane to move in the source array. This works because for any given element pointer in the array we have the relationship: .index_axis(axis, 0) + .stride_of(axis) * j == .index_axis(axis, j) where + is pointer arithmetic on the element pointers.
| // It works because for any given element pointer in the array we have the | ||
| // relationship: | ||
| // | ||
| // .index_axis(axis, 0) + .stride_of(axis) * j == .index_axis(axis, j) |
There was a problem hiding this comment.
coding style wise this is a bit ugh, since it depends on manual pointer offsetting instead of using an abstraction. Probably this would be ok as an implementation but not great as an example and that's where it is now.
There was a problem hiding this comment.
Yeah, I've never really thought this was a great example to showcase the library, although I'm not sure where else to put it. I do think it would be worth considering adding some of this functionality to ndarray itself.
There was a problem hiding this comment.
yes, of course, it's just that it needs API design to be added to ndarray
|
From the discussion we can say that this is not an example but more like a "staging area" for future features, and I'll merge this so that we have this improvement in store for when we move this over as a real feature in ndarray. It's non-obvious what the API should be IMO, and that's the reason it hasn't been included yet. |
Speed it up by avoiding bounds checking when looking up the pane to move
in the source array.
This works because for any given element pointer in the array we have the
relationship:
.index_axis(axis, 0) + .stride_of(axis) * j == .index_axis(axis, j)
where + is pointer arithmetic on the element pointers.