Skip to content

Commit 1877e6b

Browse files
committed
Test dimensional reductions
1 parent 3e9f908 commit 1877e6b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

base/reducedim.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ reducedim_init(f, op::typeof(|), A::AbstractArray, region) = reducedim_initarray
117117
# specialize to make initialization more efficient for common cases
118118

119119
let
120-
const BitIntFloat = Union{BitInteger, Math.IEEEFloat}
121-
const T = Union{
120+
BitIntFloat = Union{BitInteger, Math.IEEEFloat}
121+
T = Union{
122122
[AbstractArray{t} for t in uniontypes(BitIntFloat)]...,
123123
[AbstractArray{Complex{t}} for t in uniontypes(BitIntFloat)]...}
124124

@@ -586,7 +586,6 @@ for (fname, op) in [(:sum, :+), (:prod, :*),
586586
end
587587
fname! = Symbol(fname, '!')
588588
@eval begin
589-
# TODO: check this
590589
$(fname!)(f::Function, r::AbstractArray, A::AbstractArray; init::Bool=true) =
591590
mapreducedim!(f, $(op), initarray!(r, $(op), init), A)
592591
$(fname!)(r::AbstractArray, A::AbstractArray; init::Bool=true) = $(fname!)(identity, r, A; init=init)

test/reducedim.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,11 @@ for region in Any[-1, 0, (-1, 2), [0, 1], (1,-2,3), [0 1;
154154
@test_throws ArgumentError maximum(abs, Areduc, region)
155155
@test_throws ArgumentError minimum(abs, Areduc, region)
156156
end
157+
158+
# check type of result
159+
under_test = [UInt8, Int8, Int32, Int64, BigInt]
160+
@testset "type of sum(::Array{$T}" for T in under_test
161+
result = sum(T[1 2 3; 4 5 6; 7 8 9], 2)
162+
@test result == hcat([6, 15, 24])
163+
@test eltype(result) === typeof(promote_sys_size(zero(T)))
164+
end

0 commit comments

Comments
 (0)