def infer_context_name(*vars):
 todo = deque()
 todo.extendleft(vars)
 while todo:
  v = todo.pop()
  if isinstance(v.type, GpuArrayType):
   return v.type.context_name
  if hasattr(v.tag, 'context_name'):
   return v.tag.context_name
  if v.owner:
   if isinstance(v.owner.op, HostFromGpu):
    return v.owner.inputs[0].type.context_name
   if (len(v.owner.inputs) == 1):
    todo.extendleft(v.owner.inputs)
 try:
  get_context(None)
  return None
 except ContextNotDefined:
  raise ValueError('Could not infer context from inputs')

def infer_context_name ( * vars ) : todo = deque ( ) todo . extendleft ( vars ) while todo : v = todo . pop ( ) if isinstance ( v . type , GpuArrayType ) : return v . type . context_name if hasattr ( v . tag , 'context_name' ) : return v . tag . context_name if v . owner : if isinstance ( v . owner . op , HostFromGpu ) : return v . owner . inputs [ 0 ] . type . context_name if ( len ( v . owner . inputs ) == 1 ) : todo . extendleft ( v . owner . inputs ) try : get_context ( None ) return None except ContextNotDefined : raise ValueError ( 'Could not infer context from inputs' )
infer the context name to use from the inputs given .