-
Notifications
You must be signed in to change notification settings - Fork 40
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
Reshape with an offset parent array #245
Conversation
Codecov Report
@@ Coverage Diff @@
## master #245 +/- ##
==========================================
+ Coverage 95.26% 95.41% +0.15%
==========================================
Files 5 5
Lines 422 436 +14
==========================================
+ Hits 402 416 +14
Misses 20 20
Continue to review full report at Codecov.
|
julia> reshape(r, :) # Colon preserves offsets for an OffsetVector
Base.IdentityUnitRange(0:1) with indices -1:0 On whether Colon should preserve the offset, looks like there's a back&forth here. #228 (comment) I still believe we should preserve the offset because it provides more information. But that's definitely breaking, so need to properly deprecate it before v2.0. |
This is actually the present behavior (a single colon preserves offsets for an The present behavior (on master) is: julia> r = ones(2:3);
julia> reshape(r, :) # A single colon preserves offsets for an OffsetVector
2-element OffsetArray(::Vector{Float64}, 2:3) with eltype Float64 with indices 2:3:
1.0
1.0
julia> reshape(ones(2:3, 2:3), :) # offsets are stripped for an OffsetArray other than an OffsetVector
4-element Vector{Float64}:
1.0
1.0
1.0
1.0
julia> reshape(r, (2, :)) # colon with any other argument strips offsets
2×1 Matrix{Float64}:
1.0
1.0
julia> reshape(ones(2:3, 2:3), (3:4, :))
2×2 OffsetArray(::Matrix{Float64}, 3:4, 1:2) with eltype Float64 with indices 3:4×1:2:
1.0 1.0
1.0 1.0 In that regard I think #228 is the right step, where a |
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.
The last round of review with only some style suggestions. Feel free to merge when you're ready.
src/OffsetArrays.jl
Outdated
# try to pass on the indices as received to the parent. | ||
# If the parent doesn't define an appropriate method, this will fall back to using the lengths | ||
# Short-circuit the case with matching indices to circumvent the Base restriction to 1-based indices |
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.
Is this comment still useful? I guess no?
@johnnychen94 I've added some bugfixes, although the fix seems a bit hacky. Could you take a look? The main changes are in 9f91760, where I add |
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 can basically get your points here. And yes it is also tricky for me.
There might be some deeply hidden bugs but nothing suspicious to me so far.
Fixes #219
Now
The last one is a bugfix, as on master