Repository navigation
Propagate NaN and Inf to the unstored entries in sparse rmul!, lmul! and mul! - #1101
Merged
Merged
Conversation
…l!` and `mul!` `0 * NaN` and `0 * Inf` are NaN, so scaling only the stored values gives a different result from the dense array and from the out-of-place `A * b`. As `rdiv!` and `ldiv!` already do, fall back to `broadcast!` when the implicit zero would not stay zero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1101 +/- ##
==========================================
- Coverage 94.82% 94.82% -0.01%
==========================================
Files 16 16
Lines 10236 10234 -2
==========================================
- Hits 9706 9704 -2
Misses 530 530 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scaling a sparse matrix or vector in place by a number scales only the stored values, so an entry that is not stored stays zero when the number is NaN or infinite, although
0 * NaNand0 * Infare NaN. The dense array, the out-of-place matrixB * NaNand thermul!docstring all give NaN. The out-of-place vectorx * NaNhas the same bug.Before
After
The fix mirrors
rdiv!andldiv!by a number, which already handle0 / 0.rmul!andlmul!on a sparse matrix, a sparse vector and a column view,mul!(C, A, b)andmul!(C, b, A), and the vectorx * aanda * xkeep scaling the stored values when the implicit zero times the number is zero (or every entry is stored), and otherwise go throughbroadcast!or broadcast, which store the new entries. A fixed-pattern destination therefore throwsArgumentErrorwith nothing written, asrdiv!does. The implicit zero is taken from_implicit_zero, so an eltype without azero(Any, a matrix type) keeps scaling its stored values instead of throwing. The finite case is unchanged (minimum of@benchmark, Apple silicon, nightly):mainrmul!(A, 2.0), 10⁴×10⁴, nnz 1.0e5mul!(C, A, 2.0), samermul!(A, 2.0), 100×100, nnz 490x * 2.0, nnz 93rmul!(view(A, :, 1), 2.0)Left out: products with a
Diagonal(or a dense vector) that holds NaN or Inf still skip the entries that are not stored, as all sparse products do; that is a separate question from scaling by a number.rdiv!andldiv!on an eltype without azerostill throw, as onmain.Authored with Claude Code.
🤖 Generated with Claude Code