Skip to content

Commit

Permalink
Fix #7095, sum along first dimension broken for size(A, 1) >= 16
Browse files Browse the repository at this point in the history
This was broken by #7061. I have added a test to avoid future breakage.
  • Loading branch information
simonster committed Jun 3, 2014
1 parent efd837e commit 86c7783
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 86c7783

Please sign in to comment.