Skip to content

Conversation

ChrisRackauckas-Claude
Copy link
Contributor

Summary

  • Fixes KLUFactorization fails with AbstractSparseMatrixCSC #737 by properly handling AbstractSparseMatrixCSC subtypes in KLUFactorization
  • Adds check for uninitialized or dimension-mismatched cached values before attempting reuse
  • Ensures compatibility with custom sparse matrix types that implement the AbstractSparseMatrixCSC interface

Problem

KLUFactorization was failing with AbstractSparseMatrixCSC subtypes while UMFPACK, Sparspak, and Pardiso worked correctly. The issue occurred when:

  1. The cached value was PREALLOCATED_KLU (a 0x0 matrix)
  2. pattern_changed returned false for this case
  3. klu! was called with mismatched dimensions, causing a DimensionMismatch error

Solution

Added a check before calling klu! to verify:

  • The cacheval is not nothing or PREALLOCATED_KLU
  • The dimensions match between the cached value and the input matrix

If either condition fails, a new factorization is created instead of attempting to reuse the incompatible cached value.

Test plan

🤖 Generated with Claude Code

Fixes SciML#737 by handling the case where the cached KLU factorization is
uninitialized (PREALLOCATED_KLU) or has a dimension mismatch with the
input matrix.

The issue occurred when using AbstractSparseMatrixCSC subtypes because:
1. The cacheval would be set to PREALLOCATED_KLU (a 0x0 matrix)
2. pattern_changed would return false for this case
3. klu! would be called with mismatched dimensions, causing an error

The fix checks if the cacheval is uninitialized or has a size mismatch,
and creates a new factorization in those cases instead of trying to
reuse the incompatible cached value.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KLUFactorization fails with AbstractSparseMatrixCSC
3 participants