Repository navigation
Don't claim arrays with a Union{} element type for TrackedStyle - #325
Merged
Merged
Conversation
`Union{} <: TrackedReal`, so the covariant `BroadcastStyle` rule from #301 also claimed
e.g. `Vector{Union{}}`, and broadcasting over it errored in `getouttype` once ReverseDiff
was loaded. List the element types explicitly with invariant parameters instead, which
`Union{}` cannot match, and guard `getouttype` against a `Union{}` array that reaches a
tracked broadcast next to a tracked argument.
Fixes #324
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #325 +/- ##
==========================================
+ Coverage 94.27% 94.29% +0.01%
==========================================
Files 19 19
Lines 1695 1699 +4
==========================================
+ Hits 1598 1602 +4
Misses 97 97 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #324.
Union{} <: TrackedReal, so the covariant ruleBroadcastStyle(::Type{<:AbstractArray{<:TrackedReal{<:Any, D}, N}})from #301 also matched e.g.Vector{Union{}}. That is type piracy, and once ReverseDiff was loaded,String.(Union{}[])errored ingetouttypebecauseDwas unbound.Changes
BroadcastStylelists the element types explicitly, with invariant parameters:TrackedReal{V, D, O}, withOfree, withV <: Realfree, and with both free.Union{}cannot match an invariant parameter, so noUnion{}method is needed. A freeVhas to carry its boundV <: Realto equal the element types that e.g.typejoinbuilds.getouttypestays covariant and gets a guard,getouttype(::AbstractArray{Union{}}) = Union{}. AUnion{}array can still reach a tracked broadcast next to a tracked argument, e.g.x .+ Union{}[].Behaviour
TrackedArray, itsAdjoint/SubArray/reshape, arrays ofTrackedRealthat fixD, and static arrays, whose own style still wins.Unionof differentTrackedReals, or that carry odd bounds likeTrackedReal{<:Float64, …}. As in 1.18.5, they broadcast with the scalar rules, so the derivatives are the same but the result is anArray{<:TrackedReal}.🤖 Generated with Claude Code