parameters: (layer_list)
return_statement: return filtered
docstring: Filter out empty Layer-like containers and uniquify.
docstring_summary: Filter out empty Layer-like containers and uniquify.
docstring_tokens: Filter out empty Layer - like containers and uniquify .
function: def filter_empty_layer_containers(layer_list):
    """Filter out empty Layer-like containers and uniquify."""
    # TODO(b/130381733): Make this an attribute in base_layer.Layer.
    existing = object_identity.ObjectIdentitySet()
    to_visit = layer_list[::-1]
    filtered = []
    while to_visit:
      obj = to_visit.pop()
      if obj in existing:
        continue
      existing.add(obj)
      if is_layer(obj):
        filtered.append(obj)
      elif hasattr(obj, "layers"):
        # Trackable data structures will not show up in ".layers" lists, but
        # the layers they contain will.
        to_visit.extend(obj.layers[::-1])
    return filtered
function_tokens: def filter_empty_layer_containers ( layer_list ) : # TODO(b/130381733): Make this an attribute in base_layer.Layer. existing = object_identity . ObjectIdentitySet ( ) to_visit = layer_list [ : : - 1 ] filtered = [ ] while to_visit : obj = to_visit . pop ( ) if obj in existing : continue existing . add ( obj ) if is_layer ( obj ) : filtered . append ( obj ) elif hasattr ( obj , "layers" ) : # Trackable data structures will not show up in ".layers" lists, but # the layers they contain will. to_visit . extend ( obj . layers [ : : - 1 ] ) return filtered