Skip to content

Commit 765bf1c

Browse files
authored
bugfix: Respect init value in reduction (#366)
1 parent 8affe9e commit 765bf1c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/sparsematrix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ function Base._mapreducedim!(f, op, R::AbstractArray, A::AbstractSparseMatrixCSC
23732373

23742374
if size(R, 1) == size(R, 2) == 1
23752375
# Reduction along both columns and rows
2376-
R[1, 1] = mapreduce(f, op, A)
2376+
R[1, 1] = op(R[1, 1], mapreduce(f, op, A))
23772377
elseif size(R, 1) == 1
23782378
# Reduction along rows
23792379
_mapreducerows!(f, op, R, A)

test/sparsematrix_ops.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ dA = Array(sA)
190190
end
191191
end
192192

193+
for s0 in (spzeros(3, 7), spzeros(1, 3), spzeros(3, 1)), d in (1, 2, 3, (1,2))
194+
@test all(isone, sum(s0, dims=d, init=1.0))
195+
end
196+
193197
for f in (sum, prod, minimum, maximum)
194198
# Test with a map function that maps to non-zero
195199
for arr in (se33, sA, pA)

0 commit comments

Comments
 (0)