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

ranges: broadcast preserves length #42410

Merged
merged 1 commit into from
Sep 29, 2021
Merged

ranges: broadcast preserves length #42410

merged 1 commit into from
Sep 29, 2021

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented Sep 28, 2021

Fixes #42291

@dkarrasch dkarrasch added the domain:ranges Everything AbstractRange label Sep 28, 2021
@@ -1087,10 +1087,12 @@ broadcasted(::DefaultArrayStyle{1}, ::typeof(-), r::LinRange) = LinRange(-r.star
# 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
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa, wat.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this never actually got called since ::Real .+ ::Real would be a 0-dimensional broadcast.

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.

yeah, there's a definition broadcast(f, a::Number...) = f(a...) that catches it first

@vtjnash vtjnash merged commit 72e55a0 into master Sep 29, 2021
@vtjnash vtjnash deleted the jn/42291 branch September 29, 2021 20:09
KristofferC pushed a commit that referenced this pull request Oct 5, 2021
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:ranges Everything AbstractRange
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnitRange in 1.7-rc1
4 participants