@register_useless
@register_canonicalize
@register_specialize
@gof.local_optimizer([T.Rebroadcast])
def local_useless_rebroadcast(node):
 if isinstance(node.op, T.Rebroadcast):
  x = node.inputs[0]
  if numpy.all((x.broadcastable == node.outputs[0].broadcastable)):
   return [x]
  else:
   new_axis = {}
   for (dim, bc) in list(node.op.axis.items()):
    if (x.broadcastable[dim] != bc):
     new_axis[dim] = bc
   if (new_axis == node.op.axis):
    return
   else:
    r = T.Rebroadcast(*list(new_axis.items()))(x)
    copy_stack_trace(node.outputs, r)
    return [r]

@ register_useless @ register_canonicalize @ register_specialize @ gof . local_optimizer ( [ T . Rebroadcast ] ) def local_useless_rebroadcast ( node ) : if isinstance ( node . op , T . Rebroadcast ) : x = node . inputs [ 0 ] if numpy . all ( ( x . broadcastable == node . outputs [ 0 ] . broadcastable ) ) : return [ x ] else : new_axis = { } for ( dim , bc ) in list ( node . op . axis . items ( ) ) : if ( x . broadcastable [ dim ] != bc ) : new_axis [ dim ] = bc if ( new_axis == node . op . axis ) : return else : r = T . Rebroadcast ( * list ( new_axis . items ( ) ) ) ( x ) copy_stack_trace ( node . outputs , r ) return [ r ]
remove rebroadcast if id does not actually change the broadcasting pattern .