I can't comment on exactly why the return argument isn't inferred, but I'm 
pretty sure that's a feature that is still actively being worked on by the 
core devs.  When you need to ensure the correct type from a comprehension, 
you should be explicit:

...
mldBoot1 = Float64[ mean(sub(lD, 1:size(lD, 1), k)[sub(inds, 1:size(inds, 1
), j)]) for k = 1:size(lD, 2), j = 1:size(inds, 2) ]
...



On Wednesday, July 1, 2015 at 10:20:51 PM UTC-4, [email protected] wrote:
>
> Hi all,
>
> I'm on Julia v0.3.10 on Ubuntu 14.04 LTS. The following loop comprehension 
> correctly infers the type:
>
> function g()
>     x = randn(3, 2)
>     inds = rand(1:3, 3, 4)
>     y = [ mean(sub(x, 1:size(x, 1), k)[sub(inds, 1:size(inds, 1), j)]) for 
> k = 1:size(x, 2), j = 1:size(inds, 2) ]
>     println(typeof(y))
> end
>
> That is, the println statement returns Array{Float64, 2}.
>
> Inside another one of the my functions, I have the following code snippet
>
> function someFunction(lD::Matrix{Float64}, ...)
>
>     ...
>
>     println(typeof(lD))
>     println(typeof(inds))
>
>     mldBoot1 = [ mean(sub(lD, 1:size(lD, 1), k)[sub(inds, 1:size(inds, 1), 
> j)]) for k = 1:size(lD, 2), j = 1:size(inds, 2) ]
>
>     println(typeof(mldBoot1))
>
>     ....
>
> end
>
> The three println statements return, in order:
>
>     Array{Float64,2}
>     Array{Int64,2}
>     Array{Any,2}
>
> I've been messing around for a couple of hours now trying to work out why 
> it works in my toy example, but not in my more complicated function and 
> I've come up with nothing. Anyone else have any ideas?
>
> Cheers,
>
> Colin
>

Reply via email to