Repository navigation
Give each element of a PartialArray its own skeleton - #1542
Merged
Merged
Conversation
skeleton of a PartialArray whose element type is concrete filled every element with the skeleton of the first element that is set. Elements that hold arrays of different sizes then got skeletons of the wrong size, so rebuilding a VarNamedTuple from the skeleton threw a BoundsError or gave arrays of the wrong size. Each element that is set now gets its own skeleton, set with BangBang.setindex!!, since elements of one concrete type can also have skeletons of different types, such as when a field typed Any holds a vector in one element and a matrix in another. Fixes TuringLang#1540
sunxd3
force-pushed
the
skeleton-of-each-element
branch
from
November 19, 2026 20:25
c5a24ca to
f113816
Compare
sunxd3
approved these changes
Nov 19, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1542 +/- ##
==========================================
- Coverage 85.12% 85.11% -0.01%
==========================================
Files 52 52
Lines 4671 4677 +6
==========================================
+ Hits 3976 3981 +5
- Misses 695 696 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
@PTWaade thanks! |
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.
Dear Turing, and @sunxd3
As @sunxd3 requested, I am here opening a PR for fixing the issue reported in #1540. The PR is drafted by Claude (also incorporating the points raised in the discussion there). I don't know enough of Turing's internals to be able to confidently judge whether this is an appropriate solution, but since it at first glance seemed correct to your developers, I am opening this PR - I hope it is useful. Below is a report by Claude. Let me know if there is anything I can do!
--- Claude ---
Fixes #1540.
skeletonof aPartialArraywhose element type is concrete took the skeleton of the first element that is set, and filled every element with it. When the elements hold arrays of different sizes, the round trip in the docstring ofskeletonfails: with the shorter array first it throws aBoundsError, and with the longer first it rebuilds arrays of the wrong size. This is what madeFlexiChains.parameters_atfail on the chains in the issue.This PR gives each element that is set its own skeleton, as the branch for an abstract element type already does. As @sunxd3 pointed out, elements of one concrete type can also have skeletons of different types, such as when a field typed
Anyholds a vector in one element and a matrix in another, so each skeleton is set withBangBang.setindex!!, which widens the array when it has to. Elements that aren't set keep the skeleton of the first element that is set, as before.Tests: three cases in the
skeletontestset oftest/varnamedtuple.jl, inner arrays of different sizes in both orders, checked with@inferredand the round trip, and the case with a field typedAny, built directly as aPartialArray, whose skeleton can't be inferred. Onmain, the first throws theBoundsError, the second rebuilds a differentVarNamedTuple, and withnew_data[i] = …in place ofsetindex!!the third throws aconverterror. With this PRtest/varnamedtuple.jlpasses, 50545 tests, and the reproducer from the issue gives back its values. Formatted with JuliaFormatter 1.0.62.