-
-
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
Bug in @view
: begin
indexing vs. replace_ref_begin_end!
#41630
Comments
Now watch this: julia> a = OffsetArray([1 2; 3 4], -10:-9, 9:10)
2×2 OffsetArray(::Array{Int64,2}, -10:-9, 9:10) with eltype Int64 with indices -10:-9×9:10:
1 2
3 4
julia> @view a[end, begin]
ERROR: BoundsError: attempt to access 2×2 OffsetArray(::Array{Int64,2}, -10:-9, 9:10) with eltype Int64 with indices -10:-9×9:10 at index [-9, 1]
Stacktrace:
[1] throw_boundserror(::OffsetArray{Int64,2,Array{Int64,2}}, ::Tuple{Int64,Int64}) at ./abstractarray.jl:541
[2] checkbounds at ./abstractarray.jl:506 [inlined]
[3] view(::OffsetArray{Int64,2,Array{Int64,2}}, ::Int64, ::Int64) at ./subarray.jl:158
[4] top-level scope at REPL[5]:1 |
begin
indexing vs. replace_ref_begin_end!
@view
: begin
indexing vs. replace_ref_begin_end!
Yeah, that's definitely a bug. Should be easy enough to fix though. |
Fixing the one line in But is there any chance to reuse whatever is happening internally, so that macro writers can rely on matching behaviour? This: julia> Meta.@lower a[end, begin]
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope'
1 ─ %1 = Base.lastindex(a, 1)
│ %2 = Base.axes(a, 2)
│ %3 = Base.first(%2)
│ %4 = Base.getindex(a, %1, %3)
└── return %4
)))) looks like it has never seen |
The way our frontend is currently implemented, there's not really a nice way to do this. It is possible that might get rewritten in Julia some day and we might be able to expose some of it to macros, but there aren't any plans for that currently. |
I thought
Base.replace_ref_begin_end!
is used to implementbegin
indexing, but appearently they are inconsistent?Reading the source of it, I stumbled upon this line in views.jl:
Shouldn't that be
$firstindex($S, $n)
? I tried producing a failing example using OffsetArrays, but that only showed some sort of discrepancy, which I can't explain:The text was updated successfully, but these errors were encountered: