Skip to content

Add reverse rule for Cholesky ldiv!#3108

Open
jlperla wants to merge 2 commits into
EnzymeAD:mainfrom
jlperla:ldiv-chol-reverse
Open

Add reverse rule for Cholesky ldiv!#3108
jlperla wants to merge 2 commits into
EnzymeAD:mainfrom
jlperla:ldiv-chol-reverse

Conversation

@jlperla

@jlperla jlperla commented May 16, 2026

Copy link
Copy Markdown

Summary

  • add reverse-mode support for ldiv!(fact::Cholesky, B)
  • mirror the existing forward rule by reversing through the Cholesky triangular solves
  • cache the Cholesky factor when needed for overwritten arguments
  • add focused test_reverse coverage for vector, matrix, const, and batched paths

Tests

  • julia --project=test test/runtests.jl --verbose rules/internal_rules/linear_algebra_rules

@wsmoses wsmoses force-pushed the ldiv-chol-reverse branch from fc25d8c to 81ff85b Compare May 16, 2026 16:21
Comment thread src/internal_rules/linalg.jl Outdated
U = cache_fact.U
N = EnzymeRules.width(config)

for i in 1:N

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should make this an ntuple, not a regular for loop

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Replace `for i in 1:N` with `ntuple(Val(N)) do i ... end` in the
Cholesky ldiv! reverse rule, matching the forward rule pattern.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented May 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.99%. Comparing base (51a2569) to head (827ad0b).
⚠️ Report is 131 commits behind head on main.

Files with missing lines Patch % Lines
src/internal_rules/linalg.jl 0.00% 39 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3108      +/-   ##
==========================================
- Coverage   70.04%   69.99%   -0.05%     
==========================================
  Files          66       66              
  Lines       21840    21879      +39     
==========================================
+ Hits        15297    15314      +17     
- Misses       6543     6565      +22     

☔ 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.

@wsmoses

wsmoses commented May 17, 2026

Copy link
Copy Markdown
Member

actually taking a step back, what fails without this?

@wsmoses

wsmoses commented May 17, 2026

Copy link
Copy Markdown
Member

specifically what is the error (we have potrf derivatives iirc)

@jlperla

jlperla commented May 17, 2026

Copy link
Copy Markdown
Author

Yeah let me give you a more focused issue tomorrow or Tuesday. I was finding both failures in some cases and also some horrible performance. Can't remember which and when.

Hold off on this until i can get the big picture to show you what is going on with errors, and/or massive performance differences

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