Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #228 +/- ##
==========================================
- Coverage 94.40% 94.26% -0.15%
==========================================
Files 5 5
Lines 322 349 +27
==========================================
+ Hits 304 329 +25
- Misses 18 20 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| include("axes.jl") | ||
| include("utils.jl") | ||
| include("origin.jl") | ||
|
|
There was a problem hiding this comment.
This is to let utils.jl know the OffsetAxisKnownLength and OffsetAxis.
For better compatibility to old and future Julia versions
|
Since this changes the axes of the reshaped array, this should perhaps be treated as a breaking change? |
|
Since we never successfully supported |
|
This works currently on master: julia> A = zeros(1:2, 3:4)
2×2 OffsetArray(::Matrix{Float64}, 1:2, 3:4) with eltype Float64 with indices 1:2×3:4:
0.0 0.0
0.0 0.0
julia> reshape(A, 2:3, :)
2×2 OffsetArray(::Matrix{Float64}, 2:3, 1:2) with eltype Float64 with indices 2:3×1:2:
0.0 0.0
0.0 0.0After this PR: julia> reshape(A, 2:3, :)
2×2 OffsetArray(::Matrix{Float64}, 2:3, 3:4) with eltype Float64 with indices 2:3×3:4:
0.0 0.0
0.0 0.0 |
| function Base.reshape(A::AbstractArray, inds::Tuple{OffsetAxis,Vararg{OffsetAxis}}) | ||
| AR = reshape(A, map(_indexlength, inds)) | ||
| return OffsetArray(AR, map(_offset, axes(AR), inds)) | ||
| return OffsetArray(AR, _offset_reshape_uncolon(A, inds)) |
There was a problem hiding this comment.
This is equivalent to
return OffsetArray(AR, map(_offset, axes(AR), _offset_reshape_uncolon(A, inds)))By removing the map part, it calls another constructor.
OffsetArrays.jl/src/OffsetArrays.jl
Lines 210 to 219 in b74ae55
|
Perhaps some of the other methods need to be altered too to get this to be consistent: julia> reshape(OffsetArray(3:4, 2), :) # preserves offset
3:4 with indices 3:4
julia> reshape(OffsetArray(3:4, 2), :, 1) # does not preserve offset
2×1 reshape(::UnitRange{Int64}, 2, 1) with eltype Int64:
3
4 |
As a placeholder for a slice,
Colonat the k-th position also preserves the offset of theaxes(A, k). The default offset fork>=ndims(A)is assumed to be 0.The implementation is based on https://github.com/JuliaLang/julia/blob/d29126a43ee289fc5ab8fcb3dc0e03f514605950/base/reshapedarray.jl#L119-L137
closes #220
cc: @jishnub