Rewrite det(inv(X)) → 1/det(X)#2102
Rewrite det(inv(X)) → 1/det(X)#2102alessandrogentili001 wants to merge 2 commits intopymc-devs:mainfrom
Conversation
| @register_stabilize | ||
| @register_specialize | ||
| @node_rewriter([Elemwise]) | ||
| def local_reciprocal_linalg_special_cases(fgraph, node): |
There was a problem hiding this comment.
These aren't related to linalg, the name is wrong
Each of these should be a separate rewrite, and we should be using the new scalar Op properties. We have monotonic_increasing and monotonic_decreasing, which imply sign(f(x)) -> sign(x) and sign(f(x)) -> sign(-x) if the op is also zero_preserving.
We just have to be careful about strict montonicity vs non-strict. I can't remember if ceil(x) is marked as monotonic for example. We might need a separate flag for the strict variety and check it in this rewrite.
| def det_of_inv(fgraph, node): | ||
| """Replace det(matrix_inverse(X)) with reciprocal(det(X)). | ||
|
|
||
| Since det(inv(X)) = 1/det(X), we avoid computing the inverse. |
There was a problem hiding this comment.
| Since det(inv(X)) = 1/det(X), we avoid computing the inverse. |
|
Hi jesse, thanks for the feedback! I've refactored the implementation to address your points regarding modularity and property-based rewriting.
Let me know if you have any further suggestions! |
Description
Related Issue
Checklist
Type of change