-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What should repeat(::OffsetArray, ...) do #36294
Comments
One option I can't remember noticing in the past (but surely @andyferris and others have): should we use Currently it's a bit of a wreck: julia> a = Base.IdentityUnitRange(-3:3)
Base.IdentityUnitRange(-3:3)
julia> collect(a)
7-element Array{Int64,1}:
-3
-2
-1
0
1
2
3
julia> Array(a)
7-element Array{Int64,1}:
-3
-2
-1
0
1
2
3
julia> b = OffsetArray(-3:3, -3:3)
-3:3 with indices -3:3
julia> collect(b)
7-element Array{Int64,1}:
-3
-2
-1
0
1
2
3
julia> Array(b)
ERROR: BoundsError: attempt to access 7-element Array{Int64,1} at index [-3:3]
Stacktrace:
[1] throw_boundserror(::Array{Int64,1}, ::Tuple{OffsetArrays.IdOffsetRange{Int64,Base.OneTo{Int64}}}) at ./abstractarray.jl:537
[2] checkbounds at ./abstractarray.jl:502 [inlined]
[3] copyto!(::Array{Int64,1}, ::OffsetArray{Int64,1,UnitRange{Int64}}) at ./multidimensional.jl:959
[4] Array at ./array.jl:541 [inlined]
[5] Array(::OffsetArray{Int64,1,UnitRange{Int64}}) at ./boot.jl:429
[6] top-level scope at REPL[9]:1
julia> values(b)
-3:3 with indices -3:3
julia> values(a)
Base.IdentityUnitRange(-3:3) |
It's a good question. I have to say, I'm even sometimes a little confused about what
If I think beyond arrays, I can use for (i, x) in enumerate(iter)
...
end I could do something like for (i, x) in pairs(enumeration(iter))
...
end and |
|
My original intention for |
Thanks Stefan. Out of curiosity, what was wrong with using |
Related to this, I suggested more "lawful" approach to I think it's a good idea to make
I think the problem is that it doesn't scale. I don't think it's ideal for each custom container to have lowercase factory function that may or may not do what you expect (although it might be OK for |
In #35944 we noted that
repeat(::OffsetArray, ...)
is a little funny; it errors forinner
repeats and happens to return 1-based arrays forouter
repeats. I don't think either of these behaviors were ever explicitly thought through; it'd be good to decide how we want them to behave in the future.The text was updated successfully, but these errors were encountered: