Repository navigation
Fix sum of tracked reals in Turing - #173
Merged
Merged
Conversation
devmotion
reviewed
Apr 11, 2021
Codecov Report
@@ Coverage Diff @@
## master #173 +/- ##
=========================================
Coverage ? 84.52%
=========================================
Files ? 18
Lines ? 1725
Branches ? 0
=========================================
Hits ? 1458
Misses ? 267
Partials ? 0
Continue to review full report at Codecov.
|
Member
|
Looks like this caused a downstream test failure? |
ChrisRackauckas
added a commit
that referenced
this pull request
May 13, 2021
This reverts commit e0f515c.
mohdibntarek
pushed a commit
that referenced
this pull request
May 13, 2021
devmotion
added a commit
that referenced
this pull request
Sep 22, 2026
…, and pin #126 (#302) * Test indexing a zero-dimensional `TrackedArray` (#126) `gradient(x -> x[], fill(1.0))` threw a `MethodError` for an ambiguity between the `AbstractRange...` and `Colon...` methods of `getindex`: a bare vararg matches zero arguments, so `t[]` matched both equally. 4a50321 fixed it incidentally while fixing #202, by rewriting every `getindex(t::TrackedArray, i::T...)` as `i1::T, is::T...`. Requiring a leading index sends `t[]` down `Base`'s generic zero-index `AbstractArray` path, which lands on the `Integer` method via linear indexing -- so, like any scalar `getindex`, it aliases its parent through the origin and records nothing. Nothing pinned that, and the ambiguity would come back unnoticed with any future widening of those signatures. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Give tracked reals with a free origin a `zero` and a `one` (fixes #172) `map`ping over a tracked array mixes elements that carry an origin with ones that do not, and the resulting eltype leaves the origin free. `reducedim_init` allocates a reduction's accumulator by asking that eltype for its `zero`, or `one` for `prod`, which fell through to `convert(T, 0)` and then to `valtype`, defined only for a pinned origin: MethodError: no method matching valtype(::Type{TrackedReal{Float64, Float64}}) Neither identity depends on the origin, so both are deducible from the type alone, as `zero` requires. `Nothing` is the origin `zero` has always used, and `TrackedReal{V,D,Nothing}` is an instance of `TrackedReal{V,D}`, so the documented `zero(T) isa T` holds. The signature matches that type exactly rather than its subtypes: a `Union` of two origins is also a subtype, and no single member of it could be returned. The `zero` method is the one #173 added and #177 reverted wholesale over #175, whose cause -- `increment_deriv!` indexing into untracked elements -- was fixed by #300. `one` is its counterpart, which #173 never added. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.
This PR fixes TuringLang/Turing.jl#1573. I still need to add a reduced test.