Repository navigation
Conversation
This was referenced Nov 20, 2026
`add!` added the raw `dy`, whereas `val` applies `ProjectTo(x)`, so `add!` failed for complex cotangents of real arrays and disagreed with `val` for mixed precision (#863). `add!` now projects `dy` onto `x[inds...]` if `ProjectTo(x)` acts elementwise and falls back to `add!!(dx, val)` otherwise. Both paths now throw a `DimensionMismatch` if `dy` does not match the slice, instead of silently broadcasting a scalar or length-1 `dy`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`eachslice(x; dims)` is not inferred, so `keep` was `Any`, and with the projected cotangent the `∇getindex` result was no longer inferred. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devmotion
force-pushed
the
dmw/getindex-add
branch
from
November 20, 2026 21:21
e44a975 to
f74495e
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #875 +/- ##
==========================================
+ Coverage 96.65% 96.77% +0.11%
==========================================
Files 28 28
Lines 3615 3625 +10
==========================================
+ Hits 3494 3508 +14
+ Misses 121 117 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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 the first part of #863. This is an alternative to #872.
In the
InplaceableThunkof thegetindex/viewrrules,add!adds the rawdy, butvalappliesProjectTo(x). As a result,add!throws for complex cotangents of real arrays and gives a different result thanvalfor mixed precision.This PR changes
add!to:dywithProjectTo(@views x[inds...])and accumulate only intodx[inds...]ifProjectTo(x)acts elementwise (arrays of numbers or arrays of arrays). The scalar case uses a 0-dim view, so it doesn't scalar-index GPU arrays.add!!(dx, ∇getindex(x, dy, inds...))otherwise, e.g. forDiagonalorSymmetric.The slice branch of
∇getindexuses the same projection. Side effects:DimensionMismatchifdydoesn't match the shape of the slice. Previously a scalar or length-1dywas broadcast silently. Trailing singleton dimensions are still accepted.unthunkno longer throws for aVector{ZeroTangent}cotangent.The scalar
OneElementpath is unchanged.Update (2026-11-20)
keepinferred in theuniquerrule.eachslice(x; dims)is not inferred, and since∇getindexnow buildsdxfrom the projected cotangent, theunique(x; dims)pullback was no longer inferred.🤖 Generated with Claude Code