Those coming to Julia from languages like Python, R, Matlab/Octave, etc. 
have it ingrained in them to "fear the loop" and to perform loop-like 
calculations in "verbose and convoluted" ways.  It is actually quite easy 
to do this calculation in Julia with very little storage allocation by 
writing three nested loops.

function mindist(pos::Matrix{Float64}, Acp::Matrix{Float64})
    m,n = size(pos)
    r,s = size(Acp)
    m == r || throw(DimensionMismatch(""))
    res = fill(Inf,(n,))
    for i in 1:n
        for j in 1:s
            sm = 0.
            for k in 1:m
                sm += abs2(pos[k,i] - Acp[k,j])
            end
            if sm < res[i]
                res[i] = sm
            end
        end
    end
    res
end

On my machine timing the second execution (the first execution includes 
compile time) I get

julia> @time mindist(pos,Acp);
elapsed time: 0.002806999 seconds (744 bytes allocated)

Reply via email to