Skip to content

Commit

Permalink
Test some missing arrayops methods (#29813)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt authored and ararslan committed Oct 26, 2018
1 parent 010495f commit 665a69d
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2105,38 +2105,38 @@ let f = OOB_Functor([1,2])
@test_throws BoundsError map(f, [1,2,3,4,5])
end

# issue 15654
@test cumprod([5], dims=2) == [5]
@test cumprod([1 2; 3 4], dims=3) == [1 2; 3 4]
@test cumprod([1 2; 3 4], dims=1) == [1 2; 3 8]
@test cumprod([1 2; 3 4], dims=2) == [1 2; 3 12]

@test cumsum([5], dims=2) == [5]
@test cumsum([1 2; 3 4], dims=1) == [1 2; 4 6]
@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[]
@test cumsum(Any[1, 2.3]) == [1, 3.3] == cumsum(Real[1, 2.3])::Vector{Real}
@test cumsum([true,true,true]) == [1,2,3]
@test cumsum(0x00:0xff)[end] === UInt(255*(255+1)÷2) # no overflow
@test accumulate(+, 0x00:0xff)[end] === 0x80 # overflow
@test_throws InexactError cumsum!(similar(0x00:0xff), 0x00:0xff) # overflow

@test cumsum([[true], [true], [false]])::Vector{Vector{Int}} == [[1], [2], [2]]

@testset "issue 15654" begin
@test cumprod([5], dims=2) == [5]
@test cumprod([1 2; 3 4], dims=3) == [1 2; 3 4]
@test cumprod([1 2; 3 4], dims=1) == [1 2; 3 8]
@test cumprod([1 2; 3 4], dims=2) == [1 2; 3 12]

@test cumsum([5], dims=2) == [5]
@test cumsum([1 2; 3 4], dims=1) == [1 2; 4 6]
@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]
end
@testset "issue #18363" begin
@test_throws DimensionMismatch cumsum!([0,0], 1:4)
@test cumsum(Any[])::Vector{Any} == Any[]
@test cumsum(Any[1, 2.3]) == [1, 3.3] == cumsum(Real[1, 2.3])::Vector{Real}
@test cumsum([true,true,true]) == [1,2,3]
@test cumsum(0x00:0xff)[end] === UInt(255*(255+1)÷2) # no overflow
@test accumulate(+, 0x00:0xff)[end] === 0x80 # overflow
@test_throws InexactError cumsum!(similar(0x00:0xff), 0x00:0xff) # overflow

@test cumsum([[true], [true], [false]])::Vector{Vector{Int}} == [[1], [2], [2]]
end
#issue #18336
@test cumsum([-0.0, -0.0])[1] === cumsum([-0.0, -0.0])[2] === -0.0
@test cumprod(-0.0im .+ (0:0))[1] === Complex(0.0, -0.0)
Expand Down Expand Up @@ -2306,6 +2306,8 @@ end

@test accumulate(min, [1, 2, 5, -1, 3, -2]) == [1, 1, 1, -1, -1, -2]
@test accumulate(max, [1, 2, 5, -1, 3, -2]) == [1, 2, 5, 5, 5, 5]
@test Base.accumulate_pairwise(min, [1, 2, 5, -1, 3, -2]) == [1, 1, 1, -1, -1, -2]
@test Base.accumulate_pairwise(max, [1, 2, 5, -1, 3, -2]) == [1, 2, 5, 5, 5, 5]

@test accumulate(max, [1 0; 0 1], dims=1) == [1 0; 1 1]
@test accumulate(max, [1 0; 0 1], dims=2) == [1 1; 0 1]
Expand Down Expand Up @@ -2337,6 +2339,9 @@ end
@test out accumulate_arr
end
end
arr_cop = similar(arr)
cumprod!(arr_cop, arr)
@test arr_cop cumprod(arr)
end

# exotic indexing
Expand Down

0 comments on commit 665a69d

Please sign in to comment.