code: def local_gemm_to_ger(fgraph, node):
      """GEMM computing an outer-product -> GER."""
      if node.op == gemm_no_inplace:
          z, a, x, y, b = node.inputs
          if x.broadcastable[1] and y.broadcastable[0]:
              # x and y are both vectors so this might qualifies for a GER
              xv = x.dimshuffle(0)
              yv = y.dimshuffle(1)
              try:
                  bval = ptb.get_underlying_scalar_constant_value(b)
              except NotScalarConstantError:
                  # b isn't a constant, GEMM is doing useful pre-scaling
                  return
  
              if bval == 1:  # best case a natural GER
                  rval = ger(z, a, xv, yv)
                  new_out = [rval]
              elif (
                  bval == 0
              ):  # GER on zeros_like should be faster than GEMM
                  zeros = ptb.zeros([x.shape[0], y.shape[1]], x.dtype)
                  rval = ger(zeros, a, xv, yv)
                  new_out = [rval]
              else:
                  # if bval is another constant, then z is being usefully
                  # pre-scaled and GER isn't really the right tool for the job.
                  return
              copy_stack_trace(node.outputs, new_out)
              return new_out
  
imports: import copy
  import logging
  import time
  import numpy
  from pytensor.tensor.rewriting.basic import register_specialize
  import pytensor.scalar
  from pytensor.compile.mode import optdb
  from pytensor.configdefaults import config
  from pytensor.graph.features import ReplacementDidNotRemoveError, ReplaceValidate
  from pytensor.graph.rewriting.basic import EquilibriumGraphRewriter, GraphRewriter, copy_stack_trace, in2out, node_rewriter
  from pytensor.graph.rewriting.db import SequenceDB
  from pytensor.graph.utils import InconsistencyError
  from pytensor.tensor import basic
  from pytensor.tensor.blas import Dot22, _dot22, _dot22scalar, batched_dot, gemm_inplace, gemm_no_inplace, gemv_inplace, gemv_no_inplace, ger, ger_destructive
  from pytensor.tensor.elemwise import DimShuffle, Elemwise
  from pytensor.tensor.exceptions import NotScalarConstantError
  from pytensor.tensor.math import Dot, _matrix_matrix_matmul, add, mul, neg, sub
  from pytensor.tensor.rewriting.elemwise import local_dimshuffle_lift
  from pytensor.tensor.type import DenseTensorType, TensorType, integer_dtypes, values_eq_approx_remove_inf_nan
label_desc: Use image node_id 15 for calling a global function with example usage: local_gemm_to_ger(fgraph, node) and returns: new_out