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.
|