tff.framework.Struct
Stay organized with collections
Save and categorize content based on your preferences.
A struct with named or unnamed elements in TFF's internal language.
Inherits From: ComputationBuildingBlock
, TypedObject
, Struct
tff.framework.Struct(
elements, container_type=None
)
The concise notation for structs is <name_1=value_1, ...., name_n=value_n>
for structs with named elements, <value_1, ..., value_n>
for structs with
unnamed elements, or a mixture of these for structs with some named and some
unnamed elements, where name_k
are the names, and value_k
are the value
expressions.
For example, a lambda expression that applies fn
to elements of 2-structs
pointwise could be represented as (arg -> <fn(arg[0]),fn(arg[1])>)
.
Args |
elements
|
The elements of the struct, supplied as a list of (name, value)
pairs, where 'name' can be None in case the corresponding element is not
named and only accessible via an index (see also structure.Struct ).
|
container_type
|
An optional Python container type to associate with the
struct.
|
Raises |
TypeError
|
if arguments are of the wrong types.
|
Attributes |
proto
|
Returns a serialized form of this object as a pb.Computation instance.
|
type_signature
|
Returns the TFF type of this object (an instance of tff.Type ).
|
Methods
children
View source
children() -> Iterator[tff.framework.ComputationBuildingBlock
]
Returns an iterator yielding immediate child building blocks.
compact_representation
View source
compact_representation()
Returns the compact string representation of this building block.
View source
formatted_representation()
Returns the formatted string representation of this building block.
from_proto
View source
@classmethod
from_proto(
computation_proto: pb.Computation
) -> 'Struct'
Returns an instance of a derived class based on 'computation_proto'.
Args |
computation_proto
|
An instance of pb.Computation.
|
Returns |
An instance of a class that implements 'ComputationBuildingBlock' and
that contains the deserialized logic from in 'computation_proto'.
|
Raises |
NotImplementedError
|
if computation_proto contains a kind of computation
for which deserialization has not been implemented yet.
|
ValueError
|
if deserialization failed due to the argument being invalid.
|
named
View source
@classmethod
named(
**kwargs
) -> 'Struct'
Constructs a new Struct
with all named elements.
structural_representation
View source
structural_representation()
Returns the structural string representation of this building block.
unnamed
View source
@classmethod
unnamed(
*args
) -> 'Struct'
Constructs a new Struct
with all unnamed elements.
__eq__
View source
__eq__(
other: object
) -> bool
Return self==value.
__getitem__
View source
__getitem__(
key: Union[int, str, slice]
) -> _T
__iter__
View source
__iter__() -> Iterator[_T]
__len__
View source
__len__() -> int
__ne__
View source
__ne__(
other: object
) -> bool
Return self!=value.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-20 UTC."],[],[],null,["# tff.framework.Struct\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |\n\nA struct with named or unnamed elements in TFF's internal language.\n\nInherits From: [`ComputationBuildingBlock`](../../tff/framework/ComputationBuildingBlock), [`TypedObject`](../../tff/TypedObject), [`Struct`](../../tff/structure/Struct) \n\n tff.framework.Struct(\n elements, container_type=None\n )\n\nThe concise notation for structs is `\u003cname_1=value_1, ...., name_n=value_n\u003e`\nfor structs with named elements, `\u003cvalue_1, ..., value_n\u003e` for structs with\nunnamed elements, or a mixture of these for structs with some named and some\nunnamed elements, where `name_k` are the names, and `value_k` are the value\nexpressions.\n\nFor example, a lambda expression that applies `fn` to elements of 2-structs\npointwise could be represented as `(arg -\u003e \u003cfn(arg[0]),fn(arg[1])\u003e)`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `elements` | The elements of the struct, supplied as a list of (name, value) pairs, where 'name' can be None in case the corresponding element is not named and only accessible via an index (see also [`structure.Struct`](../../tff/structure/Struct)). |\n| `container_type` | An optional Python container type to associate with the struct. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|--------------------------------------|\n| `TypeError` | if arguments are of the wrong types. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|------------------|------------------------------------------------------------------------------------------|\n| `proto` | Returns a serialized form of this object as a pb.Computation instance. |\n| `type_signature` | Returns the TFF type of this object (an instance of [`tff.Type`](../../tff/types/Type)). |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `children`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n children() -\u003e Iterator[../../tff/framework/ComputationBuildingBlock]\n\nReturns an iterator yielding immediate child building blocks.\n\n### `compact_representation`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n compact_representation()\n\nReturns the compact string representation of this building block.\n\n### `formatted_representation`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n formatted_representation()\n\nReturns the formatted string representation of this building block.\n\n### `from_proto`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n @classmethod\n from_proto(\n computation_proto: pb.Computation\n ) -\u003e 'Struct'\n\nReturns an instance of a derived class based on 'computation_proto'.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------------------|--------------------------------|\n| `computation_proto` | An instance of pb.Computation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| An instance of a class that implements 'ComputationBuildingBlock' and that contains the deserialized logic from in 'computation_proto'. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|-----------------------|-------------------------------------------------------------------------------------------------------------|\n| `NotImplementedError` | if computation_proto contains a kind of computation for which deserialization has not been implemented yet. |\n| `ValueError` | if deserialization failed due to the argument being invalid. |\n\n\u003cbr /\u003e\n\n### `named`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n @classmethod\n named(\n **kwargs\n ) -\u003e 'Struct'\n\nConstructs a new `Struct` with all named elements.\n\n### `structural_representation`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n structural_representation()\n\nReturns the structural string representation of this building block.\n\n### `unnamed`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n @classmethod\n unnamed(\n *args\n ) -\u003e 'Struct'\n\nConstructs a new `Struct` with all unnamed elements.\n\n### `__eq__`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n __eq__(\n other: object\n ) -\u003e bool\n\nReturn self==value.\n\n### `__getitem__`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n __getitem__(\n key: Union[int, str, slice]\n ) -\u003e _T\n\n### `__iter__`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n __iter__() -\u003e Iterator[_T]\n\n### `__len__`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n __len__() -\u003e int\n\n### `__ne__`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n __ne__(\n other: object\n ) -\u003e bool\n\nReturn self!=value."]]