tf.switch_case

Create a switch/case operation, i.e. an integer-indexed conditional.

See also tf.case.

This op can be substantially more efficient than tf.case when exactly one branch will be selected. tf.switch_case is more like a C++ switch/case statement than tf.case, which is more like an if/elif/elif/else chain.

The branch_fns parameter is either a dict from int to callables, or list of (int, callable) pairs, or simply a list of callables (in which case the index is implicitly the key). The branch_index Tensor is used to select an element in branch_fns with matching int key, falling back to default if none match, or max(keys) if no default is provided. The keys must form a contiguous set from 0 to len(branch_fns) - 1.

tf.switch_case supports nested structures as implemented in tf.nest. All callables must return the same (possibly nested) value structure of lists, tuples, and/or named tuples.

Example:

Pseudocode:

switch (