Skip to content

Commit

Permalink
Fix comprod! to use mul_prod instead of add_sum (#26905)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters authored and ararslan committed Apr 26, 2018
1 parent 9f5351c commit 67fc4fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/accumulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Cumulative product of `A` along the dimension `dims`, storing the result in `B`.
See also [`cumprod`](@ref).
"""
cumprod!(B::AbstractArray{T}, A; dims::Integer) where {T} =
accumulate!(add_sum, B, A, dims=dims)
accumulate!(mul_prod, B, A, dims=dims)

"""
cumprod!(y::AbstractVector, x::AbstractVector)
Expand Down
10 changes: 10 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,16 @@ end
@test cumsum([1 2; 3 4], dims=2) == [1 3; 3 7]
@test cumsum([1 2; 3 4], dims=3) == [1 2; 3 4]

@test cumprod!(Vector{Int}(undef, 1), [5], dims=2) == [5]
@test cumprod!(Matrix{Int}(undef, 2, 2), [1 2; 3 4], dims=3) == [1 2; 3 4]
@test cumprod!(Matrix{Int}(undef, 2, 2), [1 2; 3 4], dims=1) == [1 2; 3 8]
@test cumprod!(Matrix{Int}(undef, 2, 2), [1 2; 3 4], dims=2) == [1 2; 3 12]

@test cumsum!(Vector{Int}(undef, 1), [5], dims=2) == [5]
@test cumsum!(Matrix{Int}(undef, 2, 2), [1 2; 3 4], dims=1) == [1 2; 4 6]
@test cumsum!(Matrix{Int}(undef, 2, 2), [1 2; 3 4], dims=2) == [1 3; 3 7]
@test cumsum!(Matrix{Int}(undef, 2, 2), [1 2; 3 4], dims=3) == [1 2; 3 4]

# issue #18363
@test_throws DimensionMismatch cumsum!([0,0], 1:4)
@test cumsum(Any[])::Vector{Any} == Any[]
Expand Down

0 comments on commit 67fc4fc

Please sign in to comment.