Fix rrule for broadcasted over empty Tuple{}#834
Merged
ChrisRackauckas merged 4 commits intoJuliaDiff:mainfrom Feb 11, 2026
Merged
Fix rrule for broadcasted over empty Tuple{}#834ChrisRackauckas merged 4 commits intoJuliaDiff:mainfrom
ChrisRackauckas merged 4 commits intoJuliaDiff:mainfrom
Conversation
When broadcasting over an empty tuple, `Broadcast.combine_eltypes` returns
`Union{}`. Since `Union{} <: Number` is true, the code entered
`may_bc_derivatives` which tried to construct `Tuple{Union{}, ...}` and
errored. Fix by treating `Union{}` as a trivial non-differentiable case
alongside `Bool`.
Fixes JuliaDiff#830
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
devmotion
reviewed
Feb 11, 2026
Member
devmotion
left a comment
There was a problem hiding this comment.
Is it possible to also come up with an example with more arguments?
Co-authored-by: David Müller-Widmann <devmotion@users.noreply.github.com>
Co-authored-by: David Müller-Widmann <devmotion@users.noreply.github.com>
Test atan.((), ()) to cover the multi-arg path through the trivial
broadcast rrule when eltype is Union{}.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
|
How about that? |
devmotion
approved these changes
Feb 11, 2026
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.
Summary
rruleforBroadcast.broadcastedcrashing when broadcasting over an emptyTuple{}(e.g.isone.(()))argscontains an empty tuple,Broadcast.combine_eltypes(f, args)returnsUnion{}. SinceUnion{} <: Numberistrue, the code enteredmay_bc_derivativeswhich tried to constructTuple{Union{}, ...}and errored with "Tuple field type cannot be Union{}"T === Union{}as a trivial non-differentiable case alongsideT === Bool, since empty containers produce empty results with zero gradientsisoneandsinbroadcasted over()Fixes #830
Test plan
Pkg.test(; test_args=["broadcast"])) - all 2679 tests passisone,sin) over empty tuple🤖 Generated with Claude Code