Speed up applying the permutation in sort-axis example by bluss · Pull Request #930 · rust-ndarray/ndarray · GitHub
Skip to content

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

Merged
bluss merged 1 commit into
masterfrom
faster-sort
Mar 4, 2021
Merged

Speed up applying the permutation in sort-axis example#930
bluss merged 1 commit into
masterfrom
faster-sort

Conversation

@bluss

@bluss bluss commented Mar 3, 2021

Copy link
Copy Markdown
Member

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.
Comment thread examples/sort-axis.rs

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

bluss commented Mar 4, 2021

Copy link
Copy Markdown
Member Author

@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