Skip to content

Improve bulk quantiles #5

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

Conversation

jturner314
Copy link

} else if i == partition_index {
self[i].clone()
} else {
self.slice_mut(s![partition_index + 1..])
self.slice_axis_mut(Axis(0), Slice::from(partition_index + 1..))
Copy link
Owner

Choose a reason for hiding this comment

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

I can see the rationale for all the changes you have proposed, but I feel I am missing something here: why is slice_axis_mut preferable to slice_mut?

Copy link
Author

@jturner314 jturner314 Apr 1, 2019

Choose a reason for hiding this comment

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

It's just slightly lower overhead, that's all. .slice_mut() goes through all the n-dimensional slicing infrastructure and in the end calls .slice_axis_inplace(); .slice_axis_mut() jumps there directly. [Edit: In theory, the compiler should be able to eliminate the extra slicing infrastructure through constant propagation and inlining, but in practice, some overhead usually remains.] The performance difference is quite small in this case (~2% in the small array tests when I tried it earlier), so if .slice_mut() seems cleaner, that's fine too.

Copy link
Owner

@LukeMathWalker LukeMathWalker Apr 2, 2019

Choose a reason for hiding this comment

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

Readibility-wise, I'd say they are the same. I was just curious to understand the rationale, your laser-focused optimization eye is something I am trying to learn from your PR reviews 😛

This is a bit cleaner.
For me, the tests are easier to understand when they don't collect
into a `Vec`.
This has a few advantages:

* It's now possible to save the interpolation strategy in a variable
  and easily re-use it.

* We can now freely add more type parameters to the `quantile*`
  methods as needed without making them more difficult to call.

* We now have the flexibility to add more advanced interpolation
  strategies in the future (e.g. one that wraps a closure).

* Calling the `quantile*` methods is now slightly more compact because
  a turbofish isn't necessary.
This is slightly more versatile because `ArrayBase` allows arbitrary
strides.
@jturner314 jturner314 changed the title Improve get_many_from_sorted_mut_unchecked Improve bulk quantiles Apr 2, 2019
@LukeMathWalker LukeMathWalker merged commit a4e8c5d into LukeMathWalker:bulk-quantiles Apr 2, 2019
@jturner314 jturner314 deleted the bulk-quantiles branch April 2, 2019 19:07
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