@register_canonicalize
@register_stabilize
@gof.local_optimizer([T.Reshape])
def local_reshape_lift(node):
 if (isinstance(node.op, T.Reshape) and node.inputs[0].owner and isinstance(node.inputs[0].owner.op, T.Elemwise) and (len(node.inputs[0].owner.inputs) == 1)):
  r = node.op(node.inputs[0].owner.inputs[0], node.inputs[1])
  copy_stack_trace(node.outputs, r)
  e = node.inputs[0].owner.op(r)
  copy_stack_trace((node.outputs + node.inputs), e)
  if (e.type != node.outputs[0].type):
   re = T.patternbroadcast(e, node.outputs[0].broadcastable)
   copy_stack_trace(e, re)
  else:
   re = e
  return [re]

@ register_canonicalize @ register_stabilize @ gof . local_optimizer ( [ T . Reshape ] ) def local_reshape_lift ( node ) : if ( isinstance ( node . op , T . Reshape ) and node . inputs [ 0 ] . owner and isinstance ( node . inputs [ 0 ] . owner . op , T . Elemwise ) and ( len ( node . inputs [ 0 ] . owner . inputs ) == 1 ) ) : r = node . op ( node . inputs [ 0 ] . owner . inputs [ 0 ] , node . inputs [ 1 ] ) copy_stack_trace ( node . outputs , r ) e = node . inputs [ 0 ] . owner . op ( r ) copy_stack_trace ( ( node . outputs + node . inputs ) , e ) if ( e . type != node . outputs [ 0 ] . type ) : re = T . patternbroadcast ( e , node . outputs [ 0 ] . broadcastable ) copy_stack_trace ( e , re ) else : re = e return [ re ]
reshape(unaryelemwise(x)) -> unaryelemwise(reshape(x)) this optimization is needed by optimization nnet/sigm .