Skip to content

Speed up applying the permutation in sort-axis example #930

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

Merged
merged 1 commit into from
Mar 4, 2021
Merged

Conversation

bluss
Copy link
Member

@bluss bluss commented Mar 3, 2021

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.

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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, of course, it's just that it needs API design to be added to ndarray

@bluss
Copy link
Member Author

bluss commented Mar 4, 2021

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.

@bluss bluss merged commit cef3901 into master Mar 4, 2021
@bluss bluss deleted the faster-sort branch March 4, 2021 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants