-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Construct ranges of CartesianIndexes #41960
Conversation
So there are two valid interpretations of
and the confusion shows up when the inputs to julia> range(start=[1,1], step=[2,3], length=3)
[1, 1]:[2, 3]:[5, 7] Because order and distance are undefined for vector space, we can't expect I think this is a good change, and the displayed results differences should be interpreted based on the concrete scenarios, it's not ideal but I think both usages are valid. FWIW, at some point, I was trying to propose |
Tests fail because |
I think it's clear and harmless to define: oneunit(::Char) = Char(1)
zero(::Char) = Char(0) Because string join is defined as the char multiplication, and because we don't have empty char literal(do we?), we can't define To do this I think we need a separate PR. |
This could be a bad idea. Do you think it will make things clearer to add a depwarn when Edit: I now think it's a bad idea because it enforces the input type to support |
What does this PR have to do with string joining? Since there is no addition on chars with other chars, having a If we want to go with "strings multiply", then neither |
The failing test in question is this one: Lines 38 to 40 in 14ba473
|
Sorry, I only checked that there's char subtraction Perhaps others have some ideas, but I don't see a clear path out if we want to extend |
Hmm. I see what you mean about this being confusing. But this change is too. Echoing #41960 (comment), what does a = CartesianIndex(1, 1)
range(a, step=a, stop=CartesianIndex(3, 4)) do? Having Personally I think this should be by directly calling |
Yes, given the scope for confusion, perhaps it's best to not go ahead with the general idea of ranges of |
Yeah, I agree that the constructor is missing. I don't know if you saw my edit, but I also think an error hint would be helpful here. |
Ah I had missed your edit. I have not used error hints before, where should this go? Should I make |
Would it be better if |
The meaning of
On the other hand, the behavior of |
That makes sense, and is probably the best approach. Could you point me towards how to register an error hint? Which file should I put this in? |
Maybe just explicitly add some eager checks by dispatching on # might not be a complete list
range_stop
range_start_step_length
range_stop_length
range_start_stop
range_start_length
range_start_step_stop Some currently error so it's okay to keep them erroring, some are currently working so we need to deprecate them in favor of the explicit # The `range` function on non-scalar inputs is not always well defined and could cause confusion.
const UnsupportedRangeTypes = Union{AbstractArray, AbstractCartesianIndex}
range_stop(stop::UnsupportedRangeTypes) = throw(ArgumentError("Non-scalar inputs for `range` are not supported.")
@deprecate range_start_step_length(start::UnsupportedRangeTypes, stop::UnsupportedRangeTypes, length::Integer) StepRangeLen(start, stop, length) Do you think this is doable? This could be a breaking change, however, so better to run a pkgeval before approval or merging. |
Closing in favor of #50457, which I had opened after having forgotten about this PR. |
This PR adds the ability to construct
StepRangeLen
s ofCartesianIndex
es. This works if start/stop, step and length are specified. Methods withstep
unspecified are not added, and these error as before. The display of aStepRangeLen
ofCartesianIndex
es is also changed to not use thea:b:c
spelling, as this produces aCartesianIndices
instead.This is complementary to #37829 that introduced the start-step-stop pattern to produce
CartesianIndices
that are the iterator product of multiple ranges.This PR currently also allows one to construct such a range using
range
asThis will be removed, as it is quite confusing to have
range(start; stop, length)
mean something else fromrange(start; stop, step)
. To illustrate why this should be removed: