Skip to content

Commit

Permalink
feat: 5x speedup in transfer func integration
Browse files Browse the repository at this point in the history
Another classic example of where using standard algorithms communicates
intent better, both to the reader and the compiler. Seems the quadrature
sum now gets unfolded and SIMD'd in a way that would have been tedious
to write by hand.

Results in almost a linear speedup with the number of quadrature points.
  • Loading branch information
fjebaker committed Nov 2, 2024
1 parent 67b2e9f commit 4ce0fc6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/transfer-functions/integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ function quadrature_integrate(f, a::T, b::T; rule = gauss(5)) where {T}
X, W = rule

q = (b - a) / 2
for i in eachindex(X)

total = sum(eachindex(X)) do i
xᵢ = X[i]
wᵢ = W[i]
u = muladd((xᵢ + 1), q, a)
total = muladd(wᵢ, f(u), total)
wᵢ * f(u)
end
total * q
end
Expand Down

0 comments on commit 4ce0fc6

Please sign in to comment.