code: def local_subtensor_remove_broadcastable_index(fgraph, node):
      """
      Remove broadcastable dimension with index 0 or -1
      a[:,:,:,0] -> a.dimshuffle(0,1,2), when
          a.broadcastable = (False, False, False, True)
      a[0,:,-1,:] -> a.dimshuffle(1,3), when
          a.broadcastable = (True, False, True, False)
  
      """
      if isinstance(node.op, Subtensor):
          idx = node.op.idx_list
      else:
          return
  
      remove_dim = []
      node_inputs_idx = 1
      for dim, elem in enumerate(idx):
          if isinstance(elem, (ps.ScalarType)):
              # The idx is a ScalarType, ie a Type. This means the actual index
              # is contained in node.inputs[1]
              dim_index = node.inputs[node_inputs_idx]
              if isinstance(dim_index, ps.ScalarConstant):
                  dim_index = dim_index.value
              if (
                  dim_index in (0, -1)
                  and node.inputs[0].broadcastable[dim]
              ):
                  remove_dim.append(dim)
                  node_inputs_idx += 1
              else:
                  return
          elif isinstance(elem, slice):
              if elem != slice(None):
                  return
          elif isinstance(elem, (int, np.integer)):
              if elem in (0, -1) and node.inputs[0].broadcastable[dim]:
                  remove_dim.append(dim)
          else:
              raise TypeError("case not expected")
  
      if len(remove_dim) == 0:
          return
      else:
          all_dim = range(node.inputs[0].ndim)
          remain_dim = [x for x in all_dim if x not in remove_dim]
          return [node.inputs[0].dimshuffle(tuple(remain_dim))]
  
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 11 for calling a global function with example usage: local_subtensor_remove_broadcastable_index(fgraph, node) and returns: list