Skip to content

Add slogdet rewrite for block diagonal matrices#1996

Open
YichengYang-Ethan wants to merge 1 commit intopymc-devs:v3from
YichengYang-Ethan:slogdet-blockdiag-rewrite
Open

Add slogdet rewrite for block diagonal matrices#1996
YichengYang-Ethan wants to merge 1 commit intopymc-devs:v3from
YichengYang-Ethan:slogdet-blockdiag-rewrite

Conversation

@YichengYang-Ethan
Copy link
Copy Markdown

Summary

  • Add graph rewrite rewrite_slogdet_blockdiag that decomposes slogdet(block_diag(A, B, ...)) into (prod(sign_i), sum(logabsdet_i)) where each (sign_i, logabsdet_i) = slogdet(A_i).
  • Registered on both canonicalize and stabilize phases, matching the pattern used by rewrite_det_blockdiag.
  • Avoids constructing and factoring the full block diagonal matrix when the individual blocks suffice.

Related Issue

Closes #1921

Test plan

  • Existing test test_slogdet_blockdiag_rewrite in tests/tensor/rewriting/test_linalg.py validates correctness (sign and logabsdet values) and confirms no BlockDiagonal ops remain in the rewritten graph.

🤖 Generated with Claude Code

Decompose slogdet(block_diag(A, B, ...)) into
(prod(sign_i), sum(logabsdet_i)) where each
(sign_i, logabsdet_i) = slogdet(A_i).

This avoids constructing and factoring the full block diagonal
matrix when the slogdet of each block can be computed independently.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jessegrabowski
Copy link
Copy Markdown
Member

Hi @YichengYang-Ethan , looks like a nice start. It needs a test -- there are many examples in the linalg tests. The important thing is to use asset_equal_computation to test that the rewrite produces the expected graph, rather than doing a numerical test.

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.

ENH: Add slogdet rewrite for block diagonal matrices

2 participants