Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions stdlib/SparseArrays/src/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -840,20 +840,28 @@ function _outer(trans::Tf, x, y) where Tf
@inbounds colptrC[1] = 1
@inbounds for jj = 1:nnzy
yval = nzvalsy[jj]
iszero(yval) && continue
if iszero(yval)
nnzC -= nnzx
continue
end
col = rowvaly[jj]
yval = trans(yval)

for ii = 1:nnzx
xval = nzvalsx[ii]
iszero(xval) && continue
if iszero(xval)
nnzC -= 1
continue
end
idx += 1
colptrC[col+1] += 1
rowvalC[idx] = rowvalx[ii]
nzvalsC[idx] = xval * yval
end
end
cumsum!(colptrC, colptrC)
resize!(rowvalC, nnzC)
resize!(nzvalsC, nnzC)

return SparseMatrixCSC(nx, ny, colptrC, rowvalC, nzvalsC)
end
Expand Down
9 changes: 9 additions & 0 deletions stdlib/SparseArrays/test/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -726,4 +726,13 @@ end
@test extrema(x; dims=[]) == extrema(y; dims=[])
end

@testset "issue #42670 - error in sparsevec outer product" begin
A = spzeros(Int, 4)
B = copy(A)
C = sparsevec([0 0 1 1 0 0])'
A[2] = 1
A[2] = 0
@test A * C == B * C == spzeros(Int, 4, 6)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test seems to be insufficiently specific as it passes even on v1.6. Perhaps we should include a test like this?

Suggested change
@test A * C == B * C == spzeros(Int, 4, 6)
@test A * C == B * C == spzeros(Int, 4, 6)
@test length(nonzeros(A * C)) == length(nonzeros(B * C)) == 0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test doesn't test what I care about. I'm fine if the outer product doesn't drop non-structural zeros. If this test passes on 1.6, then this is just a regression, since it doesn't pass (as in throws an error) on master with the error message referenced in the issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, your test fails since v1.7. Shall we backport this to v1.7 then?

end

end # module