You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The result of solve(A, b) is the solution x to the linear equation Ax = b. If b is an identity matrix (Eye), x is simply inv(A).
578
-
Here, we are just recognising whether the solve operation returns an inverse or not; not replacing it because solve is mathematically more stable than inv.
579
-
"""
580
-
valid_solves= (Solve, SolveTriangular)
581
-
# First, we verify whether we have a valid solve op
# If the current op is solve, we check for b. If b is an identity matrix (Eye), we can return True
587
-
solve_inputs=node.inputs
588
-
eye_node=solve_inputs[1].owner
589
-
590
-
# We check for b = Eye and also make sure that if it was an Eye, then k = 0 (1's are only across the main diagonal)
591
-
ifnot (eye_nodeandisinstance(eye_node.op, Eye)):
592
-
returnFalse
593
-
594
-
if (
595
-
isinstance(eye_node.inputs[-1], Constant)
596
-
andeye_node.inputs[-1].data.item() !=0
597
-
):
598
-
returnFalse
599
-
returnTrue
600
-
601
-
602
574
@register_canonicalize
603
575
@register_stabilize
604
576
@node_rewriter([Blockwise])
605
577
defrewrite_inv_inv(fgraph, node):
606
578
"""
607
579
This rewrite takes advantage of the fact that if there are two consecutive inverse operations (inv(inv(input))), we get back our original input without having to compute inverse once.
608
580
609
-
Here, we check for direct inverse operations (inv/pinv) and also solve operations (solve/solve_triangular) in the case when b = Eye. This allows any combination of these "inverse" nodes to be simply rewritten.
581
+
Here, we check for direct inverse operations (inv/pinv) and allows for any combination of these "inverse" nodes to be simply rewritten.
0 commit comments