@register_useless
@register_canonicalize
@register_specialize
@gof.local_optimizer([Subtensor])
def local_useless_slice(node):
 if isinstance(node.op, Subtensor):
  slices = get_idx_list(node.inputs, node.op.idx_list)
  last_slice = len(slices)
  for s in slices[::(-1)]:
   if (isinstance(s, slice) and (s.start is None) and (s.stop is None) and ((s.step is None) or (T.extract_constant(s.step, only_process_constants=True) == 1))):
    last_slice -= 1
   else:
    break
  if (last_slice < len(slices)):
   subtens = Subtensor(slices[:last_slice])
   sl_ins = Subtensor.collapse(slices[:last_slice], (lambda x: isinstance(x, T.Variable)))
   out = subtens(node.inputs[0], *sl_ins)
   copy_stack_trace(node.outputs, out)
   return [out]

@ register_useless @ register_canonicalize @ register_specialize @ gof . local_optimizer ( [ Subtensor ] ) def local_useless_slice ( node ) : if isinstance ( node . op , Subtensor ) : slices = get_idx_list ( node . inputs , node . op . idx_list ) last_slice = len ( slices ) for s in slices [ : : ( - 1 ) ] : if ( isinstance ( s , slice ) and ( s . start is None ) and ( s . stop is None ) and ( ( s . step is None ) or ( T . extract_constant ( s . step , only_process_constants = True ) == 1 ) ) ) : last_slice -= 1 else : break if ( last_slice < len ( slices ) ) : subtens = Subtensor ( slices [ : last_slice ] ) sl_ins = Subtensor . collapse ( slices [ : last_slice ] , ( lambda x : isinstance ( x , T . Variable ) ) ) out = subtens ( node . inputs [ 0 ] , * sl_ins ) copy_stack_trace ( node . outputs , out ) return [ out ]
remove subtensor of the form x[0 .