![]() |
An implementation of tff.Type
representing structural types in TFF.
tff.types.StructType(
elements: Iterable[object],
*,
convert: bool = True,
enable_well_formed_check: bool = True
)
Used in the notebooks
Used in the tutorials |
---|
Elements initialized by name can be accessed as foo.name
, and otherwise by
index, foo[index]
.
Args | |
---|---|
elements
|
An iterable of element specifications. Each element
specification is either a type spec (an instance of tff.Type or
something convertible to it via tff.types.to_type ) for the element, or
a (name, spec) for elements that have defined names. Alternatively, one
can supply here an instance of collections.OrderedDict mapping element
names to their types (or things that are convertible to types).
|
convert
|
A flag to determine if the elements should be converted using
tff.types.to_type or not.
|
enable_well_formed_check
|
This flag exists only so that
StructWithPythonType can disable the well-formedness check, as the
type won't be well-formed until the subclass has finished its own
initialization.
|
Attributes | |
---|---|
python_container
|
Methods
check_abstract
check_abstract() -> None
Check that this is a tff.AbstractType
.
check_assignable_from
check_assignable_from(
source_type: 'Type'
) -> None
Raises if values of source_type
cannot be cast to this type.
check_equivalent_to
check_equivalent_to(
other: 'Type'
) -> None
Raises if values of 'other' cannot be cast to and from this type.
check_federated
check_federated() -> None
Check that this is a tff.FederatedType
.
check_function
check_function() -> None
Check that this is a tff.FunctionType
.
check_identical_to
check_identical_to(
other: 'Type'
) -> None
Raises if other
and Type
are not exactly identical.
check_placement
check_placement() -> None
Check that this is a tff.PlacementType
.
check_sequence
check_sequence() -> None
Check that this is a tff.SequenceType
.
check_struct
check_struct() -> None
Check that this is a tff.StructType
.
check_struct_with_python
check_struct_with_python() -> None
Check that this is a tff.StructWithPythonType
.
check_tensor
check_tensor() -> None
Check that this is a tff.TensorType
.
children
children()
Returns a generator yielding immediate child types.
compact_representation
compact_representation() -> str
Returns the compact string representation of this type.
formatted_representation
formatted_representation() -> str
Returns the formatted string representation of this type.
is_abstract
is_abstract() -> bool
Returns whether or not this type is a tff.AbstractType
.
is_assignable_from
is_assignable_from(
source_type: 'Type'
) -> bool
Returns whether values of source_type
can be cast to this type.
is_equivalent_to
is_equivalent_to(
other: 'Type'
) -> bool
Returns whether values of other
can be cast to and from this type.
is_federated
is_federated() -> bool
Returns whether or not this type is a tff.FederatedType
.
is_function
is_function() -> bool
Returns whether or not this type is a tff.FunctionType
.
is_identical_to
is_identical_to(
other: 'Type'
) -> bool
Returns whether or not self
and other
are exactly identical.
is_placement
is_placement() -> bool
Returns whether or not this type is a tff.PlacementType
.
is_sequence
is_sequence() -> bool
Returns whether or not this type is a tff.SequenceType
.
is_struct
is_struct() -> bool
Returns whether or not this type is a tff.StructType
.
is_struct_with_python
is_struct_with_python() -> bool
Returns whether or not this type is a tff.StructWithPythonType
.
is_tensor
is_tensor() -> bool
Returns whether or not this type is a tff.TensorType
.
named
@classmethod
named( **kwargs ) -> 'Struct'
Constructs a new Struct
with all named elements.
unnamed
@classmethod
unnamed( *args ) -> 'Struct'
Constructs a new Struct
with all unnamed elements.
__eq__
__eq__(
other
)
Determines whether two type definitions are identical.
Note that this notion of equality is stronger than equivalence. Two types with equivalent definitions may not be identical, e.g., if they represent templates with differently named type variables in their definitions.
Args | |
---|---|
other
|
The other type to compare against. |
Returns | |
---|---|
True iff type definitions are syntatically identical (as defined above),
or False otherwise.
|
Raises | |
---|---|
NotImplementedError
|
If not implemented in the derived class. |
__getitem__
__getitem__(
key: Union[int, str, slice]
)
__iter__
__iter__()
__len__
__len__()
__ne__
__ne__(
other
)
Return self!=value.