-
-
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
add length type parameter to StepRangeLen #41619
Conversation
ref = start | ||
step = (Δ/(len-1))*Δfac | ||
else | ||
imin = Int(len) | ||
imin = len |
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.
The 2
and 1
on the call to steprangelen_hp
below might also need their types adjusted.
base/range.jl
Outdated
1 <= offset <= max(1,len) || throw(ArgumentError("StepRangeLen: offset must be in [1,$len], got $offset")) | ||
new(ref, step, len, offset) | ||
offset = convert(L, offset) | ||
1 <= offset <= max(1, len) || throw(ArgumentError("StepRangeLen: offset must be in [1,$len], got $offset")) |
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.
Maybe take the chance to put this in an internal function to avoid the GC frame? Saves a ns or so in the non-error case (~30%).
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.
I think I will leave that to someone else. This has grown already into a monstrosity (and I would like to see codegen do that transform automatically instead)
Also be more careful about using additive identity instead of multiplicative, and be more consistent about types in a few places. Fixes #41517
@JeffBezanson could you re-review? this now transforms LinRange too, for the sake of completeness |
Co-authored-by: Jeff Bezanson <jeff.bezanson@gmail.com>
# For #18336 we need to prevent promotion of the step type: | ||
broadcasted(::DefaultArrayStyle{1}, ::typeof(+), r::AbstractRange, x::Number) = range(first(r) + x, step=step(r), length=length(r)) | ||
broadcasted(::DefaultArrayStyle{1}, ::typeof(+), x::Number, r::AbstractRange) = range(x + first(r), step=step(r), length=length(r)) | ||
broadcasted(::DefaultArrayStyle{1}, ::typeof(+), r::OrdinalRange, x::Real) = range(first(r) + x, last(r) + x, step=step(r)) | ||
broadcasted(::DefaultArrayStyle{1}, ::typeof(+), x::Real, r::Real) = range(x + first(r), x + last(r), step=step(r)) |
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 line should supposedly have r::OrdinalRange
, but cf #42291.
* Document that `L`ength parameter needs Julia 1.7 vtjnash added the 4th type parameter `L` in #41619 to `StepRangeLen`. That addition seems to have appeared in Julia 1.7 so it should be documented as such. I found this out the hard way because my CI for code that used `L` is failing with Julia 1.6. Co-authored-by: Johnny Chen <johnnychen94@hotmail.com> Co-authored-by: Keno Fischer <keno@alumni.harvard.edu>
* Document that `L`ength parameter needs Julia 1.7 vtjnash added the 4th type parameter `L` in JuliaLang#41619 to `StepRangeLen`. That addition seems to have appeared in Julia 1.7 so it should be documented as such. I found this out the hard way because my CI for code that used `L` is failing with Julia 1.6. Co-authored-by: Johnny Chen <johnnychen94@hotmail.com> Co-authored-by: Keno Fischer <keno@alumni.harvard.edu>
* Document that `L`ength parameter needs Julia 1.7 vtjnash added the 4th type parameter `L` in JuliaLang#41619 to `StepRangeLen`. That addition seems to have appeared in Julia 1.7 so it should be documented as such. I found this out the hard way because my CI for code that used `L` is failing with Julia 1.6. Co-authored-by: Johnny Chen <johnnychen94@hotmail.com> Co-authored-by: Keno Fischer <keno@alumni.harvard.edu>
Also be more careful about using additive identity instead of
multiplicative, and be more consistent about types in a few places.
Fixes #41517