code: def inplace_allocempty(op, idx):
      """
      Wrapper to make an inplace optimization that deals with AllocEmpty
  
      This will duplicate the alloc input if it has more than one client
      to allow the op to work on it inplace.
  
      The decorated function must have this signature::
  
          maker(node, inputs)
  
      The `node` argument you receive is the original apply node that
      contains your op.  You should use it to grab relevant properties
      for your op so that the new version performs the same computation.
      You should also switch the op to work inplace.  The `*inputs`
      parameters contains the new inputs for your op.  You MUST use
      those inputs instead of the ones on `node`.  Note that this
      function can be as simple as::
  
          def maker(node, inputs):
              return [node.op.__class__(inplace=True)(*inputs)]
  
      Parameters
      ----------
      op : op class
          The op class to look for to make inplace
      idx : int
          The index of the (possibly) AllocEmpty input (in node.inputs).
  
      Returns
      -------
      local optimizer
          an unregistered inplace local optimizer that has the same name
          as the decorated function.
  
      """
  
      def wrapper(maker):
          @local_optimizer([op], inplace=True)
          @wraps(maker)
          def opt(node):
              if type(node.op) != op or node.op.inplace:
                  return
              inputs = list(node.inputs)
              alloc = inputs[idx]
              if (
                  alloc.owner
                  and isinstance(alloc.owner.op, GpuAllocEmpty)
                  and len(alloc.clients) > 1
              ):
                  alloc_op = GpuAllocEmpty(
                      alloc.owner.op.dtype, alloc.owner.op.context_name
                  )
                  inputs[idx] = alloc_op(*alloc.owner.inputs)
              with inherit_stack_trace(node.outputs):
                  return maker(node, inputs)
  
          return opt
  
      return wrapper
  
file_path: Theano/theano/gpuarray/opt_util.py
imports: from __future__ import absolute_import, print_function, division
  from functools import wraps
  import numpy
  from theano import tensor, scalar, Constant
  from theano.gof import local_optimizer
  from theano.gof.opt import inherit_stack_trace
  from theano.tensor import DimShuffle, get_scalar_constant_value, NotScalarConstantError
  from .basic_ops import GpuFromHost, HostFromGpu, GpuAllocEmpty, GpuReshape
  from .elemwise import GpuDimShuffle, GpuElemwise
label_desc: Use image node_id 6 for calling a global function with example usage: inplace_allocempty(op, idx) and returns: wrapper, opt, maker