@register_uncanonicalize
@gof.local_optimizer([T.Alloc])
def local_alloc_dimshuffle(node):
 if isinstance(node.op, T.Alloc):
  input_ = node.inputs[0]
  if (input_.owner and isinstance(input_.owner.op, DimShuffle)):
   new_order = input_.owner.op.new_order
   expected_new_order = ((('x',) * (input_.ndim - input_.owner.inputs[0].ndim)) + tuple(range(input_.owner.inputs[0].ndim)))
   if (new_order != expected_new_order):
    return False
   return [T.alloc(input_.owner.inputs[0], *node.inputs[1:])]
 return False

@ register_uncanonicalize @ gof . local_optimizer ( [ T . Alloc ] ) def local_alloc_dimshuffle ( node ) : if isinstance ( node . op , T . Alloc ) : input_ = node . inputs [ 0 ] if ( input_ . owner and isinstance ( input_ . owner . op , DimShuffle ) ) : new_order = input_ . owner . op . new_order expected_new_order = ( ( ( 'x' , ) * ( input_ . ndim - input_ . owner . inputs [ 0 ] . ndim ) ) + tuple ( range ( input_ . owner . inputs [ 0 ] . ndim ) ) ) if ( new_order != expected_new_order ) : return False return [ T . alloc ( input_ . owner . inputs [ 0 ] , * node . inputs [ 1 : ] ) ] return False
if a dimshuffle is inside an alloc and only adds dimension to the left .