Add cholesky overload for tracer matrices#322
Conversation
A generic `cholesky` performs pivot / positive-definiteness checks that compare matrix entries; on tracers those comparisons return a tracer instead of a `Bool`, so the global tracer cannot factorize a matrix (e.g. while constructing a dense `MvNormal`/`PDMat`). Mirror the existing `eigen` overload: collapse the input to a single conservative tracer and broadcast it over the factor with a lazy `Fill`. Both the default/`NoPivot` and the `RowMaximum` variants are covered, since the all-depends pattern does not depend on the pivoting strategy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| LinearAlgebra.checksquare(A) | ||
| n = size(A, 1) | ||
| t = second_order_or(A) | ||
| return LinearAlgebra.Cholesky(Fill(t, n, n), 'U', 0) |
There was a problem hiding this comment.
For future reference (either here or a comment in the code):
What are the extra arguments to Cholesky?
There was a problem hiding this comment.
The first argument is the upper or lower-triangular factor, the second argument indicates whether it's the upper ('U') or lower ('L') triangular factor, and the third argument is the BLAS info code (0 indicates success).
| LinearAlgebra.checksquare(A) | ||
| n = size(A, 1) | ||
| t = second_order_or(A) | ||
| return LinearAlgebra.CholeskyPivoted(Fill(t, n, n), 'U', 1:n, n, tol, 0) |
There was a problem hiding this comment.
For future reference (either here or a comment in the code):
What are the extra arguments to CholeskyPivoted?
There was a problem hiding this comment.
The first two arguments and the last argument are the same as for Cholesky (factor, type of factor and BLAS info code), the third argument is the pivoting, and the fourth argument the rank.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #322 +/- ##
==========================================
+ Coverage 93.76% 93.81% +0.05%
==========================================
Files 28 28
Lines 1090 1100 +10
==========================================
+ Hits 1022 1032 +10
Misses 68 68 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks! |
|
Great, could you make a new release with the change? |
|
Done, note that I tagged |
|
No worries, that's fine with me 🙂 |
|
Thank you! |
I wanted to use the global tracer on a function that calls
cholesky, and it errored: the pivot / positive-definiteness checks compare matrix entries, which on tracers return a tracer rather than aBool.This adds a
choleskyoverload mirroring the existingeigenoverload — collapse the input to one conservative tracer viasecond_order_orand broadcast it over the factor with a lazyFill. Both the default /NoPivot(→Cholesky) andRowMaximum(→CholeskyPivoted) variants are covered; the pattern is independent of pivoting.Reproducer (errors on
main, works here):Adds a
"Cholesky"testset mirroring"Eigenvalues".This pull request was written with the assistance of generative AI (Claude Code).