Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed May 8, 2019
1 parent 7f364f4 commit f51d8db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,12 @@ function _sum!(f, R::AbstractArray, A::AbstractArray{T,N}, w::AbstractArray;
check_reducedims(R,A)
reddims = size(R) .!= size(A)
dim = something(findfirst(reddims), ndims(R)+1)
if dim > N
dim1 = findfirst(==(1), size(A))
if dim1 !== nothing
dim = dim1
end
end
if findnext(reddims, dim+1) !== nothing
throw(ArgumentError("reducing over more than one dimension is not supported with weights"))
end
Expand Down
3 changes: 3 additions & 0 deletions test/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ end
end
end

# Corner case with a single row
@test sum([1 2], weights=[2], dims=1) == [2 4]

@test_throws ArgumentError sum(exp, [1 2], weights=[1, 10], dims=1)
@test_throws ArgumentError sum([1 2], weights=[1 10], dims=1)
end

0 comments on commit f51d8db

Please sign in to comment.