-
Notifications
You must be signed in to change notification settings - Fork 46
Fix nested IdOffsetRange constructor #185
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #185 +/- ##
==========================================
+ Coverage 98.91% 99.28% +0.36%
==========================================
Files 5 5
Lines 277 280 +3
==========================================
+ Hits 274 278 +4
+ Misses 3 2 -1
Continue to review full report at Codecov.
|
f6a8266 to
a2ebf55
Compare
|
Fixes #186 , this was a bug in julia> a = reshape(1:12, 3, 4)
3×4 reshape(::UnitRange{Int64}, 3, 4) with eltype Int64:
1 4 7 10
2 5 8 11
3 6 9 12
julia> view(a, :, OffsetArrays.IdOffsetRange(3:4)) == view(a, :, 3:4)
true
julia> vo = view(a, OffsetArrays.IdOffsetRange(2:3), 3)
2-element view(reshape(::UnitRange{Int64}, 3, 4), OffsetArrays.IdOffsetRange(2:3), 3) with eltype Int64 with indices 1:2:
8
9 |
| offset::T | ||
|
|
||
| IdOffsetRange{T,I}(r::I, offset::T) where {T<:Integer,I<:AbstractUnitRange{T}} = new{T,I}(r, offset) | ||
| function IdOffsetRange{T,IdOffsetRange{T,I}}(r::IdOffsetRange{T,I}, offset::T) where {T<:Integer,I<:AbstractUnitRange{T}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need this? AFAICT it does the same thing as the default. If this is for ambiguity resolution, perhaps add a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to avoid a stack overflow error in another method. I'll leave a comment.
On master:
julia> IdOffsetRange{Int, IdOffsetRange{Int, UnitRange{Int}}}(IdOffsetRange(2:3, 1), 1)
ERROR: StackOverflowError:
Stacktrace:
[1] IdOffsetRange at [...]/OffsetArrays.jl/src/axes.jl:80 [inlined]
[2] IdOffsetRange at [...]/OffsetArrays.jl/src/axes.jl:85 [inlined]
[3] convert at ./range.jl:148 [inlined]
[4] offset_coerce at [...]/OffsetArrays.jl/src/axes.jl:125 [inlined]
[5] IdOffsetRange{Int64,IdOffsetRange{Int64,UnitRange{Int64}}}(::IdOffsetRange{Int64,UnitRange{Int64}}, ::Int64) at [...]/OffsetArrays.jl/src/axes.jl:98
[6] IdOffsetRange{Int64,IdOffsetRange{Int64,UnitRange{Int64}}}(::IdOffsetRange{Int64,UnitRange{Int64}}, ::Int64) at [...]/OffsetArrays.jl/src/axes.jl:99 (repeats 79983 times)
This is fixed by this method.
The method called on master is IdOffsetRange{T,I}(::IdOffsetRange, offset::Integer) which tries to coerce the argument types, and call IdOffsetRange{T,I}(::I, ::T) within itself. This is presumably meant for cases like
julia> IdOffsetRange{Int, UnitRange{Int}}(IdOffsetRange(2:3, 1), 1)
OffsetArrays.IdOffsetRange(4:5)however if the typevar I itself is an IdOffsetRange it ends up calling itself because the type signature is more specific. There might be a better way around this than adding this extra method, I'd just introduced this to avoid the overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Perhaps the argument-type coercion doesn't need to specialize on IdOffsetRange for the range? If that's not an easy fix, then just adding a brief comment would be a nice addition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea behind that method was to remove the IdOffsetRange wrapper and coerce the parent range, as there is another method for generic AbstractUnitRange arguments. Not quite sure of the performance impacts of removing this, perhaps one may look into it in another PR. As of now I have added a comment in 7f4eecb
|
Very good! Would this have been easier to detect and analyze if IdOffsetRange printed the indices as well as values? I understand that not everyone likes #179, but should we change the printing some other way so that it is more revealing? |
|
Yes indeed, halfway through debugging this I was wishing that the indices were printed along with the values. It'll be good if we can figure out a way to display them. |
There was a bug introduced by #178 in defining
IdOffsetRange(::IdOffsetRange, offset), this PR fixes it.On master
After this PR: