@register_specialize
@gof.local_optimizer([T.Elemwise])
def local_alloc_unary(node):
 if (isinstance(node.op, T.Elemwise) and (len(node.inputs) == 1)):
  a = node.inputs[0]
  if (a.owner and isinstance(a.owner.op, T.Alloc)):
   x = a.owner.inputs[0]
   shp = a.owner.inputs[1:]
   v = node.op(x)
   copy_stack_trace(node.outputs[0], v)
   ret = T.alloc(T.cast(v, node.outputs[0].dtype), *shp)
   copy_stack_trace([node.outputs[0], a], ret)
   return [ret]

@ register_specialize @ gof . local_optimizer ( [ T . Elemwise ] ) def local_alloc_unary ( node ) : if ( isinstance ( node . op , T . Elemwise ) and ( len ( node . inputs ) == 1 ) ) : a = node . inputs [ 0 ] if ( a . owner and isinstance ( a . owner . op , T . Alloc ) ) : x = a . owner . inputs [ 0 ] shp = a . owner . inputs [ 1 : ] v = node . op ( x ) copy_stack_trace ( node . outputs [ 0 ] , v ) ret = T . alloc ( T . cast ( v , node . outputs [ 0 ] . dtype ) , * shp ) copy_stack_trace ( [ node . outputs [ 0 ] , a ] , ret ) return [ ret ]
unary(alloc) -> alloc(unary(x) .