JuliaArrays / OffsetArrays.jl

Fortran-like arrays with arbitrary, zero or negative starting indices.
Other
195 stars 40 forks source link

`collect(Iterator.product(offset arrays))` is an OffsetArray but `collect (offset_array)` is not #332

Open FelixBenning opened 1 year ago

FelixBenning commented 1 year ago

So here is a weird thing:

julia> Iterators.product(OffsetArray(rand(3), -1:1), 1:2) |> collect
3×2 OffsetArray(::Matrix{Tuple{Float64, Int64}}, -1:1, 1:2) with eltype Tuple{Float64, Int64} with indices -1:1×1:2:
 (0.892917, 1)  (0.892917, 2)
 (0.398366, 1)  (0.398366, 2)
 (0.550785, 1)  (0.550785, 2)

julia> collect(ans)
3×2 Matrix{Tuple{Float64, Int64}}:
 (0.892917, 1)  (0.892917, 2)
 (0.398366, 1)  (0.398366, 2)
 (0.550785, 1)  (0.550785, 2)

Since collect promises an Array not an AbstractArray I am thinking that the first return is wrong. But I think this should probably be consistent at least. At least I would assume that collect(collect()) == collect

jishnub commented 1 year ago

This seems like a problem with collect using similar to create the destination, instead of using an Array. Could you report this in Julia Base? That's where the fix should go to

jishnub commented 5 months ago

Xref: https://github.com/JuliaLang/julia/issues/50051