-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Permit the construction of a 1D StepRangeLen
of CartesianIndex
es
#50457
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
Permit the construction of a 1D StepRangeLen
of CartesianIndex
es
#50457
Conversation
The wider discussion around how |
There is certainly some scope for ambiguity here, as the following will behave differently: julia> range(CartesianIndex(1,1), step=CartesianIndex(1,1), stop=CartesianIndex(2,2))
CartesianIndices((1:1:2, 1:1:2))
julia> range(CartesianIndex(1,1), step=CartesianIndex(1,1), length=2)
CartesianIndex(1, 1):CartesianIndex(1, 1):CartesianIndex(2, 2) However, a 1D range of |
Yes that's a very good point - we'll likely have to decide one way or another at some point what we want the semantics to be. The core issue is in which direction that length ("how many steps to take") should be, i.e. whether a |
Looking at the history of the colon constructor for It seems like I had attempted a similar change in #41960, where the suggestion was the same: that |
Yes, there have been a few attempts :) Calling |
I think that since |
CartesianIndex
constructor with ndims
-matching CartesianIndex
argumentStepRangeLen
of CartesianIndex
es
Triage says 👍 on adding the constructor method, but we don't think adding the error method fixes the real problem. The real problem is the printing of the |
9f3740b
to
273d2cb
Compare
I've specialized julia> StepRangeLen(CartesianIndex(1, 2), CartesianIndex(3, 4), 2)
StepRangeLen(CartesianIndex(1, 2), CartesianIndex(3, 4), 2) This should fix #50784 |
Gentle bump |
Gentle bump @JeffBezanson |
Gentle bump |
Gentle bump |
Gentle bump, is there anything that remains to be done here? |
I think it's good now, I added the |
Triage already approved this. |
Thanks everyone! |
Thank you for bearing with us. |
) With #50457 now merged, an `AbstractRange` of `CartesianIndex`es should use `CartesianIndexing` in constructing a `SubArray`. I've limited the method to integer ranges, as this is the case where we know for sure that the indexing may be linear. Fixes ```julia julia> view(1:2, StepRangeLen(CartesianIndex(1), CartesianIndex(1), 0)) 0-element view(::UnitRange{Int64}, StepRangeLen(CartesianIndex(1,), CartesianIndex(1,), 0)) with eltype Int64 ``` --------- Co-authored-by: N5N3 <[email protected]>
This PR adds a
CartesianIndex
constructor withndims
-matchingCartesianIndex
argument.This allows constructing the following range: