code: def local_dot_to_dot22(fgraph, node):
      # This works for tensor.outer too because basic.outer is a macro that
      # produces a dot(dimshuffle,dimshuffle) of form 4 below
      if not isinstance(node.op, Dot):
          return
  
      if any(
          not isinstance(i.type, DenseTensorType) for i in node.inputs
      ):
          return False
  
      x, y = node.inputs
      if y.type.dtype != x.type.dtype:
          # TODO: upcast one so the types match
          _logger.info(
              f"Not optimizing dot with inputs {x} {y} {x.type} {y.type}"
          )
          return
  
      if y.type.dtype in (
          "float16",
          "float32",
          "float64",
          "complex64",
          "complex128",
      ):
          if x.ndim == 2 and y.ndim == 2:
              new_out = [_dot22(*node.inputs)]
          elif x.ndim == 2 and y.ndim == 1:
              new_out = [_dot22(x, y.dimshuffle(0, "x")).dimshuffle(0)]
          elif x.ndim == 1 and y.ndim == 2:
              new_out = [_dot22(x.dimshuffle("x", 0), y).dimshuffle(1)]
          elif x.ndim == 1 and y.ndim == 1:
              new_out = [
                  _dot22(
                      x.dimshuffle("x", 0), y.dimshuffle(0, "x")
                  ).dimshuffle()
              ]
          else:
              return
          copy_stack_trace(node.outputs, new_out)
          return new_out
  
      _logger.info(
          f"Not optimizing dot with inputs {x} {y} {x.type} {y.type}"
      )
  
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 10 for calling a global function with example usage: local_dot_to_dot22(fgraph, node) and returns: False, new_out