@@ -1455,20 +1455,24 @@ symdiff(a, b, rest...) = symdiff(a, symdiff(b, rest...))
1455
1455
_cumsum_type {T<:Number} (v:: AbstractArray{T} ) = typeof (+ zero (T))
1456
1456
_cumsum_type (v) = typeof (v[1 ]+ v[1 ])
1457
1457
1458
- for (f, fp, op) = ((:cumsum , :cumsum_pairwise , :+ ),
1459
- (:cumprod , :cumprod_pairwise , :* ) )
1460
- # in-place cumsum of c = s+v(i1:n), using pairwise summation as for sum
1461
- @eval function ($ fp)(v:: AbstractVector , c:: AbstractVector , s, i1, n)
1458
+ for (f, fp, op) = ((:cumsum , :cumsum_pairwise! , :+ ),
1459
+ (:cumprod , :cumprod_pairwise! , :* ) )
1460
+ # in-place cumsum of c = s+v[range(i1,n)], using pairwise summation
1461
+ @eval function ($ fp){T}(v:: AbstractVector , c:: AbstractVector{T} , s, i1, n)
1462
+ local s_:: T # for sum(v[range(i1,n)]), i.e. sum without s
1462
1463
if n < 128
1463
- @inbounds c[i1] = ($ op)(s, v[i1])
1464
+ @inbounds s_ = v[i1]
1465
+ @inbounds c[i1] = ($ op)(s, s_)
1464
1466
for i = i1+ 1 : i1+ n- 1
1465
- @inbounds c[i] = $ (op)(c[i- 1 ], v[i])
1467
+ @inbounds s_ = $ (op)(s_, v[i])
1468
+ @inbounds c[i] = $ (op)(s, s_)
1466
1469
end
1467
1470
else
1468
- n2 = div (n, 2 )
1469
- ($ fp)(v, c, s, i1, n2)
1470
- ( $ fp)(v, c, c[(i1 + n2) - 1 ] , i1+ n2, n- n2)
1471
+ n2 = n >> 1
1472
+ s_ = ($ fp)(v, c, s, i1, n2)
1473
+ s_ = $ (op)(s_, ( $ fp)(v, c, s + s_ , i1+ n2, n- n2) )
1471
1474
end
1475
+ return s_
1472
1476
end
1473
1477
1474
1478
@eval function ($ f)(v:: AbstractVector )
0 commit comments