-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Unexpected type when using comprehensions #4430
Comments
Inferring types in array comprehensions has frequently been brittle, but In the mean time, assuming the type is always the same, you can get around julia> x = rand(3) julia> y = Float64[x[i] for i = 1:3] Kevin On Thu, Oct 3, 2013 at 3:23 PM, Carlos Baptista [email protected]:
|
Interesting point: this problem is related to being in the global scope and doesn't happen inside of functions.
I think the problem is that, in the global scope, the compiler doesn't feel certain of the type of |
Thanks, John--I've forgotten this point more than once! On Thu, Oct 3, 2013 at 3:36 PM, John Myles White
|
Thanks Kevin. That did the trick. And likewise I keep on forgetting to check things out in functions. With a background in MATLAB and Python, I still have to get used to that. |
Usually I get a type from comprehensions which I expected, except for the last example below. I find it weird that
y
becomes an array ofAny
. I was expecting an array ofFloat64
. I was able to get an array ofFloat64
by definingx
as aconst
. However that will not be possible in all use cases. How can I avoid this 'weird' behaviour (without usingconst x
orconst x2 = copy(x)
? Or is this a bug perhaps?The text was updated successfully, but these errors were encountered: