tff.framework.transform_preorder
Stay organized with collections
Save and categorize content based on your preferences.
Walks the AST of comp
preorder, calling transform
on the way down.
tff.framework.transform_preorder(
comp: tff.framework.ComputationBuildingBlock
,
transform: Callable[[building_blocks.ComputationBuildingBlock], TransformReturnType]
) -> tff.framework.ComputationBuildingBlock
Notice that this function will stop walking the tree when its transform
function modifies a node; this is to prevent the caller from unexpectedly
kicking off an infinite recursion. For this purpose the transform function
must identify when it has transformed the structure of a building block; if
the structure of the building block is modified but False
is returned as
the second element of the tuple returned by transform
, transform_preorder
may result in an infinite recursion.
Args |
comp
|
Instance of building_blocks.ComputationBuildingBlock to be
transformed in a preorder fashion.
|
transform
|
Transform function to be applied to the nodes of comp . Must
return a two-tuple whose first element is a
building_blocks.ComputationBuildingBlock and whose second element is a
Boolean. If the computation which is passed to comp is returned in a
modified state, must return True for the second element. This Boolean
controls whether or not to stop traversing the tree under comp ; if this
Bool is True , transform_preorder will not traverse this subtree.
|
Returns |
A two-tuple, whose first element is modified version of comp , and
whose second element is a Boolean indicating whether comp was transformed
during the walk.
|
Raises |
TypeError
|
If the argument types don't match those specified above.
|
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.
[null,null,["Last updated 2024-09-20 UTC."],[],[],null,["# tff.framework.transform_preorder\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\nWalks the AST of `comp` preorder, calling `transform` on the way down. \n\n tff.framework.transform_preorder(\n comp: ../../tff/framework/ComputationBuildingBlock,\n transform: Callable[[building_blocks.ComputationBuildingBlock], TransformReturnType]\n ) -\u003e ../../tff/framework/ComputationBuildingBlock\n\nNotice that this function will stop walking the tree when its transform\nfunction modifies a node; this is to prevent the caller from unexpectedly\nkicking off an infinite recursion. For this purpose the transform function\nmust identify when it has transformed the structure of a building block; if\nthe structure of the building block is modified but `False` is returned as\nthe second element of the tuple returned by `transform`, `transform_preorder`\nmay result in an infinite recursion.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `comp` | Instance of `building_blocks.ComputationBuildingBlock` to be transformed in a preorder fashion. |\n| `transform` | Transform function to be applied to the nodes of `comp`. Must return a two-tuple whose first element is a `building_blocks.ComputationBuildingBlock` and whose second element is a Boolean. If the computation which is passed to `comp` is returned in a modified state, must return `True` for the second element. This Boolean controls whether or not to stop traversing the tree under `comp`; if this Bool is `True`, `transform_preorder` will not traverse this subtree. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A two-tuple, whose first element is modified version of `comp`, and whose second element is a Boolean indicating whether `comp` was transformed during the walk. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|----------------------------------------------------------|\n| `TypeError` | If the argument types don't match those specified above. |\n\n\u003cbr /\u003e"]]