I'm no Julia expert, but I'm pretty certain this fall under the category "If you Julia to optimize, put your code in a function."
gibson@timaeus$ ~/packages/julia-0.4.0/bin/julia _ _ _ _(_)_ | A fresh approach to technical computing (_) | (_) (_) | Documentation: http://docs.julialang.org _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 0.4.0 (2015-10-08 06:20 UTC) _/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release |__/ | x86_64-unknown-linux-gnu julia> X = rand(2,2) 2x2 Array{Float64,2}: 0.713809 0.0650767 0.916874 0.111741 julia> K = [dot(X[:,i], X[:,j]) for i=1:2, j=1:2] 2x2 Array{Any,2}: 1.35018 0.148905 0.148905 0.0167211 julia> f(X) = [dot(X[:,i], X[:,j]) for i=1:2, j=1:2] f (generic function with 1 method) julia> f(X) 2x2 Array{Float64,2}: 1.35018 0.148905 0.148905 0.0167211 John On Monday, November 9, 2015 at 11:42:15 AM UTC-5, rizal zaini wrote: > > My concern is also on parallel code: > > julia> K = @parallel [dot(X[:,i], X[:,j]) for i=1:5, j=1:5] 5x5 > DArray{Any,2,Array{Any,2}}: 1.35134 1.36439 1.28474 1.13181 1.07863 1.36439 > 1.40077 1.25708 1.22365 1.08332 1.28474 1.25708 1.54494 0.95311 1.15779 > 1.13181 1.22365 0.95311 1.70348 1.30076 1.07863 1.08332 1.15779 1.30076 > 1.34577 > > I expect to get a DArray{Float64,2,Array{Float64,2}} rather than > DArray{Any,2,Array{Any,2}} > > Please help. > > Rizal > > On Mon, Nov 9, 2015 at 9:11 AM, rizal zaini <riza...@gmail.com > <javascript:>> wrote: > >> Hi all >> >> I want to create matrix containing dot products >> >> julia> X = rand(5,5) >> 5x5 Array{Float64,2}: >> 0.274799 0.564619 0.915595 0.341059 0.57361 >> 0.0806822 0.293939 0.379279 0.608582 0.652441 >> 0.264678 0.532751 0.289088 0.457759 0.492777 >> 0.33856 0.495587 0.499099 0.548237 0.402534 >> 0.686305 0.168385 0.8322 0.605532 0.518693 >> >> julia> K = [dot(X[:,i], X[:,j]) for i=1:5, j=1:5] >> 5x5 Array{Any,2}: >> 0.737716 0.603229 1.09884 0.865174 0.832958 >> 0.603229 0.962978 1.16994 0.988988 1.06501 >> 1.09884 1.16994 2.00739 1.45298 1.54767 >> 0.865174 0.988988 1.45298 1.36347 1.35304 >> 0.832958 1.06501 1.54767 1.35304 1.42861 >> >> I expect to get an Array{Float64,2}, but what I got is Array{Any,2}. >> How to get Array{Float64,2} using Array comprehension? >> >> Thanks before >> Rizal >> > >