Skip to content

Commit 2f34b50

Browse files
committed
remove an accidentally quadratic algorithm
1 parent 276b51b commit 2f34b50

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/rulesets/Base/mapreduce.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,10 @@ end
312312
@inline function ∇cumprod!(dx::AbstractVector, x::AbstractVector, dy, y)
313313
lo, hi = firstindex(x), lastindex(x)
314314
z = something(findfirst(iszero, x), hi+1)
315-
@inbounds for i in lo:z-1
316-
ixi = 1/x[i]
317-
for k in i:z-1
318-
dx[i] += y[k] * dy[k] * ixi
319-
end
315+
acc = zero(eltype(dy))
316+
@inbounds for k in z-1:-1:lo
317+
acc += y[k] * dy[k]
318+
dx[k] += acc / x[k]
320319
end
321320
@inbounds if z != hi+1
322321
yk = z==1 ? one(eltype(y)) : y[z-1] # will be prod(x[j] for j=1:k if j!=z)

0 commit comments

Comments
 (0)