Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #42670 - error in sparsevec outer product with stored zeros #42671

Merged
merged 1 commit into from
Oct 18, 2021
Merged

Conversation

Keno
Copy link
Member

@Keno Keno commented Oct 16, 2021

The SparseMatrixCSC constructor checks that the passed in buffers
have length matching the expected number of non-zeros, but the
_outer constructor allocated buffers of the number of structural
non-zeros, not actual non-zeros. Fix this by shrinking the buffers
once the outer product is fully computed.

Fixes #42670.

The SparseMatrixCSC constructor checks that the passed in buffers
have length matching the expected number of non-zeros, but the
_outer constructor allocated buffers of the number of structural
non-zeros, not actual non-zeros. Fix this by shrinking the buffers
once the outer product is fully computed.
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?

@dkarrasch dkarrasch added the sparse Sparse arrays label Oct 16, 2021
@Keno Keno merged commit d885fc2 into master Oct 18, 2021
@Keno Keno deleted the kf/42670 branch October 18, 2021 00:22
KristofferC pushed a commit that referenced this pull request Oct 18, 2021
The SparseMatrixCSC constructor checks that the passed in buffers
have length matching the expected number of non-zeros, but the
_outer constructor allocated buffers of the number of structural
non-zeros, not actual non-zeros. Fix this by shrinking the buffers
once the outer product is fully computed.

(cherry picked from commit d885fc2)
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Feb 22, 2022
…ros (JuliaLang#42671)

The SparseMatrixCSC constructor checks that the passed in buffers
have length matching the expected number of non-zeros, but the
_outer constructor allocated buffers of the number of structural
non-zeros, not actual non-zeros. Fix this by shrinking the buffers
once the outer product is fully computed.
LilithHafner pushed a commit to LilithHafner/julia that referenced this pull request Mar 8, 2022
…ros (JuliaLang#42671)

The SparseMatrixCSC constructor checks that the passed in buffers
have length matching the expected number of non-zeros, but the
_outer constructor allocated buffers of the number of structural
non-zeros, not actual non-zeros. Fix this by shrinking the buffers
once the outer product is fully computed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sparse Sparse arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sparse outer product fails for SparseVector with stored zero
4 participants