Skip to content

Conversation

ChrisRackauckas-Claude
Copy link
Contributor

Summary

This PR adds comprehensive allocation tests for the caching interface in LinearSolve.jl to ensure that the caching mechanism doesn't allocate unnecessarily when reusing factorizations, as documented in https://docs.sciml.ai/LinearSolve/stable/tutorials/caching_interface/

Changes

  • Added test/nopre/caching_allocation_tests.jl with comprehensive allocation tests
  • Updated test/nopre/Project.toml to include AllocCheck.jl for allocation testing
  • Added the new test file to test/runtests.jl in the NoPre test group

Test Coverage

The tests verify allocation-free behavior for:

Dense Factorizations

  • LUFactorization
  • QRFactorization
  • CholeskyFactorization
  • SVDFactorization
  • BunchKaufmanFactorization
  • NormalCholeskyFactorization
  • DiagonalFactorization

Sparse Factorizations

  • KLUFactorization
  • UMFPACKFactorization
  • CHOLMODFactorization

Iterative Solvers

  • SimpleGMRES
  • KrylovJL_GMRES
  • KrylovJL_CG
  • KrylovJL_BICGSTAB

Key Test Scenarios

  1. Allocation-free solving with different b vectors - Verifies that changing only the right-hand side vector and resolving doesn't allocate after initial factorization
  2. Matrix change triggers refactorization - Ensures that changing the matrix properly triggers refactorization (allocations expected)
  3. Non-square matrix handling - Tests overdetermined and underdetermined systems with appropriate residual checks
  4. Performance comparison - Compares caching vs non-caching approaches to verify the benefit

Implementation Notes

  • Uses @check_allocs from AllocCheck.jl to verify zero allocations
  • Some algorithms may still allocate in certain Julia versions (marked as @test_broken where appropriate)
  • Tests follow the caching interface pattern: initsolve\! → modify cache.bsolve\! again

Test Results

All tests pass successfully, with some expected @test_broken for algorithms that haven't been optimized for zero allocations yet.

🤖 Generated with Claude Code

This commit adds comprehensive allocation tests to ensure the caching
interface doesn't allocate unnecessarily when reusing factorizations.
The tests verify that solving with the same matrix but different
right-hand side vectors is allocation-free after initial factorization.

Tests cover:
- Dense factorizations (LU, QR, Cholesky, SVD, etc.)
- Sparse factorizations (KLU, UMFPACK, CHOLMOD)
- Iterative solvers (SimpleGMRES, KrylovJL methods)
- Non-square matrix handling
- Matrix change refactorization behavior

Uses AllocCheck.jl to verify zero allocations in the caching path.

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

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas ChrisRackauckas merged commit 247b597 into SciML:main Aug 9, 2025
111 of 118 checks passed
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.

2 participants