@register_canonicalize
@register_stabilize
@gof.local_optimizer([T.Flatten])
def local_flatten_lift(node):
 if (isinstance(node.op, T.Flatten) and node.inputs[0].owner and isinstance(node.inputs[0].owner.op, T.Elemwise) and (len(node.inputs[0].owner.inputs) == 1)):
  f = node.op(node.inputs[0].owner.inputs[0])
  copy_stack_trace(node.outputs, f)
  e = node.inputs[0].owner.op(f)
  copy_stack_trace((node.outputs + [node.inputs[0]]), e)
  return [e]

@ register_canonicalize @ register_stabilize @ gof . local_optimizer ( [ T . Flatten ] ) def local_flatten_lift ( node ) : if ( isinstance ( node . op , T . Flatten ) and node . inputs [ 0 ] . owner and isinstance ( node . inputs [ 0 ] . owner . op , T . Elemwise ) and ( len ( node . inputs [ 0 ] . owner . inputs ) == 1 ) ) : f = node . op ( node . inputs [ 0 ] . owner . inputs [ 0 ] ) copy_stack_trace ( node . outputs , f ) e = node . inputs [ 0 ] . owner . op ( f ) copy_stack_trace ( ( node . outputs + [ node . inputs [ 0 ] ] ) , e ) return [ e ]
flatten(unaryelemwise(x)) -> unaryelemwise(flatten(x)) this optimization is needed by optimization nnet/sigm .