Hi,
I am working on optimizing the following function:
@inbounds function get_symmetric_polynomials!(dest::Matrix{Complex{MultiFloat{Float64, 2}}}, roots::Matrix{Complex{MultiFloat{Float64, 2}}}, b::Int64)
if b == 0
dest[1, :] .= one(Complex{MultiFloat{Float64, 2}})
return
elseif b == 1
dest[1, :] .= one(Complex{MultiFloat{Float64, 2}})
dest[2, :] .= sum.(eachcol(roots))
return
end
dest[1, :] .= one(Complex{MultiFloat{Float64, 2}})
dest[2:end, :] .= zero(Complex{MultiFloat{Float64, 2}})
for i in axes(roots, 1)
for j in min(i, b):-1:1
dest[j+1, :] .+= roots[i, :] .* dest[j, :]
end
end
return
end
This function calculates elementary symmetric polynomials up to a given order b from a vector of complex numbers (roots). Specifically, given a vector X = {x_{1}, x_{2}, ..., x_{N}} and an integer b, it computes e_{a} = \sum_{i_{1} < i_{2} < \dots < i_{a+1}=1}^{N}x_{i_{1}}x_{i_{2}}\dots x_{i_{a}} for 0 \leq a \leq b.
Any suggestions on how to optimize this function further would be greatly appreciated.
I was first using the complex numbers from DoubleFloats.jl (using ComplexF64 leads to loss of precision for the sort of roots I am interested in, but in my testing, the precision offered by DoubleFloats is sufficient for the range of b
I am interested in, which is for b
up to 25), but then using MultiFloats.jl gives a nice speed up.
When I profile my code, I see that about half of the time is spent in multidimensional.jl
_getindex
. I am not sure what that is.
Any suggestions on how to optimize this function further would be greatly appreciated.