-
Notifications
You must be signed in to change notification settings - Fork 5
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
Deprecate r + 1 in favor of r .+ 1 #8
Conversation
@mbauman, for julia> r = Base.IdentityUnitRange(-2:2)
Base.IdentityUnitRange(-2:2)
julia> r .+ 1
-1:3
julia> axes(r .+ 1)
(Base.OneTo(5),) Compare with this PR: julia> r = IdentityRange(-3:3)
IdentityRange(-3:3)
julia> r .+ 1
7-element OffsetArray(::UnitRange{Int64}, -3:3) with eltype Int64 with indices -3:3:
-2
-1
0
1
2
3
4 There is no type in Base that can represent the correct answer, so should we just have it throw an error? |
Oh dang. That's unfortunate. Yup, I agree — we can't keep doing what we were doing. The problem stems from the use of All these abstract range definitions will be wrong for an offset range like |
Presumably we could make them conditional on having unit axes, so that one can specialize those methods and make them work. Perhaps OffsetArrays could engage in a bit of type-piracy and provide the correct implementations? |
That sounds reasonable to me — on both points. It feels a little messy, but I guess we could just dispatch to an internal function that also takes the axes of the given abstract range. That'd allow us to default to an error and allow OffsetArrays to recover the functionality gracefully (well, as gracefully as a peg-legged pirate can be). |
Also wrong are |
Also fixes r .+ 1, r .* 2, r ./ 2, and 2 .\ r (and other orders)
Thanks for pointing out the errors on |
Actually, if we can, let's have the |
Yeah, that requires OffsetArrays to know all concrete offset range implementations. I suppose there are a very limited number, though, so this probably isn't worth the extra contortions. Another bug: |
Here it was mostly correct because of the |
Ah, nice. We still need to change it in Base, though... that was my bigger concern. |
This was giving incorrect results for
r .+ 1
(it "erased" the axes), because the old correct implementations were forr + 1
. I should have noticed this as part of #7, but failed to do so.So, this is a breaking change. Will release as 0.3.