Skip to content

Backports for release 1.13#701

Open
dkarrasch wants to merge 7 commits intorelease-1.13from
backports-release-1.13
Open

Backports for release 1.13#701
dkarrasch wants to merge 7 commits intorelease-1.13from
backports-release-1.13

Conversation

ChrisRackauckas-Claude and others added 4 commits April 17, 2026 10:17
## Summary

Add a specialized `isdiag` method for `AbstractSparseMatrixCSC` that
traverses the CSC structure directly in O(nnz) time, compared to the
generic fallback which is O(n²) for an n×n matrix.

**Changes:**
- Import `isdiag` from LinearAlgebra
- Add `isdiag(A::AbstractSparseMatrixCSC)` that checks diagonal property
by traversing the sparse structure
- Add comprehensive tests for `isdiag` on sparse matrices

## Motivation

This addresses performance issues in packages like OrdinaryDiffEq.jl
where `isdiag` checks on large sparse mass matrices caused severe
initialization delays. For large DAE systems (e.g., 259k variables),
this reduces initialization time from ~60 seconds to <1ms.

Reference: SciML/OrdinaryDiffEq.jl#3011

## Benchmarks

```
n=1000:   generic=0.00ms, efficient=0.00ms
n=10000:  generic=0.04ms, efficient=0.00ms, speedup=12626x
n=50000:  generic=0.19ms, efficient=0.00ms, speedup=47511x
n=100000: generic=0.39ms, efficient=0.00ms, speedup=96737x
```

The efficient implementation runs in essentially constant time since it
only needs to check the stored elements.

## Test plan

- Added `isdiag` tests in `test/sparsematrix_ops.jl`:
  - Diagonal matrices (sparse diagonal, empty matrix)
  - Non-diagonal matrices (tridiagonal, bidiagonal, full)
  - Non-square matrices
  - Consistency with dense `isdiag`
  - Explicit zeros on off-diagonal (should still be diagonal)

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

---------

Co-authored-by: ChrisRackauckas-Claude <noreply@anthropic.com>
Co-authored-by: Chris Rackauckas <accounts@chrisrackauckas.com>
Create a unified initialization function for all SuiteSparse libraries
(both in the stdlib and elsewhere like KLU). This remains lazily
initialized. Should address
#671.

I wonder whether this should be truly `public` but KLU, AMD, and ParU,
SPEX will rely on this to function correctly so probably should be.

Also bumps wrapper generation. 

@gbaraldi not sure how to test this with your PR but tests on MinFEM.jl
seem to pass locally for me.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 69.23077% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.34%. Comparing base (5307f25) to head (4d4a98d).

Files with missing lines Patch % Lines
src/solvers/LibSuiteSparse.jl 60.00% 10 Missing ⚠️
src/solvers/wrappers.jl 0.00% 6 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           release-1.13     #701      +/-   ##
================================================
+ Coverage         84.14%   84.34%   +0.19%     
================================================
  Files                12       13       +1     
  Lines              9330     9339       +9     
================================================
+ Hits               7851     7877      +26     
+ Misses             1479     1462      -17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

4 participants