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

Incorrect type when using dot syntax for broadcasting, in Julia 0.4 #282

Closed
giordano opened this issue Sep 15, 2016 · 3 comments
Closed

Comments

@giordano
Copy link

Run the following code in Julia 0.4

using Compat
x = 0:10
typeof(@compat(sin.(x)))
# => Array{Any,1}

while I'd expect type Array{Float64,1}. This is a problem because, for example, fft doesn't work with Array{Any}. It happens only if the argument is a named variable, @compat(sin.(0:10)) works as expected.

@stevengj
Copy link
Member

The type computation in broadcast got improved in 0.5 ...

Maybe @compat(f.(x)) should look and see whether f is one of the list of built-in "vectorized" functions in 0.4 (sin etc. — see JuliaLang/julia#17302 for a list), and if so just call f(x).

@giordano
Copy link
Author

But in Julia 0.4 this returns the correct type:

typeof(broadcast(sin, 0.0:10.0))
# => Array{Float64,1}
x = 0.0:10.0
typeof(broadcast(sin, x))
# => Array{Float64,1}

May it be a problem with parsing the named variable within the macro?

@yuyichao
Copy link
Contributor

This is not fixable without actually backporting a significant amount of 0.5 code back to 0.4 in Compat. The broadcast syntax compat uses the same algorithm (well, it directly uses) for comprehension so the return type is as good as that. If you make x a local or a const the problem will be gone.

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

3 participants