Skip to content

Conversation

@ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Dec 10, 2025

The old local_det_chol rewrite is extended to cover more cases of a matrix that is factorized elsewhere, not just with Cholesky, but also LU, LUFactor, or SVD, QR (the latter two only if the sign isn't needed)

A new rewrite is added for the determinant of a factorization itself. The logic is slightly different, for instance det(LUFactor) is non-sensical, and the determinant for some outputs of SVD/ QR can always be computed even if the determinant of the whole factorization cannot.

Also extended the rewrite of log(prod(x)) to sum(log(x)), which should increase the stability of many of these when we want the log determinant (or log(abs(determintant))).

Still missing tests

Closes #1679
Related to #573

@ricardoV94 ricardoV94 added linalg Linear algebra enhancement New feature or request graph rewriting labels Dec 10, 2025
match core_op:
case Cholesky():
L = client.outputs[0]
new_det = matrix_diagonal_product(L) ** 2
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: Add the positive tag here.

Possibly also rewrite for log(x ** 2) -> log(x) * 2, when we know x is positive

Copy link
Member

Choose a reason for hiding this comment

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

This all seemed out of scope so I didn't address it. Positive tagging isn't used systematically and I'd rather we have a plan for doing that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed

@ricardoV94
Copy link
Member Author

Still missing tests and a couple other things. I wanted to first get #1786 in (which I think is still not ready either)

@jessegrabowski
Copy link
Member

I approved to poke you towards finishing it :)

@jessegrabowski
Copy link
Member

I used claude to add tests. I think it did a reasonable job.

@jessegrabowski
Copy link
Member

I also rebased, so if you want to keep working on it be aware of that.

@jessegrabowski jessegrabowski marked this pull request as ready for review January 4, 2026 19:11
ricardoV94 and others added 2 commits January 15, 2026 10:25
Co-authored-by: Jesse Grabowski <48652735+jessegrabowski@users.noreply.github.com>
Co-authored-by: Jesse Grabowski <48652735+jessegrabowski@users.noreply.github.com>
@ricardoV94 ricardoV94 merged commit a314476 into pymc-devs:main Jan 15, 2026
66 checks passed
@ricardoV94
Copy link
Member Author

Thanks for the help @jessegrabowski

@ricardoV94 ricardoV94 deleted the det_rewrites branch January 15, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request graph rewriting linalg Linear algebra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

local_det_chol doesn't work

2 participants