@register_uncanonicalize
@gof.local_optimizer([T.Reshape])
def local_reshape_dimshuffle(node):
 if isinstance(node.op, T.Reshape):
  input_ = node.inputs[0]
  if (input_.owner and isinstance(input_.owner.op, DimShuffle)):
   new_order = input_.owner.op.new_order
   offset = 0
   for dim in new_order:
    if (dim == 'x'):
     continue
    elif (dim != offset):
     return False
    else:
     offset += 1
   return [T.reshape(input_.owner.inputs[0], node.inputs[1], ndim=node.outputs[0].ndim)]
 return False

@ register_uncanonicalize @ gof . local_optimizer ( [ T . Reshape ] ) def local_reshape_dimshuffle ( node ) : if isinstance ( node . op , T . Reshape ) : input_ = node . inputs [ 0 ] if ( input_ . owner and isinstance ( input_ . owner . op , DimShuffle ) ) : new_order = input_ . owner . op . new_order offset = 0 for dim in new_order : if ( dim == 'x' ) : continue elif ( dim != offset ) : return False else : offset += 1 return [ T . reshape ( input_ . owner . inputs [ 0 ] , node . inputs [ 1 ] , ndim = node . outputs [ 0 ] . ndim ) ] return False
if a dimshuffle is inside a reshape and does not change the order of dimensions .