-
Notifications
You must be signed in to change notification settings - Fork 42
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
Use to_indices in the OffsetArray constructor #157
Conversation
Codecov Report
@@ Coverage Diff @@
## master #157 +/- ##
==========================================
+ Coverage 94.60% 99.60% +5.00%
==========================================
Files 4 4
Lines 241 256 +15
==========================================
+ Hits 228 255 +27
+ Misses 13 1 -12
Continue to review full report at Codecov.
|
Haven't taken a look at the details but it looks nice. Should I get #148 in first, or get this in first? Either way it requires some extra rebasing work to solve the conflicts. |
Maybe #148 can go first as it is less of a change, more of a cleanup |
I think it's worth splitting this PR into two, with the bugfixes and performance improvements going into the 1.2 series and the added feature into 1.3 |
Oh. I haven’t thought about branching developments. I was thinking about squashing all these commits into 1.3.0 release.
The Origin features should be released in 1.3.0; this kind of blocks your plan unless we revert it :sad:
Johnny Chen
陈久宁
School of Mathematical Sciences, East China Normal University, Shanghai
华东师范大学数学科学学院
2020年9月24日 +0800 15:35 Jishnu Bhattacharya <notifications@github.com>,写道:
… I think it's worth splitting this PR into two, with the bugfixes and performance improvements going into the 1.2 series and the added feature into 1.3
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
As per semver, bugfixes should go in patch releases and features should go in minor releases. Origin and using to_indices therefore belong to 1.3. However bugfixes should go in 1.2.x. Maybe once Origin is merged I can rebase on top of that if we target 1.3, otherwise it's for 1.4. |
Strictly speaking, yes. I see the constructor rework and the origin feature as new features, so I'm targeting 1.3.0 and no more 1.2.x release. That said, I think it is totally fine to squash some bug fixes into a minor release; this frees us from managing different release branches with cherry-picks and back-ports or so...
LOL #147 is already merged. |
de948d1
to
9f26eb1
Compare
This PR also modifies this behavior on master: # on master
julia> OffsetVector(zeros(2,2), 1:2, 1:2)
2×2 OffsetArray(::Array{Float64,2}, 1:2, 1:2) with eltype Float64 with indices 1:2×1:2:
0.0 0.0
0.0 0.0 # this PR
julia> OffsetVector(zeros(2,2), 1:2, 1:2)
ERROR: ArgumentError: OffsetVector requires a 1D array |
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.
Except for the additional dispatch complexity and the tendency to somehow revert #148 🤣 , it looks really nice!
to_indices converts colons to ranges. This is followed by converting CartesianIndices to ranges. Fix indexing IdOffsetRange using offset ranges, ensuring that indexing is idempotent
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.
Thanks for doing this, really nice an improvement to make this generic! The test looks really awesome, too.
# In general, indices get converted to AbstractUnitRanges. | ||
# CartesianIndices{N} get converted to N ranges | ||
@eval function $FT(A::AbstractArray, inds::Tuple) | ||
@eval function $FT(A::AbstractArray, inds::Tuple{Any,Vararg{Any}}) |
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 isn't really necessary given the dispatch priority of Tuple{Vararg{Integer}}
over Tuple
, but helps to clarify that this method doesn't handle empty tuples.
# Nested OffsetArrays may strip off the wrapper and collate the offsets | ||
@eval function $FT(A::OffsetArray, offsets::Tuple{Vararg{Integer}}) | ||
_checkindices(A, offsets, "offsets") | ||
$FT(parent(A), map(+, A.offsets, offsets)) |
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.
Broadcasting treats values in Tuple
s as scalars as opposed to treating the Tuple
as a collection in itself, so something like (1,2) .+ (1,)
evaluates to (2,3)
. map
, on the other hand, operates elementwise. This is not strictly necessary as _checkindices
catches it anyway, but might help against future bugs.
@jishnub you're doing really great work! Feel free to merge when you think it is ready. I think this is the last piece we need to v1.3.0? |
Maybe we can include #152 in 1.3 as well, now that julia 1.5.2 has been released |
This PR relaxes the types that may be passed to the constructor. After this, any type that may be converted to an
AbstractUnitRange
may be passed, including types defined in an external package.For example, using EllipsisNotation.jl,
the leading axes are replaced by colons, and only the last index is offset.
The PR also fixes some indexing issues with
IdOffsetRange
s. Now indexing with offset rages are also idempotent.Also define
Base.firstindex
for anIdOfffsetRange
to make it marginally faster wrt. master, now it's as fast as the parent.vs