-
-
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
ArgumentError when adding opposed ranges #28072
Comments
We do have such a range construct that can handle 0 steps: julia> StepRangeLen(5,0,4)
5:0:5
julia> StepRangeLen(5,0,4) == collect(1:4) .+ (4:-1:1)
true The reason we don't return such a thing when adding two Note: julia> (1.0:4) .+ (4.0:-1:1)
5.0:0.0:5.0
julia> (1.0:4) .+ (4.0:-1:1) == [5, 5, 5, 5]
true |
Duplicate of #10391 |
Thanks for the great explanation Matt! |
This is magical:
I love that we can be so clever. Unfortunately, it can come back and bite us sometimes:
This is very clearly due to us trying to construct the range
[5:0:5]
that is supposed to be 4 elements long, but unfortunately we lose that information since it's supposed to be implicit instart
,stop
andstep
. The range abstraction doesn't know what to do here, and so we fail out.Likely we should have a fallback for this cleverness that simply constructs an array, but I don't like the idea that
Range
+Range
=Union{Range,Vector}
. I would rather that we had a different abstraction similar toUnitRange
, perhaps calledConstantRange
or something, that takes in a value and an explicit length so that we don't have some poor fool who is doing something like:and have his memory blow up for very particular values of
stepA
andstepB
. (Note that the code sample above, fanciful as it is, fails on current versions of Julia because it cannot finish the summation of the two ranges)The text was updated successfully, but these errors were encountered: