code: def local_subtensor_of_dot(fgraph, node):
      """Rewrite ``at.dot(A, B)[idxs]`` into ``at.dot(A[idxs_a], B[idxs_b])``.
      ``idxs_a`` is the first ``A.ndim-1`` entries of ``idxs``, and ``idxs_b`` is
      the remaining entries of ``idxs`` (if any), modified to skip the
      second-to-last dimension of ``B`` (because dot sums over this dimension).
      """
      if not isinstance(node.op, Subtensor):
          return
      if not node.inputs[0].owner or not isinstance(
          node.inputs[0].owner.op, Dot
      ):
          return
      # If there is other node that use the outputs of the dot
      # We don't want to compute twice the sub part.
      if len(fgraph.clients[node.inputs[0]]) > 1:
          return
  
      a = node.inputs[0].owner.inputs[0]
      b = node.inputs[0].owner.inputs[1]
  
      idx_list = get_idx_list(node.inputs, node.op.idx_list)
  
      num_a_indices = min(a.ndim - 1, len(idx_list))
      a_indices = idx_list[:num_a_indices]
      b_indices = idx_list[num_a_indices:]
  
      # This is necessary because np.dot sums the last index of a with the second to last of b
      # so we want to skip the second-to-last index into b.
      # This wasn't necessary for a, because we just omitted the last index.
      # We skip this if b.ndim = 1, since then we just want b_sub = b, not b_sub = b[:]
      # (dot also handles b.ndim < 2 as a special case)
      if b.ndim > 1 and len(b_indices) >= b.ndim - 1:
          b_indices = (
              b_indices[: b.ndim - 2]
              + (slice(None, None, None),)
              + b_indices[b.ndim - 2 :]
          )
  
      a_sub = a.__getitem__(tuple(a_indices))
      b_sub = b.__getitem__(tuple(b_indices)) if b_indices else b
  
      # Copy over previous output stacktrace to a_sub and b_sub,
      # because an error in the subtensor operation (e.g. an index error)
      # on either a or b must correspond to an error in the
      # subtensor operation on their dot product.
      copy_stack_trace(node.outputs[0], [a_sub, b_sub])
  
      # Copy over previous output stacktrace and previous dot product stacktrace,
      # because an error here may correspond to an either in either the original
      # dot product, or in the dot product after the subtensor operation.
      r = dot(a_sub, b_sub)
      copy_stack_trace([node.outputs[0], node.inputs[0]], r)
  
      return [r]
  
imports: import sys
  from collections.abc import Iterable
  import numpy
  import pytensor
  import pytensor.scalar.basic
  from pytensor import compile
  from pytensor.graph.basic import Constant, Variable
  from pytensor.graph.rewriting.basic import WalkingGraphRewriter, copy_stack_trace, in2out, node_rewriter
  from pytensor.raise_op import Assert
  from pytensor.tensor.basic import Alloc, Join, MakeVector, ScalarFromTensor, TensorFromScalar, alloc, as_tensor, cast, concatenate, extract_constant, get_underlying_scalar_constant_value, register_infer_shape, switch
  from pytensor.tensor.blockwise import Blockwise
  from pytensor.tensor.elemwise import Elemwise
  from pytensor.tensor.exceptions import NotScalarConstantError
  from pytensor.tensor.math import Dot, add, and_, ceil_intdiv, dot, eq, ge, gt, le, lt, maximum, minimum, or_
  from pytensor.tensor.math import all
  from pytensor.tensor.rewriting.basic import register_canonicalize, register_specialize, register_stabilize
  from pytensor.tensor.shape import Shape, SpecifyShape, Unbroadcast, shape_padleft, shape_tuple, specify_shape, unbroadcast
  from pytensor.tensor.sharedvar import TensorSharedVariable
  from pytensor.tensor.subtensor import AdvancedIncSubtensor, AdvancedIncSubtensor1, AdvancedSubtensor, AdvancedSubtensor1, IncSubtensor, Subtensor, advanced_inc_subtensor1, advanced_subtensor, advanced_subtensor1, as_index_constant, as_index_literal, get_canonical_form_slice, get_constant_idx, get_idx_list, get_slice_elements, inc_subtensor, indices_from_subtensor
  from pytensor.tensor.type import TensorType
  from pytensor.tensor.type_other import NoneTypeT, SliceConstant, SliceType
  from pytensor.tensor.variable import TensorConstant, TensorVariable
label_desc: Use image node_id 7 for calling a global function with example usage: local_subtensor_of_dot(fgraph, node) and returns: list