Skip to content

Keep solve scratch out of the solver factorizations and take an optional workspace in ldiv! - #914

Merged
ViralBShah merged 2 commits into
mainfrom
vs/ldiv-workspace
Sep 24, 2026
Merged

ViralBShah merged 2 commits into
mainfrom
vs/ldiv-workspace

Conversation

@ViralBShah

@ViralBShah ViralBShah commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

ldiv! with a CHOLMOD, UMFPACK or SPQR factorization now takes an optional workspace keyword. Without one, a solve allocates its own scratch space instead of reusing a buffer stored in the factorization. This is the workspace part of #912, split out so that #912 only changes threading.

Each solver kept its solve scratch inside the factorization: the ldiv! buffers of a CHOLMOD.Factor, the UmfpackWS field of an UmfpackLU, and the _ldiv_workspace of a QRSparse. That state is gone. ldiv!(x, F, b; workspace) takes a caller-owned workspace instead:

factorization workspace
lu UMFPACK.UmfpackWS(F) (existing)
cholesky, ldlt CHOLMOD.CholmodWS(F) (new)
qr SPQR.SpqrWS(F) (new)

1. Uniform support. The keyword works with F, F' and transpose(F), in both ldiv!(x, F, b) and ldiv!(F, b), for all three solvers. This PR adds the methods that were missing on main:

  • 3-argument ldiv! for F' and transpose(F) of a CHOLMOD Factor: the adjoint solves the same Hermitian system, and the transpose solves the conjugate one;
  • ldiv!(x, transpose(F), b) for SPQR;
  • in-place ldiv!(F, b) for a square qr factorization and its adjoint and transpose.

2. Sizing. A workspace grows as needed. An UmfpackWS that is too small, for example after turning on iterative refinement, used to throw ArgumentError; it now grows.

3. Cost. Time is unchanged; allocations change as follows:

ldiv!(x, F, b) main no workspace with workspace
cholesky, n = 100 1.7 µs, 0 B 1.8 µs, 3488 B 1.7 µs, 0 B
lu, n = 100 1.4 µs, 0 B 1.4 µs, 1792 B 1.4 µs, 0 B
qr, n = 100 2.6 µs, 0 B 2.5 µs, 928 B 2.5 µs, 0 B

4. Behaviour changes.

5. Docs. "Reusing a factorization" in docs/src/solvers.md now explains the keyword. UMFPACK.UmfpackWS, CHOLMOD.CholmodWS and SPQR.SpqrWS are documented and included in the manual. The new names follow the existing UmfpackWS, and each constructor takes F, F' or transpose(F). The thread-safety section no longer says the factorizations own a workspace.

Tested on Julia nightly with Pkg.test(test_args=["solvers"]), ambiguous, the doctests and the whitespace check. A new test in test/solvers/solvers.jl runs every form above with and without a workspace for all three solvers, against dense solves. The allocation tests now pass a workspace and still require zero allocations, and the CHOLMOD lifetime tests check that a CholmodWS frees its buffers through the right Common.

Written with Claude Code.

🤖 Generated with Claude Code

…nal `workspace` in `ldiv!`

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.24390% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.95%. Comparing base (4a3d247) to head (ecf9218).

Files with missing lines Patch % Lines
src/solvers/spqr.jl 84.21% 3 Missing ⚠️
src/solvers/umfpack.jl 91.42% 3 Missing ⚠️
src/solvers/cholmod.jl 92.85% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #914      +/-   ##
==========================================
- Coverage   94.01%   93.95%   -0.06%     
==========================================
  Files          16       16              
  Lines        9189     9198       +9     
==========================================
+ Hits         8639     8642       +3     
- Misses        550      556       +6     

☔ View full report in Codecov by Harness.
📢 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.

@ViralBShah
ViralBShah added this pull request to stack #916 September 24, 2026 21:10
…ACK.UmfpackWS`

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ViralBShah
ViralBShah merged commit c63c46c into main Sep 24, 2026
10 checks passed
@ViralBShah
ViralBShah deleted the vs/ldiv-workspace branch September 24, 2026 21:47
ViralBShah added a commit that referenced this pull request Oct 9, 2026
…ember (#1017)

Documentation only, drawn from the pull requests merged since early
September and their review comments.

- **PR text.** The rule against reporting routine checks is its own
bullet and names the forms that still got through: test modes passing,
the ambiguity check, the Julia build, pass counts. Titles fit one line
of `git log --oneline`.
- **Added.** Julia's CI flags, `--depwarn=error` and the trim test
(#971, #972); dense results where every entry would be stored (#1004,
#1005, #1007); opaque elements (#982, #977, #1006); fixed test inputs
and `mismatch` (#991, #998).
- **Removed.** Rules that Aqua, `.gitignore` or #990 made unnecessary,
and test detail that `test/AGENTS.md` already holds.
- **`src/solvers/`.** Caller-owned solve workspaces (#914), copying an
aliased right-hand side (#942), validating before a refactorization
(#899, #901). Corrects the lock field names and the index-type testing
rule.
- **`test/`.** Fixed inputs and top-level helper loading (#971); drops
the notes on worker groups, which `runtests.jl` no longer has.
- **`gen/`.** Header order, and running `make` before a change (#1003).

Written by Claude Code (Claude Opus 5.5).

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

Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant