Skip to content
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

Refactor reduce module; improve performance for mode, median #270

Merged
merged 4 commits into from
Aug 6, 2024

Conversation

Huite
Copy link
Collaborator

@Huite Huite commented Aug 5, 2024

  • Simplify methods by just giving a contiguous values array instead of source and indices
  • Provide a pre-allocated workspace to avoid dynamic allocation in reduce functions
  • Add a generalized percentile function

Fixes #240

* Simplify methods by just giving a contiguous values array instead of source and indices
* Provide a pre-allocated workspace to avoid dynamic allocation in reduce functions
* Add a generalized percentile function
@Huite Huite requested a review from JoerivanEngelen August 5, 2024 20:16
Copy link
Contributor

@JoerivanEngelen JoerivanEngelen left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes. I have some small suggestions but no major things. Approving in advance.

return values, weights, work


def reverse_args():
Copy link
Contributor

Choose a reason for hiding this comment

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

To remove some duplicate code and show the precise difference between forward and reverse args, you can simplify this function to:

Suggested change
def reverse_args():
def reverse_args():
values, weights, work = forward_args()
return np.flip(values), weights, work

(FYI: I wasn't allowed by Github to put a multi-line suggestion here, as some lines are deleted. Therefore put the suggestion just on the function definition line).

@@ -0,0 +1,97 @@
"""
Numba percentile methods allocate continuosly on the heap.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Numba percentile methods allocate continuosly on the heap.
Numba percentile methods allocate continuously on the heap.

Comment on lines 468 to 473
Examples
--------
Setup a custom percentile method and apply it:

>>> p33_3 = OverlapRegridder.create_percentile_method(33.3)
>>> regridder = OverlapRegridder(source, target, method=p33_3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Good that you are adding an example of the percentiles. I think most users are just looking for the simple use case, so for them it is better to start with the simplest example. And perhaps also guide them to what is the most important method to call (regrid)?

Suggested change
Examples
--------
Setup a custom percentile method and apply it:
>>> p33_3 = OverlapRegridder.create_percentile_method(33.3)
>>> regridder = OverlapRegridder(source, target, method=p33_3)
Examples
--------
Create an OverlapRegridder to regrid with means:
>>> regridder = OverlapRegridder(source_grid, target_grid, method="mean")
>>> regridder.regrid(source_data)
Setup a custom percentile method and apply it:
>>> p33_3 = OverlapRegridder.create_percentile_method(33.3)
>>> regridder = OverlapRegridder(source_grid, target_grid, method=p33_3)

@Huite Huite merged commit 5964770 into main Aug 6, 2024
14 checks passed
@Huite Huite deleted the regridder-reduction branch August 6, 2024 09:34
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.

Performance median method regridder worse than other methods
2 participants