From 0b0a61a446869132ebf0885ea5cf39492cecfcd5 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 4 May 2023 07:30:08 -0400 Subject: [PATCH] Remove sum (does pairwise addition?) --- src/gamma_inc.jl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gamma_inc.jl b/src/gamma_inc.jl index d0fb8eb2..5a8b8f5c 100644 --- a/src/gamma_inc.jl +++ b/src/gamma_inc.jl @@ -444,8 +444,11 @@ function gamma_inc_taylor(a::Float64, x::Float64, ind::Integer) sm += t end - # Sum terms from small to large - sm += sum(reverse!(@view wk[1:i])) + # sum terms from small to large + for v ∈ @view wk[i:-1:1] + sm += v + end + p = (rgammax(a, x) / a) * (1.0 + sm) return (p, 1.0 - p) end @@ -486,8 +489,11 @@ function gamma_inc_asym(a::Float64, x::Float64, ind::Integer) sm += t end - # Sum terms from small to large - sm += sum(reverse!(@view wk[1:i])) + # sum terms from small to large + for v ∈ @view wk[i:-1:1] + sm += v + end + q = (rgammax(a, x) / x) * (1.0 + sm) return (1.0 - q, q) end