Also if k is known in advance, you could precompute the signs and map to 
the sample.

# clumsy computation of all vectors of length k with 1/-1 as entries using 
powerset.
 signs(k) = [[(-1)^(i in s) for i = 1:k] for s=powerset(1:k)]

# now return a closure
sdifsums(k) = let s=signs(k) ; a->map(x-> sum(x.*a), s) ; end

# test with arrays of length 6
sdifsums6 = sdifsums(6)

# this gives X10 speedup on my computer
julia> @time 
sdifsums6([-0.160767,-1.48275,-0.384419,-1.3541,1.03842,-1.16268])
elapsed time: 0.001349613 seconds (97904 bytes allocated)
64-element Array{Float64,1}:
...

Reply via email to