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

Should Scalar(1) .+ 1 return 2 or Scalar(2)? #775

Open
MasonProtter opened this issue Apr 24, 2020 · 4 comments
Open

Should Scalar(1) .+ 1 return 2 or Scalar(2)? #775

MasonProtter opened this issue Apr 24, 2020 · 4 comments
Labels
broadcast design speculative design related issue

Comments

@MasonProtter
Copy link

If was brought up here: JuliaLang/julia#35591 that one nice property of Ref is that

julia> Ref(1) .+ 1
2

whereas

julia> Scalar(1) .+ 1
Scalar{Int64}((2,))

I'm not sure how I feel about this difference yet, but I figured I should open an issue to discuss it.

@MasonProtter
Copy link
Author

More evidence perhaps pointing towards the idea that the output should be 2:

julia> A = Array{Int, 0}(undef)
0-dimensional Array{Int64,0}:
0

julia> A[] = 1
1

julia> A .+ 1
2

@MasonProtter
Copy link
Author

The simplest way to get this behaviour for Scalar is to do

Base.BroadcastStyle(::Type{<:Scalar}) = Base.Broadcast.DefaultArrayStyle{0}()

but perhaps someone who understands broadcast internals better than me could just tweak StaticArrayStyle{0} to do the 'right' thing.

@tkf
Copy link
Member

tkf commented Apr 25, 2020

just tweak StaticArrayStyle{0} to do the 'right' thing

Sounds like the best approach to me.

@c42f
Copy link
Member

c42f commented Apr 25, 2020

I started rewriting StaticArrays broadcast for #744... just got bogged down and haven't had a chance to finish it, it's very fiddly! I suppose this could be considered at the same time.

@c42f c42f added broadcast design speculative design related issue labels Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
broadcast design speculative design related issue
Projects
None yet
Development

No branches or pull requests

3 participants