fix: guard ResizableArray.iterate — skip unassigned slots, don't crash on empty/sparse tensors - #317
Open
docxology wants to merge 1 commit into
Open
Conversation
…ots) Iterating a ragged/sparse tensor raised BoundsError because iterate indexed by the reported max-extent size without checking isassigned. Skip unassigned slots, consistent with vec/first.
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.
Description
Fixes the sparse/ragged-tensor and empty-tensor iteration crashes in
src/resizable_array.jl:for e in athrewBoundsErrorbecauseiterateindexed by the reported max-extentsizewithout anisassignedguard;iterate(array)destructurediterate(CartesianIndices(...))unguarded, crashing on
nothing.Change
Rewrote the two
Base.iteratemethods to skip unassigned slots and to guard theexhausted/empty cases, delegating to a small helper
_resizable_iterate_step(see
findings/finding-05-…mdfor the exact code). Dense iteration order and the standardzip/enumerateiteration protocol are unchanged.Tests
Regression test in
test/resizable_array_tests.jl: sparseResizableArray(unassignedslot) iterates via
for/zip/vecwithout throwing and yields only the assigned values;an empty
ResizableArrayiterates to zero elements.Verification (Julia 1.12, direct)
mainfor e in sorder ==vec(Array)for e in a[1,2,3])for e in emptyzip(Array′, s)orderNote: the full
test/resizable_array_tests.jlrun via ReTestItems is blocked on this box bythe pre-existing GraphViz weak-dep precompile failure on Julia 1.12 (minor-06), unrelated to
this change; the
iterateitem itself runs and the direct checks above mirror its assertions.