Repository navigation
Fix \ for sparse matrices with LayoutArray right-hand sides - #288
Merged
Merged
Conversation
`\` with a sparse matrix (or its Adjoint/Transpose) and a LayoutVector,
LayoutMatrix, Diagonal{<:LayoutVector} or triangular LayoutMatrix right-hand side
was ambiguous between SparseArrays and the @layoutldiv overloads.
Symmetric/Hermitian sparse matrices errored for LayoutArrays whose copy is not
strided, since CHOLMOD does not support ldiv! with such arrays.
Resolve both by converting the right-hand side to an Array and calling
SparseArrays' solver.
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 @@
## master #288 +/- ##
==========================================
+ Coverage 90.33% 90.57% +0.24%
==========================================
Files 12 12
Lines 1987 2038 +51
==========================================
+ Hits 1795 1846 +51
Misses 192 192 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
A \ Bfails whenAis a sparse matrix andBis aLayoutArray. Found via BlockArrays.jl, wheresparse_matrix \ BlockedVectorfails.Ambiguity. For
Aa sparse matrix, itsAdjointor itsTranspose,A \ Bis ambiguous between SparseArrays'\(::AbstractSparseMatrixCSC / AdjOrTrans{sparse}, ::AbstractVecOrMat)and the\(::AbstractMatrix, ::Typ)methods from@layoutldiv.Bhere is aLayoutVector, aLayoutMatrix, aDiagonal{<:LayoutVector}, or a triangular wrapper of aLayoutMatrix(or of its view, adjoint or transpose).CHOLMOD. For
AaSymmetric/Hermitiansparse matrix,A \ Bgoes throughArrayLayouts.ldiv. That ends inldiv!(::CHOLMOD.Factor, ...), which CHOLMOD does not support. It fails whenevercopy(B)is not a strided array, e.g.BlockedVector, or theMyVector/MyMatrixtest types:Fix
In
ArrayLayoutsSparseArraysExt, define\for each of these sparse matrix types against each layout right-hand side type. Each method convertsBto anArrayand calls SparseArrays' solver, which requires strided arrays anyway. ADiagonal{<:LayoutVector}keeps itsDiagonalwrapper, with only the diagonal converted.This removes all 57
\ambiguities between ArrayLayouts and SparseArrays that have a sparse matrix on the left. 48 ambiguities in the other direction remain: a triangular layout matrix\a sparse vector or matrix. They're not touched here.Tests
sparse/ldivtestset intest_layoutarray.jlcovering every combination. It errors without the fix.Adjoint,Transpose,SymmetricandHermitianmatricesBlockedVector,BlockVector,BlockedMatrixandBlockMatrixright-hand sides.Version bumped to 1.15.1.
🤖 Generated with Claude Code