@@ -1439,20 +1439,24 @@ symdiff(a, b, rest...) = symdiff(a, symdiff(b, rest...))
14391439_cumsum_type {T<:Number} (v:: AbstractArray{T} ) = typeof (+ zero (T))
14401440_cumsum_type (v) = typeof (v[1 ]+ v[1 ])
14411441
1442- for (f, fp, op) = ((:cumsum , :cumsum_pairwise , :+ ),
1443- (:cumprod , :cumprod_pairwise , :* ) )
1442+ for (f, fp, op) = ((:cumsum , :cumsum_pairwise! , :+ ),
1443+ (:cumprod , :cumprod_pairwise! , :* ) )
14441444 # in-place cumsum of c = s+v(i1:n), using pairwise summation as for sum
1445- @eval function ($ fp)(v:: AbstractVector , c:: AbstractVector , s, i1, n)
1445+ @eval function ($ fp){T}(v:: AbstractVector , c:: AbstractVector{T} , s, i1, n)
1446+ local s_:: T # for sum(v(i1:n)), i.e. sum without s
14461447 if n < 128
1447- @inbounds c[i1] = ($ op)(s, v[i1])
1448+ @inbounds s_ = v[i1]
1449+ @inbounds c[i1] = ($ op)(s, s_)
14481450 for i = i1+ 1 : i1+ n- 1
1449- @inbounds c[i] = $ (op)(c[i- 1 ], v[i])
1451+ @inbounds s_ = $ (op)(s_, v[i])
1452+ @inbounds c[i] = $ (op)(s, s_)
14501453 end
14511454 else
14521455 n2 = div (n,2 )
1453- ($ fp)(v, c, s, i1, n2)
1454- ( $ fp)(v, c, c[(i1 + n2) - 1 ] , i1+ n2, n- n2)
1456+ s_ = ($ fp)(v, c, s, i1, n2)
1457+ s_ = $ (op)(s_, ( $ fp)(v, c, s + s_ , i1+ n2, n- n2) )
14551458 end
1459+ return s_
14561460 end
14571461
14581462 @eval function ($ f)(v:: AbstractVector )
0 commit comments