parameters: (layer_list)
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]
    while to_visit:
      obj = to_visit.pop()
      if obj in existing:
        continue
      existing.add(obj)
      if is_layer(obj):
        yield obj
      else:
        sub_layers = getattr(obj, "layers", None) or []
  
        # Trackable data structures will not show up in ".layers" lists, but
        # the layers they contain will.
        to_visit.extend(sub_layers[::-1])
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 ] while to_visit : obj = to_visit . pop ( ) if obj in existing : continue existing . add ( obj ) if is_layer ( obj ) : yield obj else : sub_layers = getattr ( obj , "layers" , None ) or [ ] # Trackable data structures will not show up in ".layers" lists, but # the layers they contain will. to_visit . extend ( sub_layers [ : : - 1 ] )