Skip to content

fix: guard ResizableArray.iterate — skip unassigned slots, don't crash on empty/sparse tensors - #317

Open
docxology wants to merge 1 commit into
ReactiveBayes:mainfrom
docxology:fix/resizablearray-iterate-guard
Open

fix: guard ResizableArray.iterate — skip unassigned slots, don't crash on empty/sparse tensors#317
docxology wants to merge 1 commit into
ReactiveBayes:mainfrom
docxology:fix/resizablearray-iterate-guard

Conversation

@docxology

Copy link
Copy Markdown

Description

Fixes the sparse/ragged-tensor and empty-tensor iteration crashes in
src/resizable_array.jl:

  • sparse/ragged tensors (unassigned slots): for e in a threw BoundsError because
    iterate indexed by the reported max-extent size without an isassigned guard;
  • empty tensors: iterate(array) destructured iterate(CartesianIndices(...))
    unguarded, crashing on nothing.

Change

Rewrote the two Base.iterate methods to skip unassigned slots and to guard the
exhausted/empty cases, delegating to a small helper _resizable_iterate_step
(see findings/finding-05-…md for the exact code). Dense iteration order and the standard
zip/enumerate iteration protocol are unchanged.

Tests

Regression test in test/resizable_array_tests.jl: sparse ResizableArray (unassigned
slot) iterates via for/zip/vec without throwing and yields only the assigned values;
an empty ResizableArray iterates to zero elements.

Verification (Julia 1.12, direct)

check main this branch
dense for e in s order == vec(Array) pass pass
sparse 2-D hole: for e in a BoundsError pass ([1,2,3])
empty 2-D: for e in empty threw pass (0 elems)
zip(Array′, s) order pass pass

Note: the full test/resizable_array_tests.jl run via ReTestItems is blocked on this box by
the pre-existing GraphViz weak-dep precompile failure on Julia 1.12 (minor-06), unrelated to
this change; the iterate item itself runs and the direct checks above mirror its assertions.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant