def is_pure_elemwise(graph, inputs):
 allowed_ops = (tensor.basic.DimShuffle, tensor.basic.Elemwise)
 owner = graph.owner
 op = (graph.owner.op if (graph.owner is not None) else None)
 if ((owner is None) and (graph in inputs)):
  return True
 elif ((owner is None) and isinstance(graph, tensor.basic.TensorConstant)):
  return True
 elif ((owner is None) and (graph not in inputs)):
  return False
 elif ((op is not None) and (not isinstance(op, allowed_ops))):
  return False
 else:
  if isinstance(graph.owner.op, tensor.basic.DimShuffle):
   shuffled = graph.owner.inputs[0]
   if (not isinstance(shuffled, tensor.basic.TensorConstant)):
    return False
  for inp in graph.owner.inputs:
   if (not is_pure_elemwise(inp, inputs)):
    return False
  return True

def is_pure_elemwise ( graph , inputs ) : allowed_ops = ( tensor . basic . DimShuffle , tensor . basic . Elemwise ) owner = graph . owner op = ( graph . owner . op if ( graph . owner is not None ) else None ) if ( ( owner is None ) and ( graph in inputs ) ) : return True elif ( ( owner is None ) and isinstance ( graph , tensor . basic . TensorConstant ) ) : return True elif ( ( owner is None ) and ( graph not in inputs ) ) : return False elif ( ( op is not None ) and ( not isinstance ( op , allowed_ops ) ) ) : return False else : if isinstance ( graph . owner . op , tensor . basic . DimShuffle ) : shuffled = graph . owner . inputs [ 0 ] if ( not isinstance ( shuffled , tensor . basic . TensorConstant ) ) : return False for inp in graph . owner . inputs : if ( not is_pure_elemwise ( inp , inputs ) ) : return False return True
checks whether a graph is purely elementwise and containing only inputs from a given list .