code: def local_adv_sub1_adv_inc_sub1(fgraph, node):
      """Rewrite graphs like ``AdvancedSubtensor1(AdvancedSetSubtensor1(...), ...)``.
  
      .. code::
  
          AdvancedSubtensor1(AdvancedSetSubtensor1(x, y, idx), idx) -> y
  
  
      Notes
      -----
      This rewrite adds an `AssertOp`; otherwise, it would remove shape and index
      error. If you want to get rid of them, see the :ref:`unsafe_rewrites`
      section.
  
      A previous version of this rewrite also matched
      ``AdvancedSubtensor1(AdvancedIncSubtensor1(x, y, idx), idx)``.
      This is incorrect when there are duplicate indices.
      The current version warns the user about potential issues.
  
      """
      if not isinstance(node.op, AdvancedSubtensor1):
          return
      inp = node.inputs[0]
      if not inp.owner or not isinstance(
          inp.owner.op, AdvancedIncSubtensor1
      ):
          return
      idx = node.inputs[1]
      idx2 = inp.owner.inputs[2]
      x = inp.owner.inputs[0]
      y = inp.owner.inputs[1]
      if idx is not idx2:
          return
      if (
          not inp.owner.op.set_instead_of_inc
          and
          # Don't use only_process_constants=True. We need to
          # investigate Alloc of 0s but with non constant shape.
          extract_constant(x, elemwise=False) != 0
      ):
          return
  
      if not inp.owner.op.set_instead_of_inc:
          return
  
      cond = [pt_all(and_(lt(idx, x.shape[0]), ge(idx, -x.shape[0])))]
      if not fgraph.shape_feature.same_shape(idx, y, 0, 0):
          cond.append(eq(idx.shape[0], y.shape[0]))
      r = Assert(
          "Bad indexing or shapes in a AdvancedIncSubtensor1 that was optimized away"
      )(y, *cond)
      copy_stack_trace(y, r)
  
      if r.dtype == node.outputs[0].dtype:
          return [r]
      # It is possible that y is upcast or downcast to x.dtype.
      # In all case, as we set or add with 0, we can just cast y.
      r2 = cast(r, node.outputs[0].dtype)
  
      # Copy over stacktrace from before casting, since
      # we don't expect problems in the casting operation,
      # and any problems in the indexing would have been spotted above.
      copy_stack_trace(r, r2)
      return [r2]
  
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 27 for calling a global function with example usage: local_adv_sub1_adv_inc_sub1(fgraph, node) and returns: list, list