|View source on GitHub|
Represents a struct-like structure with named and/or unnamed fields.
tff.structure.Struct( elements: Iterable[Tuple[Optional[str], Any]] )
Structs are similar to
collections.namedtuple in that their elements can
be accessed by name or by index. However,
Structs provide a performance
collections.namedtuple by using a single class to
represent values with many different possible structures, rather than
creating a brand new class for every new instance.
Structs are commonly used inside Tensorflow Federated as a standard
intermediate representation of other structure types, including
x = Struct([('foo', 10), (None, 20), ('bar', 30)]) len(x) == 3 x == 10 x == 20 x == 30 list(iter(x)) == [10, 20, 30] dir(x) == ['bar', 'foo'] x.foo == 10 x['bar'] == 30
Note that field names are optional, allowing
Struct to be used like an
ordinary positional tuple.
An iterable of element specifications, each being a pair
consisting of the element name (either
__eq__( other )
__getitem__( key: Union[int, str, slice] )
__ne__( other )