Skip to content
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

Merged
merged 4 commits into from
Jul 23, 2021
Merged

add length type parameter to StepRangeLen #41619

merged 4 commits into from
Jul 23, 2021

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented Jul 16, 2021

Also be more careful about using additive identity instead of
multiplicative, and be more consistent about types in a few places.

Fixes #41517

@vtjnash vtjnash added the needs tests Unit tests are required for this change label Jul 16, 2021
base/range.jl Outdated Show resolved Hide resolved
ref = start
step = (Δ/(len-1))*Δfac
else
imin = Int(len)
imin = len
Copy link
Sponsor Member

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 Show resolved Hide resolved
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"))
Copy link
Sponsor Member

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%).

Copy link
Sponsor Member Author

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
@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Jul 21, 2021

@JeffBezanson could you re-review? this now transforms LinRange too, for the sake of completeness

@vtjnash vtjnash removed the needs tests Unit tests are required for this change label Jul 21, 2021
base/range.jl Outdated Show resolved Hide resolved
Co-authored-by: Jeff Bezanson <[email protected]>
@vtjnash vtjnash added the status:merge me PR is reviewed. Merge when all tests are passing label Jul 23, 2021
@vtjnash vtjnash merged commit 4f77aba into master Jul 23, 2021
@vtjnash vtjnash deleted the jn/41517 branch July 23, 2021 20:55
@vtjnash vtjnash removed the status:merge me PR is reviewed. Merge when all tests are passing label Jul 23, 2021
KristofferC pushed a commit that referenced this pull request Jul 26, 2021
Allows creating these ranges for any type of integer lengths.

Also need to be careful about using additive identity instead of
multiplicative, and be even more consistent now about types in a
few places.

Fixes #41517

(cherry picked from commit 4f77aba)
@mcabbott mcabbott mentioned this pull request Sep 17, 2021
# 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))
Copy link
Contributor

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.

KristofferC pushed a commit that referenced this pull request Jul 8, 2022
* 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 <[email protected]>
Co-authored-by: Keno Fischer <[email protected]>
ffucci pushed a commit to ffucci/julia that referenced this pull request Aug 11, 2022
* 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 <[email protected]>
Co-authored-by: Keno Fischer <[email protected]>
pcjentsch pushed a commit to pcjentsch/julia that referenced this pull request Aug 18, 2022
* 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 <[email protected]>
Co-authored-by: Keno Fischer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Julia v1.7: Multiplication broken with BigInt ranges
7 participants