MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / is_flat

Function is_flat

tensorflow/python/compiler/xla/xla.py:397–429  ·  view source on GitHub ↗

Checks if outputs is a flat structure. Following structures and values are considered flat: 1) None 2) A single object 3) A list or tuple of Tensors/Operations The only structures that this function understands are sequences and dictionaries. E.g. this means that if output

(outputs)

Source from the content-addressed store, hash-verified

395
396
397def is_flat(outputs):
398 """Checks if outputs is a flat structure.
399
400 Following structures and values are considered flat:
401 1) None
402 2) A single object
403 3) A list or tuple of Tensors/Operations
404
405 The only structures that this function understands are sequences and
406 dictionaries. E.g. this means that if outputs contains a single
407 user-defined Object, it is considered to be flat. Errors are raised later on
408 if that Object cannot be converted to a Tensor.
409
410 Args:
411 outputs: Output from `computation` inside `xla.compile`.
412
413 Returns:
414 A boolean indicates whether outputs is flat.
415 """
416 # If outputs is a list or tuple, check if it has any nested structure. If
417 # there is, then outputs is non-flat.
418 if isinstance(outputs, collections.Sequence):
419 for o in outputs:
420 if isinstance(o, collections.Sequence) or isinstance(o, dict):
421 return False
422
423 # If outputs is a dict, it is non-flat.
424 if isinstance(outputs, dict):
425 return False
426
427 # Getting here means either outputs itself is a single non-structured value
428 # or it is a flat list of single non-structured values.
429 return True
430
431
432def _postprocess_flat_outputs(outputs):

Callers 1

_compile_internalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected