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 with type argument generating incorrect output types #19419

Closed
jdlangs opened this issue Nov 25, 2016 · 1 comment
Closed

Broadcast with type argument generating incorrect output types #19419

jdlangs opened this issue Nov 25, 2016 · 1 comment
Labels
compiler:inference Type inference

Comments

@jdlangs
Copy link
Contributor

jdlangs commented Nov 25, 2016

I noticed this behavior with round, ceil, and floor at least.

julia> broadcast(round, Int, [1,2,3])
3-element Array{Float64,1}:
 1.0
 2.0
 3.0

julia> broadcast(round, Int, 1.0*[1,2,3])
3-element Array{Int64,1}:
 1
 2
 3
@Sacha0
Copy link
Member

Sacha0 commented Nov 25, 2016

Edit edit: No mistake, but the issue is upstream of Core.Inference.return_type, I think in ziptype and _default_eltype. Specifically, broadcast(round, Int, [1,2,3]) determines its return eltype from this line,

    T = _default_eltype(Base.Generator{ziptype(As...), ftype(f, As...)})

with As = (Int, [1,2,3]). And due to this line, default_eltype effectively calls

Core.Inference.return_type(first, Tuple{Base.Generator{ziptype(As...), ftype(f, As...)}})

ziptype(Int, [1,2,3]) returns Base.Iterator.Zip2{Tuple{Int64},Tuple{Int64}}, causing type inference to inspect the round method appropriate for a pair of Int64s rather than the Int64 type paired with Int64.

Edit: Think I made a mistake. Please ignore.

A little reduction:

julia> VERSION
v"0.6.0-dev.1308"

julia> G = Base.Generator{Iterators.Zip2{Tuple{Int64},Tuple{Int64}}, typeof(a -> round(a...))}
Base.Generator{Base.Iterators.Zip2{Tuple{Int64},Tuple{Int64}},##3#4}

julia> Core.Inference.return_type(first, Tuple{G})
Float64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

No branches or pull requests

3 participants