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

Padding inside ufunc #447

Draft
wants to merge 4 commits into
base: grid_ufunc_refactor_project
Choose a base branch
from

Conversation

TomNicholas
Copy link
Contributor

Sketch of how we might refactor the code to pad inside the ufunc, as discussed in #443.

The idea is that all the complexity of composing the the padding operation with the desired ufunc operation is abstracted away into this Padder class, making apply_as_grid_ufunc as simple as possible to understand.

Also adds tests for the bug described in #436.

@TomNicholas TomNicholas added this to In progress in Grid ufunc refactor via automation Mar 7, 2022
Comment on lines +6 to +16
class Padder:
"""
Internal class which can pad numpy arrays, or compose a numpy ufunc with a particular padding operation.

One instance of the Padder class should be used for one padding operation, as its internals store the options chosen
for that particular use.
"""
grid: "Grid"
boundary_width: ... # TODO work out what all these types need to be
boundary: ...
fill_value: ...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbusecke I'm posting this as a WIP so you can see what I'm imagining here

Comment on lines +493 to +495
# Compose the ufunc with the padding needed to replace trimmed elements
padder = Padder(grid, boundary_width_real_axes, boundary, fill_value)
pad_then_func = padder.compose_with(func)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Means that this is all the reference to padding I need to have in apply_as_grid_ufunc

@TomNicholas TomNicholas deleted the branch xgcm:grid_ufunc_refactor_project April 20, 2022 20:57
Grid ufunc refactor automation moved this from In progress to Done Apr 20, 2022
@TomNicholas TomNicholas reopened this Apr 20, 2022
Grid ufunc refactor automation moved this from Done to In progress Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

1 participant