code: def local_useless_inc_subtensor(fgraph, node):
      r"""Remove redundant `IncSubtensor`\s.
  
      More specifically, ``set_subtensor(x[indices], y)`` is replaced by
      ``y[indices]`` when ``indices`` are full `slice`\s and ``y``'s shape is
      equal to ``x[indices]``, and ``inc_subtensor(x[indices], y)`` is replaced
      by ``y[indices]`` when ``x[indices]`` is some array of ``0``\s, ``indices``
      are full slices, and the shapes are equal.
      """
      if not isinstance(node.op, IncSubtensor):
          return
  
      if not hasattr(fgraph, "shape_feature"):
          return
  
      x, y, *index_inputs = node.inputs
  
      if node.op.set_instead_of_inc is False:
          # This is an increment operation, so the array being incremented must
          # consist of all zeros in order for the entire operation to be useless
          try:
              c = get_underlying_scalar_constant_value(x)
              if c != 0:
                  return
          except NotScalarConstantError:
              return
  
      idx_cst = indices_from_subtensor(
          list(index_inputs), node.op.idx_list
      )
  
      # Check that all indices are full slices with only reversals and no step
      # sizes
      # TODO: It seems like there should be a basic `IncSubtensor`
      # canonicalization that removes these redundant slices.
      if all(
          isinstance(e, slice)
          and e.start is None
          and e.stop is None
          and (
              e.step is None
              or extract_constant(e.step, only_process_constants=True)
              == -1
          )
          for e in idx_cst
      ):
          # `IncSubtensor` broadcasts `x` on `y` based on run-time shapes, so we
          # must check that they are the same
          if not fgraph.shape_feature.same_shape(x, y):
              return
  
          # There are no reversals, so we don't need a replacement.
          if all(e.step is None for e in node.op.idx_list):
              # They are exactly the same shapes, so we can remove this `IncSubtensor`
              return [y]
  
          new_node = Subtensor(node.op.idx_list).make_node(
              y, *index_inputs
          )
          new_out = new_node.outputs[0]
          copy_stack_trace(node.outputs, new_out)
  
          return [new_out]
  
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 15 for calling a global function with example usage: local_useless_inc_subtensor(fgraph, node) and returns: list, list