diff --git a/base/reducedim.jl b/base/reducedim.jl index 0f9bbb49ab9f2..5e562ace3f1e8 100644 --- a/base/reducedim.jl +++ b/base/reducedim.jl @@ -142,7 +142,7 @@ end sz1 = size(A, 1) if size(R, 1) < sz1 && sz1 >= 16 && rdims == 1 for i = 1:div(length(A), sz1) - @inbounds R[i] = sum_impl(f, A, (i-1)*sz1+1, i*sz1) + @inbounds R[i] = mapreduce_impl(f, AddFun(), A, (i-1)*sz1+1, i*sz1) end else @nloops N i A d->(j_d = sizeR_d==1 ? 1 : i_d) begin diff --git a/test/reducedim.jl b/test/reducedim.jl index 556424cbe0e3e..2d35070c35fb7 100644 --- a/test/reducedim.jl +++ b/test/reducedim.jl @@ -32,6 +32,17 @@ for region in { @test_approx_eq Base.sumabs2(Areduc, region) safe_sumabs2(Areduc, region) end +# Test reduction along first dimension; this is special-cased for +# size(A, 1) >= 16 +Breduc = rand(64, 3) +r = fill(NaN, Base.reduced_dims(size(Breduc), 1)) +@test_approx_eq sum!(r, Breduc) safe_sum(Breduc, 1) +@test_approx_eq Base.sumabs!(r, Breduc) safe_sumabs(Breduc, 1) +@test_approx_eq Base.sumabs2!(r, Breduc) safe_sumabs2(Breduc, 1) +@test_approx_eq sum(Breduc, 1) safe_sum(Breduc, 1) +@test_approx_eq Base.sumabs(Breduc, 1) safe_sumabs(Breduc, 1) +@test_approx_eq Base.sumabs2(Breduc, 1) safe_sumabs2(Breduc, 1) + @test reducedim((a,b) -> a|b, [true false; false false], 1, false) == [true false] R = reducedim((a,b) -> a+b, [1 2; 3 4], 2, 0.0) @test eltype(R) == Float64