Summary
Base.iterate for ResizableArray (src/resizable_array.jl:175-194) indexes by the
reported (= max-extent) size without an isassigned guard. Iterating a ragged or
sparsely-filled tensor (collect, for … in arr, map, broadcast) raises BoundsError
for unassigned slots. Base.vec/first/firstwithindex/lastwithindex do guard with
isassigned, so iteration is the odd one out.
Repro
using GraphPPL
a = GraphPPL.ResizableArray(Float64, Val(2))
a[1, 1] = 1.0; a[1, 2] = 2.0; a[2, 1] = 3.0 # row 2 has no [2,2]
size(a) # (2, 2) — max extent
isassigned(a, 2, 2) # false
collect(a) # ERROR: BoundsError
GraphPPL.vec(a) # [1.0, 3.0, 2.0] (guarded — works)
Suggested fix
Guard iterate (both the 0-arg and state-carrying methods) with isassigned, skipping
unassigned slots — consistent with vec/first. Alternatively document that full iteration
requires a dense array and steer users to vec.
Summary
Base.iterateforResizableArray(src/resizable_array.jl:175-194) indexes by thereported (= max-extent)
sizewithout anisassignedguard. Iterating a ragged orsparsely-filled tensor (
collect,for … in arr,map, broadcast) raisesBoundsErrorfor unassigned slots.
Base.vec/first/firstwithindex/lastwithindexdo guard withisassigned, so iteration is the odd one out.Repro
Suggested fix
Guard
iterate(both the 0-arg and state-carrying methods) withisassigned, skippingunassigned slots — consistent with
vec/first. Alternatively document that full iterationrequires a dense array and steer users to
vec.