MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / case

Function case

tensorflow/python/ops/control_flow_ops.py:3386–3490  ·  view source on GitHub ↗

Create a case operation. See also `tf.switch_case`. The `pred_fn_pairs` parameter is a dict or list of pairs of size N. Each pair contains a boolean scalar tensor and a python callable that creates the tensors to be returned if the boolean evaluates to True. `default` is a callable gener

(pred_fn_pairs,
         default=None,
         exclusive=False,
         strict=False,
         name="case")

Source from the content-addressed store, hash-verified

3384
3385@tf_export(v1=["case"])
3386def case(pred_fn_pairs,
3387 default=None,
3388 exclusive=False,
3389 strict=False,
3390 name="case"):
3391 """Create a case operation.
3392
3393 See also `tf.switch_case`.
3394
3395 The `pred_fn_pairs` parameter is a dict or list of pairs of size N.
3396 Each pair contains a boolean scalar tensor and a python callable that
3397 creates the tensors to be returned if the boolean evaluates to True.
3398 `default` is a callable generating a list of tensors. All the callables
3399 in `pred_fn_pairs` as well as `default` (if provided) should return the same
3400 number and types of tensors.
3401
3402 If `exclusive==True`, all predicates are evaluated, and an exception is
3403 thrown if more than one of the predicates evaluates to `True`.
3404 If `exclusive==False`, execution stops at the first predicate which
3405 evaluates to True, and the tensors generated by the corresponding function
3406 are returned immediately. If none of the predicates evaluate to True, this
3407 operation returns the tensors generated by `default`.
3408
3409 `tf.case` supports nested structures as implemented in
3410 `tf.contrib.framework.nest`. All of the callables must return the same
3411 (possibly nested) value structure of lists, tuples, and/or named tuples.
3412 Singleton lists and tuples form the only exceptions to this: when returned by
3413 a callable, they are implicitly unpacked to single values. This
3414 behavior is disabled by passing `strict=True`.
3415
3416 If an unordered dictionary is used for `pred_fn_pairs`, the order of the
3417 conditional tests is not guaranteed. However, the order is guaranteed to be
3418 deterministic, so that variables created in conditional branches are created
3419 in fixed order across runs.
3420
3421 @compatibility(eager)
3422 Unordered dictionaries are not supported in eager mode when `exclusive=False`.
3423 Use a list of tuples instead.
3424 @end_compatibility
3425
3426
3427 **Example 1:**
3428
3429 Pseudocode:
3430
3431 ```
3432 if (x < y) return 17;
3433 else return 23;
3434 ```
3435
3436 Expressions:
3437
3438 ```python
3439 f1 = lambda: tf.constant(17)
3440 f2 = lambda: tf.constant(23)
3441 r = tf.case([(tf.less(x, y), f1)], default=f2)
3442 ```
3443

Callers

nothing calls this directly

Calls 1

_case_helperFunction · 0.85

Tested by

no test coverage detected