Skip to content

Fix isone for sparse matrices with stored zeros - #764

Merged
ViralBShah merged 1 commit into
mainfrom
vs/isone-stored-zeros
Sep 7, 2026
Merged

Fix isone for sparse matrices with stored zeros#764
ViralBShah merged 1 commit into
mainfrom
vs/isone-stored-zeros

Conversation

@ViralBShah

Copy link
Copy Markdown
Member

isone(A::AbstractSparseMatrixCSC) only validated the stored entries it encountered and used nnz(A) >= n as a proxy for "every column has a diagonal entry". A matrix with a stored zero and a missing diagonal entry therefore passed:

julia> M = sparse([1 0; 1 1]) * sparse([1 0; -1 0])
2×2 SparseMatrixCSC{Int64, Int64} with 2 stored entries:
 1  
 0  

julia> isone(M)
true

This PR tracks, per column, whether a stored diagonal entry equal to one was seen, and returns false otherwise. Added regression tests covering the issue's example, stored zeros on and off the diagonal, and a missing diagonal entry.

Fixes #763

🤖 Generated with Claude Code

https://claude.ai/code/session_01XzN6CtuVBJWDVc88ShNYso

`isone(A::AbstractSparseMatrixCSC)` only validated the stored entries it
encountered and relied on `nnz(A) >= n` as a proxy for "every column has
a diagonal entry". A matrix with a stored zero and a missing diagonal
entry therefore passed, e.g. `sparse([1 0; 1 1]) * sparse([1 0; -1 0])`.

Track per column whether a stored diagonal entry equal to one was seen,
and return `false` otherwise.

Fixes #763

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XzN6CtuVBJWDVc88ShNYso
@ViralBShah ViralBShah added the backport 1.13 Change should be backported to release-1.13 label Sep 7, 2026
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.01%. Comparing base (4ba7b1c) to head (6394e8e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #764      +/-   ##
==========================================
+ Coverage   83.99%   84.01%   +0.02%     
==========================================
  Files          13       13              
  Lines        9366     9378      +12     
==========================================
+ Hits         7867     7879      +12     
  Misses       1499     1499              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ViralBShah
ViralBShah merged commit 4ce0756 into main Sep 7, 2026
12 checks passed
@ViralBShah
ViralBShah deleted the vs/isone-stored-zeros branch September 7, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.13 Change should be backported to release-1.13

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Function isone returns true for matrices that are not one

1 participant