Skip to content

Commit 03d5d7a

Browse files
author
Carlos Baptista
committed
devectorise 'poly' for better performance
I devectorised the single vectorised line. This provides a substantial reduction in both execution time and memory usage. For specifying 5 roots, the reduction is already about a factor of 2 for time and 8 for memory. The reduction grows substantially for an increasing number of specified roots.
1 parent 6b65f47 commit 03d5d7a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Polynomials.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ function poly{T}(r::AbstractVector{T}, var=:x)
296296
c = zeros(T, n+1)
297297
c[1] = 1
298298
for j = 1:n
299-
c[2:j+1] = c[2:j+1]-r[j]*c[1:j]
299+
for i = 1:j
300+
c[i+1] = c[i+1]-r[j]*c[i]
301+
end
300302
end
301303
return Poly(reverse(c), var)
302304
end

0 commit comments

Comments
 (0)