First, it is better to use a 3-dimensional array rather than an array of
arrays. If you must use an array of arrays, it is better for the outer
array to be of type Array{Array{Float,2},1} rather than Array{Any,1}.
For max performance, it is hard to beat explicit loops:
result = Array(Float64, size(V,1), 2, size(EV,2))
for k = 1 : size(EV,2)
for j = 1 : 2
for i = 1 : size(V,1)
result[i,j,k] = V[i,EV[j,k]]
end
end
end
There are some macro packages like Einsum.jl that let you hide the explicit
loops.
-- Steve Vavasis
On Friday, September 30, 2016 at 9:53:43 AM UTC-4, [email protected] wrote:
>
> Hi guys,
>
> I'm learning the language while implementing an advanced package for
> geometric and solid modeling.
> My question is: What is the right idiom (shorter and/or faster) for
> writing this kind of array indexing:
>
> linesFromLineArray(V,EV) = Any[[V[:,EV[:,k][1]] V[:,EV[:,k][2]] ] for
> k=1:size(EV,2)]
>
> The efficiency is the strongest issue, since this method should provide
> the indirect indexing for any kind of cellular complexes.
> Many thanks for your help
>
>
> julia> V,EV
> (
> 2x10 Array{Float64,2}:
> 0.13611 0.14143 0.38501 0.42103 0.96927 0.90207 0.0 0.11508
> 0.61437 0.52335
> 0.59824 0.58921 0.25964 0.24118 0.19741 0.34109 0.0213 0.0
> 0.05601 0.17309,
>
> 2x5 Array{Int64,2}:
> 1 3 5 7 9
> 2 4 6 8 10)
>
> julia> linesFromLineArray(V,EV)
> 5-element Array{Any,1}:
> 2x2 Array{Float64,2}:
> 0.13611 0.14143
> 0.59824 0.58921
> 2x2 Array{Float64,2}:
> 0.38501 0.42103
> 0.25964 0.24118
> 2x2 Array{Float64,2}:
> 0.96927 0.90207
> 0.19741 0.34109
> 2x2 Array{Float64,2}:
> 0.0 0.11508
> 0.0213 0.0
> 2x2 Array{Float64,2}:
> 0.61437 0.52335
> 0.05601 0.17309
>
>