code: def local_useless_slice(fgraph, node):
      """
      Remove Subtensor of the form:
          1. X[0, :] -> X[0]
          2. X[:] -> X
  
      """
      idxs = get_idx_list(node.inputs, node.op.idx_list)
  
      if not idxs:
          return [node.inputs[0]]
  
      last_useless_slice = len(idxs)
      for s in idxs[::-1]:
          # check if slice and then check slice indices
          if (
              isinstance(s, slice)
              and s.start is None
              and s.stop is None
              and (
                  s.step is None
                  or extract_constant(
                      s.step, only_process_constants=True
                  )
                  == 1
              )
          ):
              last_useless_slice -= 1
          else:
              break
      # check if we removed something
      if last_useless_slice < len(idxs):
          new_idxs = idxs[:last_useless_slice]
          if new_idxs:
              new_subtensor = Subtensor(new_idxs)
              new_subtensor_inputs = get_slice_elements(
                  new_idxs, lambda x: isinstance(x, Variable)
              )
              out = new_subtensor(node.inputs[0], *new_subtensor_inputs)
              # Copy over previous output stacktrace
              copy_stack_trace(node.outputs, out)
              return [out]
          else:
              # Subtensor is not needed at all
              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 8 for calling a global function with example usage: local_useless_slice(fgraph, node) and returns: list, list, list