code: def local_useless_subtensor(fgraph, node):
      """Remove `Subtensor` if it takes the full input."""
  
      if not node.op.idx_list:
          return [node.inputs[0]]
  
      # The more elaborate optimization needs ShapeOpt and fgraph.shape_feature
      if not hasattr(fgraph, "shape_feature"):
          return
  
      shape_of = fgraph.shape_feature.shape_of
  
      cdata = get_constant_idx(
          node.op.idx_list,
          node.inputs,
          allow_partial=True,
          only_process_constants=True,
      )
      for pos, idx in enumerate(cdata):
          if not isinstance(idx, slice):
              # If idx is not a slice, this means we remove this dimension
              # from the output, so the subtensor is not useless
              return False
          if idx.start is not None and idx.start != 0:
              # If the start of the slice is different from 0, or is a
              # variable, then we assume the subtensor is not useless
              return False
          if idx.step is not None and idx.step != 1:
              # If we are going backwards, or skipping elements, then this
              # is not a useless subtensor
              return False
  
          length_pos = shape_of[node.inputs[0]][pos]
  
          if isinstance(idx.stop, (int, np.integer)):
              length_pos_data = sys.maxsize
              try:
                  length_pos_data = (
                      get_underlying_scalar_constant_value(
                          length_pos, only_process_constants=True
                      )
                  )
              except NotScalarConstantError:
                  pass
  
              if idx.stop < length_pos_data:
                  return False
          elif isinstance(idx.stop, Variable):
              length_pos_shape_i = idx.stop
              # length_pos is a tensor variable, but length_pos_shape_i
              # is a scalar variable. We try to see if they represent
              # the same underlying variable.
              if length_pos_shape_i.owner and isinstance(
                  length_pos_shape_i.owner.op, ScalarFromTensor
              ):
                  length_pos_shape_i = length_pos_shape_i.owner.inputs[
                      0
                  ]
              elif length_pos.owner and isinstance(
                  length_pos.owner.op, TensorFromScalar
              ):
                  length_pos = length_pos.owner.inputs[0]
              else:
                  # We did not find underlying variables of the same type
                  return False
  
              # The type can be different: int32 vs int64. length_pos
              # should always be int64 as that is what the shape
              # tracker keep. Subtensor accept any scalar int{8,16,32,64}
              # as index type.
              assert str(length_pos.type.dtype) == "int64"
              assert str(length_pos_shape_i.type.dtype) in [
                  "int8",
                  "int16",
                  "int32",
                  "int64",
              ]
  
              # length_pos_shape_i cannot be None
              if length_pos_shape_i != length_pos:
                  return False
          elif idx.stop is None:
              continue
          else:
              return False
  
      return [node.inputs[0]]
  
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 17 for calling a global function with example usage: local_useless_subtensor(fgraph, node) and returns: list, list, False, False, False, False, False, False, False