@register_opt()
@local_optimizer([tensor.DimShuffle, GpuFromHost])
def local_gpu_dimshuffle_0(node):
 if isinstance(node.op, tensor.DimShuffle):
  (input,) = node.inputs
  if (input.owner and isinstance(input.owner.op, HostFromGpu)):
   p_dict = node.op._props_dict()
   p_dict.pop('inplace', None)
   new_op = GpuDimShuffle(**p_dict)
   return [host_from_gpu(new_op(as_cuda_ndarray_variable(input)))]
 if isinstance(node.op, GpuFromHost):
  host_input = node.inputs[0]
  if (host_input.owner and isinstance(host_input.owner.op, tensor.DimShuffle)):
   dimshuffle_node = host_input.owner
   p_dict = dimshuffle_node.op._props_dict()
   p_dict.pop('inplace', None)
   new_op = GpuDimShuffle(**p_dict)
   return [new_op(as_cuda_ndarray_variable(dimshuffle_node.inputs[0]))]
 return False

@ register_opt ( ) @ local_optimizer ( [ tensor . DimShuffle , GpuFromHost ] ) def local_gpu_dimshuffle_0 ( node ) : if isinstance ( node . op , tensor . DimShuffle ) : ( input , ) = node . inputs if ( input . owner and isinstance ( input . owner . op , HostFromGpu ) ) : p_dict = node . op . _props_dict ( ) p_dict . pop ( 'inplace' , None ) new_op = GpuDimShuffle ( ** p_dict ) return [ host_from_gpu ( new_op ( as_cuda_ndarray_variable ( input ) ) ) ] if isinstance ( node . op , GpuFromHost ) : host_input = node . inputs [ 0 ] if ( host_input . owner and isinstance ( host_input . owner . op , tensor . DimShuffle ) ) : dimshuffle_node = host_input . owner p_dict = dimshuffle_node . op . _props_dict ( ) p_dict . pop ( 'inplace' , None ) new_op = GpuDimShuffle ( ** p_dict ) return [ new_op ( as_cuda_ndarray_variable ( dimshuffle_node . inputs [ 0 ] ) ) ] return False
dimshuffle(host_from_gpu()) -> host_from_gpu gpu_from_host -> gpu_dimshuffle .