Fix GPU Cholesky cache initialization for non-square matrices#857
Fix GPU Cholesky cache initialization for non-square matrices#857ChrisRackauckas-Claude wants to merge 4 commits intoSciML:mainfrom
Conversation
When using DefaultLinearSolver with non-square GPU matrices (e.g., for least squares problems), the init_cacheval function for CholeskyFactorization would fail because it tried to compute cholesky(A) on a non-square matrix. The fix checks assumptions.issq before attempting Cholesky factorization and returns nothing for non-square matrices, allowing the DefaultLinearSolver to properly use QRFactorization instead. Fixes SciML/NonlinearSolve.jl#746 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
91c9aec to
854d90f
Compare
Add check for assumptions.issq in the SparseArrays extension's NormalCholeskyFactorization init_cacheval to avoid DimensionMismatch errors when DefaultLinearSolver initializes caches for non-square GPU matrices. This is part of the fix for SciML/NonlinearSolve.jl#746 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Added a second fix for the The previous commit fixed This commit adds the same |
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
CI Status UpdateThe key downstream tests are passing:
The failing tests appear to be pre-existing issues:
GPU tests run on Buildkite separately and will validate the fix for non-square GPU matrices. |
The previous change incorrectly returned nothing for ALL non-square matrices (sparse and GPU), but NormalCholeskyFactorization actually works with non-square matrices because it factors A'*A which is square. The issue was only with GPU arrays where ArrayInterface.cholesky_instance fails for non-square. Sparse CPU arrays handle this correctly. Now the check only applies to GPUArraysCore.AnyGPUArray, allowing sparse CPU matrices to use the original cholesky_instance path. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fix for Non-Square Tests FailureThe previous change incorrectly returned The issue was only with GPU arrays where Fix: Changed the condition to only apply to # Before (incorrect - broke sparse CPU):
elseif !assumptions.issq
nothing
# After (correct - only affects GPU):
elseif A isa LinearSolve.GPUArraysCore.AnyGPUArray && !assumptions.issq
nothing |
✅ All Core Tests PassingAfter the fix to only apply the non-square check to GPU arrays (not sparse CPU arrays), all Core tests are now passing:
The only remaining failures are pre-existing infrastructure issues:
Summary of changes:
The fix allows |
Summary
Fixes SciML/NonlinearSolve.jl#746
When using
DefaultLinearSolverwith non-square GPU matrices (e.g., for least squares problems in NonlinearSolve.jl), theinit_cachevalfunction forCholeskyFactorizationwould fail withDimensionMismatch: matrix is not squarebecause it tried to computecholesky(A)on a non-square matrix.Root Cause
The
@generatedinit_cachevalforDefaultLinearSolverinitializes caches for all possible algorithms upfront, includingCholeskyFactorization. For non-square GPU matrices, this fails even thoughCholeskyFactorizationwould never actually be used (thedefaultalgfunction correctly selectsQRFactorizationfor non-square matrices).Fix
The fix checks
assumptions.issqbefore attempting Cholesky factorization ininit_cacheval(::CholeskyFactorization, ::GPUArraysCore.AnyGPUArray, ...)and returnsnothingfor non-square matrices, allowing the cache initialization to succeed.Changes
src/factorization.jl: Added square matrix check ininit_cachevalforCholeskyFactorizationwith GPU arraystest/gpu/cuda.jl: Added tests for non-square GPU matrices (overdetermined and underdetermined systems)Test plan
🤖 Generated with Claude Code