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

broadcast is ambiguous with base #132

Closed
Keno opened this issue Apr 1, 2017 · 10 comments
Closed

broadcast is ambiguous with base #132

Keno opened this issue Apr 1, 2017 · 10 comments

Comments

@Keno
Copy link
Contributor

Keno commented Apr 1, 2017

This method: https://github.com/Keno/StaticArrays.jl/blob/master/src/broadcast.jl#L7
is ambiguous with base:

MethodError: broadcast(::Optim.UnivariateProblems.##1#3, ::Float64) is ambiguous. Candidates:
  broadcast(f, a::Union{Number, StaticArrays.StaticArray}, b::Union{Number, StaticArrays.StaticArray}...) in StaticArrays at /global/cscratch1/sd/kfischer/celeste-pkgs/v0.6/StaticArrays/src/broadcast.jl:8
  broadcast(f, x::Number...) in Base.Broadcast at broadcast.jl:16

that's bad form

@timholy
Copy link
Member

timholy commented Apr 1, 2017

The problem here is that Base broadcast requires zero or more arguments whereas here it requires one or more. Presumably just need to get rid of the a argument and start straight with b, since Union{A,B} should always be less specific than A.

Overall, detect_ambiguities picks up 72 ambiguities when StaticArrays is loaded. The good news is that Base.Dates seems to no longer be a source of trouble.

@andyferris
Copy link
Member

This is due to a recent PR by @tkelman: https://github.com/JuliaArrays/StaticArrays.jl/pull/126/files

I suspect we should role back that particular change for broadcast?

@marius311
Copy link
Contributor

Just ran into this also. Can't say I'm following closely enough to understand why the two separate a,b args were needed in the PR mentioned above, but if you want to keep that, you could use the following trick,

function broadcast(f, a::Union{_, Number, StaticArray}, b::Union{_, Number, StaticArray}...) where {_<:StaticArray}

this will only match when there's at least one StaticArray present among the args, so there's not even a question of if its more specific.

@marius311
Copy link
Contributor

(See also https://discourse.julialang.org/t/incorrect-ambiguity/2690 since this trick/hack doesn't always work, granted I just checked it does in this case)

@andyferris
Copy link
Member

Thanks @marius311 - that's a very interesting observation.

@dlfivefifty
Copy link
Member

Even exp.(1.0+2.0im) triggers this....

@dlfivefifty
Copy link
Member

dlfivefifty commented Apr 3, 2017

How would you feel about this (less than elegant) work around for low number of arguments:

@propagate_inbounds broadcast(f, a::StaticArray, b::Union{Number, StaticArray}...) = _broadcast(f, broadcast_sizes(a,b...), a, b...)
@propagate_inbounds broadcast(f, n1::Number, a::StaticArray, b::Union{Number, StaticArray}...) = _broadcast(f, broadcast_sizes(n1,a,b...), n1, a, b...)
@propagate_inbounds broadcast(f, n1::Number, n2::Number, a::StaticArray, b::Union{Number, StaticArray}...) = _broadcast(f, broadcast_sizes(n1,n2,a,b...), n1, n2, a, b...)

@andyferris
Copy link
Member

Does #135 work for you @dlfivefifty?

@dlfivefifty
Copy link
Member

dlfivefifty commented Apr 4, 2017 via email

@c42f
Copy link
Member

c42f commented Apr 14, 2017

I assume this is sorted now out via #135.

By the way @marius311 that's a really nice trick. I've used in #136 which would otherwise seem intractable in general.

@c42f c42f closed this as completed Apr 14, 2017
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

No branches or pull requests

6 participants