@@ -92,14 +92,14 @@ function cumsum(A::AbstractArray{T}; dims::Integer) where T
9292end
9393
9494"""
95- cumsum(itr::Union{AbstractVector,Tuple} )
95+ cumsum(itr)
9696
9797Cumulative sum an iterator. See also [`cumsum!`](@ref)
9898to use a preallocated output array, both for performance and to control the precision of the
9999output (e.g. to avoid overflow).
100100
101101!!! compat "Julia 1.5"
102- `cumsum` on a tuple requires at least Julia 1.5.
102+ `cumsum` on a non-array iterator requires at least Julia 1.5.
103103
104104# Examples
105105```jldoctest
@@ -117,6 +117,12 @@ julia> cumsum([fill(1, 2) for i in 1:3])
117117
118118julia> cumsum((1, 1, 1))
119119(1, 2, 3)
120+
121+ julia> cumsum(x^2 for x in 1:3)
122+ 3-element Array{Int64,1}:
123+ 1
124+ 5
125+ 14
120126```
121127"""
122128cumsum (x:: AbstractVector ) = cumsum (x, dims= 1 )
@@ -170,14 +176,14 @@ function cumprod(A::AbstractArray; dims::Integer)
170176end
171177
172178"""
173- cumprod(itr::Union{AbstractVector,Tuple} )
179+ cumprod(itr)
174180
175181Cumulative product of an iterator. See also
176182[`cumprod!`](@ref) to use a preallocated output array, both for performance and
177183to control the precision of the output (e.g. to avoid overflow).
178184
179185!!! compat "Julia 1.5"
180- `cumprod` on a tuple requires at least Julia 1.5.
186+ `cumprod` on a non-array iterator requires at least Julia 1.5.
181187
182188# Examples
183189```jldoctest
@@ -195,6 +201,12 @@ julia> cumprod([fill(1//3, 2, 2) for i in 1:3])
195201
196202julia> cumprod((1, 2, 1))
197203(1, 2, 2)
204+
205+ julia> cumprod(x^2 for x in 1:3)
206+ 3-element Array{Int64,1}:
207+ 1
208+ 4
209+ 36
198210```
199211"""
200212cumprod (x:: AbstractVector ) = cumprod (x, dims= 1 )
@@ -210,6 +222,9 @@ also [`accumulate!`](@ref) to use a preallocated output array, both for performa
210222to control the precision of the output (e.g. to avoid overflow). For common operations
211223there are specialized variants of `accumulate`, see: [`cumsum`](@ref), [`cumprod`](@ref)
212224
225+ !!! compat "Julia 1.5"
226+ `accumulate` on a non-array iterator requires at least Julia 1.5.
227+
213228# Examples
214229```jldoctest
215230julia> accumulate(+, [1,2,3])
@@ -250,6 +265,10 @@ julia> accumulate(+, fill(1, 3, 3), dims=2)
250265```
251266"""
252267function accumulate (op, A; dims:: Union{Nothing,Integer} = nothing , kw... )
268+ if dims === nothing && ! (A isa AbstractVector)
269+ # This branch takes care of the cases not handled by `_accumulate!`.
270+ return collect (Iterators. accumulate (op, A; kw... ))
271+ end
253272 nt = kw. data
254273 if nt isa NamedTuple{()}
255274 out = similar (A, promote_op (op, eltype (A), eltype (A)))
0 commit comments