returnn.tensor.control_flow_ctx#

Control flow context

class returnn.tensor.control_flow_ctx.ControlFlowContext(*, kind: str, identifier: str, outer_ctx: ControlFlowContext | None = None)[source]#

This represents the current control flow context, e.g. whether this runs in a loop or a conditional branch.

In case of TF, this is a simple wrapper around the TF ControlFlowContext which comes from tf.while_loop or tf.cond.

We have this wrapper to refer to a context which might not exist yet (e.g. at template construction time). Also, we might want to store additional information, such the spatial dim tag of the loop.

Parameters:
  • kind – from ControlFlowContext.Types

  • outer_ctx

class Types[source]#

Possible types of context.

Loop = 'loop'[source]#
CondTrue = 'cond-true'[source]#
CondFalse = 'cond-false'[source]#
repr_inner()[source]#
Return type:

str

classmethod abs_ctx_stack(ctx)[source]#
Parameters:

ctx (ControlFlowContext|None) –

Return type:

list[ControlFlowContext]

classmethod abs_ctx_stack_with_root(ctx)[source]#
Parameters:

ctx (ControlFlowContext|None) –

Return type:

list[ControlFlowContext|None]

Returns:

chain of ctx, last is self, first is None

classmethod is_parent_or_same(parent, child)[source]#
Parameters:
Return type:

bool

classmethod collect_parent_dims(ctx)[source]#
Parameters:

ctx (ControlFlowContext|None) –

Return type:

list[Dim]

is_loop()[source]#
Return type:

bool

is_cond()[source]#
Return type:

bool

property outer_ctx[source]#
Return type:

ControlFlowContext|None

property tf_control_flow_ctx[source]#
Return type:

tensorflow.python.ops.control_flow_ops.ControlFlowContext|None

property loop_spatial_dim[source]#
Return type:

Dim|None