Repository navigation
Match dense isequal with a lazy adjoint of a sparse array - #1189
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ViralBShah
force-pushed
the
vs/isequal-lazy-adjoint
branch
from
November 22, 2026 14:42
877c3cf to
193b6d1
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1189 +/- ##
==========================================
- Coverage 98.97% 98.96% -0.01%
==========================================
Files 16 16
Lines 10759 10770 +11
==========================================
+ Hits 10649 10659 +10
- Misses 110 111 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
10 tasks done
ViralBShah
added a commit
that referenced
this pull request
Nov 22, 2026
Fixes #1185. `isequal` with a lazy adjoint of a sparse matrix or vector disagrees with dense `isequal` in both directions, and is true for some pairs whose hashes differ. Julia 1.13 agrees with dense; 1.14.0-beta1 and nightly do not, since #985. **Before** ```julia julia> Z = spzeros(ComplexF64, 2, 2); julia> isequal(Z, Z'), isequal(spzeros(2, 2), Z') # dense: (false, false) (true, true) julia> A = sparse([1], [1], [1]); B = sparse([1], [1], [1.0 + 0.0im]); julia> isequal(A', B), isequal(B, A'), isequal(A', B') # dense: (true, true, false) (false, false, true) julia> x = sparsevec([1], [1]); y = sparsevec([1], [1.0 + 0.0im]); julia> isequal(x', y') # dense: false true ``` **After** ```julia julia> isequal(Z, Z'), isequal(spzeros(2, 2), Z') (false, false) julia> isequal(A', B), isequal(B, A'), isequal(A', B') (true, true, false) julia> isequal(x', y') false ``` The adjoint of a complex zero is `0.0 - 0.0im`, which `isequal` tells from `0.0 + 0.0im`, and `isequal(1, 1.0 + 0.0im)` holds but `isequal(1, 1.0 - 0.0im)` does not. Three places conjugated the wrong side. The comparison of a matrix with a lazy adjoint took the implicit zero of the adjoint's parent, in its check and in the merge it falls back to. Its search over the adjoint's stored entries conjugated the other matrix's entries instead of the adjoint's own. And `isequal` with an adjoint as the first argument, of matrices or of vectors, compared `A'` with `B'`, conjugating both sides. Now a wrapper applies to its own side only: to the implicit zero of its parent, and to its own entries, while the other matrix is only indexed with its indices swapped. `isequal` with an adjoint first compares `A'` and `B'` by `isequal` of the adjoints of their entries. `==`, which conjugating both sides does not change, keeps its path. Over every pair of 30 small sparse matrices with `Int`, `Float64`, `ComplexF64` and `ComplexF32` entries, signed zeros, `NaN` and stored zeros, each without a wrapper, under `adjoint` or `transpose`, or under both nested, `isequal` and `==` now agree with dense: 972 of the 88,200 comparisons differed on `main`. In a smaller sweep, the 40 pairs that were `isequal` with different hashes no longer are. With a complex eltype `isequal(A, B')` now finds the implicit zeros unequal, so it merges `A` with the sparse transpose of `B'` instead of searching `B'` for each stored entry. That allocates a copy of `B`, and for 10⁴×10⁴ matrices with 10⁵ stored entries it takes 0.29 ms where the search took 3.2 ms. The other comparisons keep their path and time. Should be backported to 1.14, which has #985. Left out: `==`, and `isequal` of real matrices, still compare a matrix with a lazy adjoint by that search, which on those matrices takes 3.1 ms where the transpose and a full merge take 0.48 ms. Written with Claude Code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) (cherry picked from commit 355782e)
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.
Fixes #1185.
isequalwith a lazy adjoint of a sparse matrix or vector disagrees with denseisequalin both directions, and is true for some pairs whose hashes differ. Julia 1.13 agrees with dense; 1.14.0-beta1 and nightly do not, since #985.Before
After
The adjoint of a complex zero is
0.0 - 0.0im, whichisequaltells from0.0 + 0.0im, andisequal(1, 1.0 + 0.0im)holds butisequal(1, 1.0 - 0.0im)does not. Three places conjugated the wrong side. The comparison of a matrix with a lazy adjoint took the implicit zero of the adjoint's parent, in its check and in the merge it falls back to. Its search over the adjoint's stored entries conjugated the other matrix's entries instead of the adjoint's own. Andisequalwith an adjoint as the first argument, of matrices or of vectors, comparedA'withB', conjugating both sides. Now a wrapper applies to its own side only: to the implicit zero of its parent, and to its own entries, while the other matrix is only indexed with its indices swapped.isequalwith an adjoint first comparesA'andB'byisequalof the adjoints of their entries.==, which conjugating both sides does not change, keeps its path.Over every pair of 30 small sparse matrices with
Int,Float64,ComplexF64andComplexF32entries, signed zeros,NaNand stored zeros, each without a wrapper, underadjointortranspose, or under both nested,isequaland==now agree with dense: 972 of the 88,200 comparisons differed onmain. In a smaller sweep, the 40 pairs that wereisequalwith different hashes no longer are.With a complex eltype
isequal(A, B')now finds the implicit zeros unequal, so it mergesAwith the sparse transpose ofB'instead of searchingB'for each stored entry. That allocates a copy ofB, and for 10⁴×10⁴ matrices with 10⁵ stored entries it takes 0.29 ms where the search took 3.2 ms. The other comparisons keep their path and time.Should be backported to 1.14, which has #985.
Left out:
==, andisequalof real matrices, still compare a matrix with a lazy adjoint by that search, which on those matrices takes 3.1 ms where the transpose and a full merge take 0.48 ms.Written with Claude Code.
🤖 Generated with Claude Code