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

Automatic xarray broadcasting for numba-accelerated functions #98

Merged
merged 6 commits into from
Feb 17, 2025

Conversation

kmnhan
Copy link
Owner

@kmnhan kmnhan commented Feb 17, 2025

Numba functions only take pure numpy arrays as input. This PR adds a decorator for jitted functions that broadcasts input DataArrays and passes numpy arrays to the decorated function. If the returned array matches the broadcast shape, the output is converted to a DataArray with the broadcasted coordinates and attributes.

…casting

Adds a new decorator that enables passing DataArrays to functions that only accepts numpy arrays or always returns numpy arrays, like numba-accelerated functions and some scipy functions.
…ng coordinates

Adds `DataArray.qsel.average`, which takes dimension names and calls `DataArray.qsel` with the bin widths set to infinity. Unlike `DataArray.mean`, the new method retains coordinates associated with the averaged dimension.
Copy link

codecov bot commented Feb 17, 2025

Codecov Report

Attention: Patch coverage is 98.14815% with 1 line in your changes missing coverage. Please review.

Project coverage is 83.95%. Comparing base (567d989) to head (831c5bd).
Report is 9 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/erlab/utils/array.py 97.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #98      +/-   ##
==========================================
+ Coverage   83.89%   83.95%   +0.05%     
==========================================
  Files          82       82              
  Lines       14360    14401      +41     
==========================================
+ Hits        12047    12090      +43     
+ Misses       2313     2311       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kmnhan kmnhan merged commit 1e6dd5d into main Feb 17, 2025
14 checks passed
@kmnhan kmnhan deleted the dev-broadcast branch February 17, 2025 04:27
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.

1 participant