Traverses comp recursively postorder and replaces its constituents.
tff.framework.transform_postorder(comp,transform)
For each element of comp viewed as an expression tree, the transformation
transform is applied first to building blocks it is parameterized by, then
the element itself. The transformation transform should act as an identity
function on the kinds of elements (computation building blocks) it does not
care to transform. This corresponds to a post-order traversal of the
expression tree, i.e., parameters are always transformed left-to-right (in
the order in which they are listed in building block constructors), then the
parent is visited and transformed with the already-visited, and possibly
transformed arguments in place.
Args
comp
A computation_building_block.ComputationBuildingBlock to traverse
and transform bottom-up.
transform
The transformation to apply locally to each building block in
comp. It is a Python function that accepts a building block at input,
and should return a (building block, bool) tuple as output, where the
building block is a computation_building_block.ComputationBuildingBlock
representing either the original building block or a transformed building
block and the bool is a flag indicating if the building block was modified
as.
Returns
The result of applying transform to parts of comp in a bottom-up
fashion, along with a Boolean with the value True if comp was
transformed and False if it was not.
Raises
TypeError
If the arguments are of the wrong computation_types.
NotImplementedError
If the argument is a kind of computation building block
that is currently not recognized.
[null,null,["Last updated 2024-09-20 UTC."],[],[],null,["# tff.framework.transform_postorder\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\nTraverses `comp` recursively postorder and replaces its constituents. \n\n tff.framework.transform_postorder(\n comp, transform\n )\n\nFor each element of `comp` viewed as an expression tree, the transformation\n`transform` is applied first to building blocks it is parameterized by, then\nthe element itself. The transformation `transform` should act as an identity\nfunction on the kinds of elements (computation building blocks) it does not\ncare to transform. This corresponds to a post-order traversal of the\nexpression tree, i.e., parameters are always transformed left-to-right (in\nthe order in which they are listed in building block constructors), then the\nparent is visited and transformed with the already-visited, and possibly\ntransformed arguments in place.\n| **Note:** In particular, in `Call(f,x)`, both `f` and `x` are arguments to `Call`. Therefore, `f` is transformed into `f'`, next `x` into `x'` and finally, `Call(f',x')` is transformed at the end.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `comp` | A `computation_building_block.ComputationBuildingBlock` to traverse and transform bottom-up. |\n| `transform` | The transformation to apply locally to each building block in `comp`. It is a Python function that accepts a building block at input, and should return a (building block, bool) tuple as output, where the building block is a `computation_building_block.ComputationBuildingBlock` representing either the original building block or a transformed building block and the bool is a flag indicating if the building block was modified as. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The result of applying `transform` to parts of `comp` in a bottom-up fashion, along with a Boolean with the value `True` if `comp` was transformed and `False` if it was not. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-----------------------|-------------------------------------------------------------------------------------------|\n| `TypeError` | If the arguments are of the wrong computation_types. |\n| `NotImplementedError` | If the argument is a kind of computation building block that is currently not recognized. |\n\n\u003cbr /\u003e"]]