|
731 | 731 | @test_broken @inferred(maximum(exp, A; dims = 1))[1] === missing |
732 | 732 | @test_broken @inferred(extrema(exp, A; dims = 1))[1] === (missing, missing) |
733 | 733 | end |
| 734 | + |
| 735 | +some_exception(op) = try return (Some(op()), nothing); catch ex; return (nothing, ex); end |
| 736 | +reduced_shape(sz, dims) = ntuple(d -> d in dims ? 1 : sz[d], length(sz)) |
| 737 | + |
| 738 | +@testset "Ensure that calling, e.g., sum(empty; dims) has the same behavior as sum(empty)" begin |
| 739 | + @testset "$r(Array{$T}(undef, $sz); dims=$dims)" for |
| 740 | + r in (minimum, maximum, findmin, findmax, extrema, sum, prod, mapreduce, all, any, count), |
| 741 | + T in (Int, Union{Missing, Int}, Number, Union{Missing, Number}, Bool, Union{Missing, Bool}, Any), |
| 742 | + sz in ((0,), (0,1), (1,0), (0,0), (0,0,1), (1,0,1)), |
| 743 | + dims in (1, 2, 3, 4, (1,2), (1,3), (2,3,4), (1,2,3)) |
| 744 | + |
| 745 | + A = Array{T}(undef, sz) |
| 746 | + rsz = reduced_shape(sz, dims) |
| 747 | + |
| 748 | + v, ex = some_exception() do; r(A); end |
| 749 | + if isnothing(v) |
| 750 | + @test_throws typeof(ex) r(A; dims) |
| 751 | + else |
| 752 | + actual = fill(something(v), rsz) |
| 753 | + @test isequal(r(A; dims), actual) |
| 754 | + @test eltype(r(A; dims)) === eltype(actual) |
| 755 | + end |
| 756 | + |
| 757 | + for f in (identity, abs, abs2) |
| 758 | + v, ex = some_exception() do; r(f, A); end |
| 759 | + if isnothing(v) |
| 760 | + @test_throws typeof(ex) r(f, A; dims) |
| 761 | + else |
| 762 | + actual = fill(something(v), rsz) |
| 763 | + @test isequal(r(f, A; dims), actual) |
| 764 | + @test eltype(r(f, A; dims)) === eltype(actual) |
| 765 | + end |
| 766 | + end |
| 767 | + end |
| 768 | +end |
0 commit comments