code: def batched_vector_b_solve_to_matrix_b_solve(fgraph, node):
      """Replace a batched Solve(a, b, b_ndim=1) by Solve(a, b.T, b_ndim=2).T
  
      `a` must have no batched dimensions, while `b` can have arbitrary batched dimensions.
      """
      core_op = node.op.core_op
  
      if not isinstance(core_op, SolveBase):
          return None
  
      if node.op.core_op.b_ndim != 1:
          return None
  
      [a, b] = node.inputs
  
      # Check `b` is actually batched
      if b.type.ndim == 1:
          return None
  
      # Check `a` is a matrix (possibly with degenerate dims on the left)
      a_bcast_batch_dims = a.type.broadcastable[:-2]
      if not all(a_bcast_batch_dims):
          return None
      # We squeeze degenerate dims, any that are still needed will be introduced by the new_solve
      elif len(a_bcast_batch_dims):
          a = a.squeeze(axis=tuple(range(len(a_bcast_batch_dims))))
  
      # Recreate solve Op with b_ndim=2
      props = core_op._props_dict()
      props["b_ndim"] = 2
      new_core_op = type(core_op)(**props)
      matrix_b_solve = Blockwise(new_core_op)
  
      # Ravel any batched dims
      original_b_shape = tuple(b.shape)
      if len(original_b_shape) > 2:
          b = b.reshape((-1, original_b_shape[-1]))
  
      # Apply the rewrite
      new_solve = matrix_b_solve(a, b.T).T
  
      # Unravel any batched dims
      if len(original_b_shape) > 2:
          new_solve = new_solve.reshape(original_b_shape)
  
      old_solve = node.outputs[0]
      copy_stack_trace(old_solve, new_solve)
  
      return [new_solve]
  
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 6 for calling a global function with example usage: batched_vector_b_solve_to_matrix_b_solve(fgraph, node) and returns: list, None, None, None, None