FIX inv_as_solve rewrite correctness for matmul inverse patterns#1895
Open
aman-coder03 wants to merge 5 commits intopymc-devs:mainfrom
Open
FIX inv_as_solve rewrite correctness for matmul inverse patterns#1895aman-coder03 wants to merge 5 commits intopymc-devs:mainfrom
inv_as_solve rewrite correctness for matmul inverse patterns#1895aman-coder03 wants to merge 5 commits intopymc-devs:mainfrom
Conversation
…add transpose–solve–transpose simplification rewrite with tests
Author
|
@ricardoV94 can you please have a look at this PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #1894
This PR improves the correctness and canonicalization of linear algebra rewrites involving matrix inverse and matmul operations.
The existing
inv_as_solverewrite handledDotpatterns but did not correctly handle_matmulpatterns. In particularA @ inv(B)must be rewritten assolve(B.T, A.T).Tto preserve correct algebraic semanticsThis PR extends the rewrite to handle
_matmuland ensures mathematically correct transformationsAfter inverse-to-solve rewrites, expressions such as
transpose(solve(transpose(A), transpose(B)))may appear in the graphThis PR introduces a canonicalization rewrite
transpose(solve(transpose(A), transpose(B))) → solve(A, B)This removes redundant transpose operations and improves graph simplicity
Added tests to verify
• Solve rewrite is applied
• Simplification rewrite works correctly
• Numerical correctness is preserved
Related Issue
Checklist
Type of change