Fix broadcasting for operations that are not part of AbstractOperations.operations#5649
Open
simone-silvestri wants to merge 8 commits into
Open
Fix broadcasting for operations that are not part of AbstractOperations.operations#5649simone-silvestri wants to merge 8 commits into
AbstractOperations.operations#5649simone-silvestri wants to merge 8 commits into
Conversation
…/Oceananigans.jl into ss/only-broadcast-when-abstract-op
glwagner
approved these changes
Jun 1, 2026
glwagner
reviewed
Jun 1, 2026
Comment on lines
+21
to
+25
| if Symbol(bc.f) ∈ operators | ||
| abstract_op = bc.f(loc, Tuple(broadcasted_to_abstract_operation(loc, grid, a) for a in bc.args)...) | ||
| return interpolate_operation(loc, abstract_op) # For "stubborn" BinaryOperations | ||
| else | ||
| return bc |
Member
There was a problem hiding this comment.
Doesn't this produce incorrect results?
glwagner
requested changes
Jun 1, 2026
glwagner
left a comment
Member
There was a problem hiding this comment.
I don't think its a good idea to silently allow incorrect operations
Collaborator
Author
|
what if we add a warning which explains how to deal with custom functions? if !(Symbol(bc.f) ∈ operators)
@error "$(Symbol(bc.f)) is not registered as an AbstractOperation, see @unary, @binary and @multiary [ref...] to use $(Symbol(bc.f)) in broadcasting operations"
end |
Member
I think that would be nice! We can also check whether we need interpolation. If we don't need interpolation, we can let it pass through (what I assumed would happen before I read the code) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For operations that are not registered as abstract operations, we do not want to spawn an abstract operation but just pass through the broadcast pipeline with a simple broadcast.
The example is:
The last broadcast does not work in main but works when we bypass the abstract operations pipeline.
However, I have also added
minas a@multiaryoperation (together withmax) so that it can operate correctly on multiple fields.