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.
|
Thanks for the report — the underlying bug (#308) is real and reproducible. But this patch makes the failure mode worse, so I'm closing it in favour of a different fix.
On this branch, using the exact 2×2 example from #308 ( Silently returning garbage is strictly worse than crashing for a library whose job is building factor graphs deterministically — and broadcasting still throws regardless, so the crash isn't even eliminated. Making this work properly would mean changing #308 stays open and is being fixed that way, with a regression test. One process note that applies to all four PRs in this batch: the description here says a regression test was added to |
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.