Skip to content

Commit 35c8313

Browse files
committed
reducedim as well
1 parent 937b954 commit 35c8313

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

base/reducedim.jl

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -610,26 +610,17 @@ julia> any!([1 1], A)
610610
"""
611611
any!(r, A)
612612

613-
for (fname, op) in [(:sum, :+), (:prod, :*),
613+
for (fname, op) in [(:sum, :add_tosys), (:prod, :mul_tosys),
614614
(:maximum, :scalarmax), (:minimum, :scalarmin),
615615
(:all, :&), (:any, :|)]
616-
function compose_promote_sys_size(x)
617-
if fname === :sum
618-
:(promote_sys_size_add $x)
619-
elseif fname === :prod
620-
:(promote_sys_size_mul $x)
621-
else
622-
x
623-
end
624-
end
625616
fname! = Symbol(fname, '!')
626617
@eval begin
627618
$(fname!)(f::Function, r::AbstractArray, A::AbstractArray; init::Bool=true) =
628619
mapreducedim!(f, $(op), initarray!(r, $(op), init, A), A)
629620
$(fname!)(r::AbstractArray, A::AbstractArray; init::Bool=true) = $(fname!)(identity, r, A; init=init)
630621

631622
$(fname)(f::Function, A::AbstractArray, region) =
632-
mapreducedim($(compose_promote_sys_size(:f)), $(op), A, region)
623+
mapreducedim(f, $(op), A, region)
633624
$(fname)(A::AbstractArray, region) = $(fname)(identity, A, region)
634625
end
635626
end

test/reducedim.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,5 +343,5 @@ under_test = [UInt8, Int8, Int32, Int64, BigInt]
343343
@testset "type of sum(::Array{$T}" for T in under_test
344344
result = sum(T[1 2 3; 4 5 6; 7 8 9], 2)
345345
@test result == hcat([6, 15, 24])
346-
@test eltype(result) === typeof(Base.promote_sys_size_add(zero(T)))
346+
@test eltype(result) === (under_test in (Int64, BigInt) ? under_test : Int)
347347
end

0 commit comments

Comments
 (0)