code: def generic_solve_to_solve_triangular(fgraph, node):
      """
      If any solve() is applied to the output of a cholesky op, then
      replace it with a triangular solve.
  
      """
      if isinstance(node.op.core_op, Solve):
          if node.op.core_op.assume_a == "gen":
              A, b = node.inputs  # result is solution Ax=b
              if (
                  A.owner
                  and isinstance(A.owner.op, Blockwise)
                  and isinstance(A.owner.op.core_op, Cholesky)
              ):
                  if A.owner.op.core_op.lower:
                      return [
                          solve_triangular(
                              A,
                              b,
                              lower=True,
                              b_ndim=node.op.core_op.b_ndim,
                          )
                      ]
                  else:
                      return [
                          solve_triangular(
                              A,
                              b,
                              lower=False,
                              b_ndim=node.op.core_op.b_ndim,
                          )
                      ]
              if is_matrix_transpose(A):
                  (A_T,) = A.owner.inputs
                  if (
                      A_T.owner
                      and isinstance(A_T.owner.op, Blockwise)
                      and isinstance(A_T.owner.op, Cholesky)
                  ):
                      if A_T.owner.op.lower:
                          return [
                              solve_triangular(
                                  A,
                                  b,
                                  lower=False,
                                  b_ndim=node.op.core_op.b_ndim,
                              )
                          ]
                      else:
                          return [
                              solve_triangular(
                                  A,
                                  b,
                                  lower=True,
                                  b_ndim=node.op.core_op.b_ndim,
                              )
                          ]
  
imports: import logging
  from typing import cast
  from pytensor.graph.rewriting.basic import copy_stack_trace, node_rewriter
  from pytensor.tensor.basic import TensorVariable, diagonal, swapaxes
  from pytensor.tensor.blas import Dot22
  from pytensor.tensor.blockwise import Blockwise
  from pytensor.tensor.elemwise import DimShuffle
  from pytensor.tensor.math import Dot, Prod, _matrix_matrix_matmul, log, prod
  from pytensor.tensor.nlinalg import MatrixInverse, det
  from pytensor.tensor.rewriting.basic import register_canonicalize, register_specialize, register_stabilize
  from pytensor.tensor.slinalg import Cholesky, Solve, SolveBase, cholesky, solve, solve_triangular
label_desc: Use image node_id 5 for calling a global function with example usage: generic_solve_to_solve_triangular(fgraph, node) and returns: list, list, list, list