def inplace_allocempty(op, idx):
 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 = gpu_alloc_empty(alloc.owner.op.context_name, dtype=alloc.owner.op.dtype)
    inputs[idx] = alloc_op(*alloc.owner.inputs)
   return maker(node, inputs)
  return opt
 return wrapper

def inplace_allocempty ( op , idx ) : 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 = gpu_alloc_empty ( alloc . owner . op . context_name , dtype = alloc . owner . op . dtype ) inputs [ idx ] = alloc_op ( * alloc . owner . inputs ) return maker ( node , inputs ) return opt return wrapper
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 .