Skip to content

Rewrite determinant of diagonal matrix as product of diagonal #797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
82b7e98
Added det-diag rewrite
tanish1729 Jun 2, 2024
e661ba4
fixed pt.diagonal error
tanish1729 Jun 2, 2024
a1823e9
Added test for rewrite
tanish1729 Jun 5, 2024
ac21b9e
Added test for rewrite
tanish1729 Jun 5, 2024
01e47d7
fixed test
tanish1729 Jun 5, 2024
89f209f
added check for verifying rewrite
tanish1729 Jun 6, 2024
0bd2e26
fixed other failing test
tanish1729 Jun 6, 2024
170a860
added docstring
tanish1729 Jun 7, 2024
0191b97
updated docstring
tanish1729 Jun 7, 2024
7f7c803
fixed mypy error
tanish1729 Jun 7, 2024
8d7f9f7
added det_diag_from_diag and test
tanish1729 Jun 9, 2024
9ad0606
fixed node rewriter name
tanish1729 Jun 9, 2024
c897296
added row/col tests
tanish1729 Jun 11, 2024
6c3cdae
updated check for eye
tanish1729 Jun 11, 2024
6b58cfb
updated rewrite and tests
tanish1729 Jun 15, 2024
4316e75
added check for eye_input and new test for cases where not to apply r…
tanish1729 Jun 21, 2024
20c8505
Merge branch 'pymc-devs:main' into det-diag-rewrite
tanish1729 Jun 22, 2024
6743e0a
does not apply rewrite to specific cases
tanish1729 Jun 22, 2024
ebca339
typecasted test variable
tanish1729 Jun 22, 2024
58212b6
typecast variables
tanish1729 Jun 23, 2024
3ef186d
removed shape known check; fails for rectangle eye
tanish1729 Jun 24, 2024
2c96faf
added new tests for (1,1) eye and rectangle eye
tanish1729 Jun 24, 2024
9a48a72
added helper function for diag from eye_mul
tanish1729 Jun 25, 2024
ffc0f81
updated case for no rewrite which was failing tests
tanish1729 Jun 25, 2024
9f661e3
cleaned code; updated rectangle_eye test which is an invalid rewrite
tanish1729 Jun 26, 2024
b02818d
add check for k in pt.eye
tanish1729 Jun 26, 2024
0dbc28e
Update pytensor/tensor/rewriting/linalg.py
tanish1729 Jun 26, 2024
d4ffb7f
typecasted det_val
tanish1729 Jun 26, 2024
060863a
Merge branch 'det-diag-rewrite' of https://github.com/tanish1729/pyte…
tanish1729 Jun 26, 2024
557fea1
fixed final typecasting
tanish1729 Jun 26, 2024
12ffb8f
Merge branch 'main' into det-diag-rewrite
tanish1729 Jun 30, 2024
27a9864
fixed merge
tanish1729 Jul 1, 2024
6831069
fixed failing rectangle eye test
tanish1729 Jul 1, 2024
9811b88
fixed typo
tanish1729 Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pytensor/tensor/rewriting/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ def _find_diag_from_eye_mul(potential_mul_input):
for mul_input in inputs_to_mul
if mul_input.owner and isinstance(mul_input.owner.op, Eye)
]

# Check if 1's are being put on the main diagonal only (k = 1)
if eye_input and getattr(eye_input[0].owner.inputs[-1], "data", 0).item() != 0:
return None

# If the broadcast pattern of eye_input is not (False, False), we do not get a diagonal matrix and thus, dont need to apply the rewrite
if eye_input and eye_input[0].broadcastable[-2:] != (False, False):
return None
Expand Down