Creates default action for a list of actions and their predicates. It uses the input actions to select an arbitrary as default and makes sure that corresponding predicates have valid values. Args: predicates: a list of bool scalar tensors actions: a list of callable objects which ret
(predicates, actions)
| 3036 | |
| 3037 | |
| 3038 | def _case_create_default_action(predicates, actions): |
| 3039 | """Creates default action for a list of actions and their predicates. |
| 3040 | |
| 3041 | It uses the input actions to select an arbitrary as default and makes sure |
| 3042 | that corresponding predicates have valid values. |
| 3043 | |
| 3044 | Args: |
| 3045 | predicates: a list of bool scalar tensors |
| 3046 | actions: a list of callable objects which return tensors. |
| 3047 | |
| 3048 | Returns: |
| 3049 | a callable |
| 3050 | """ |
| 3051 | k = len(predicates) - 1 # could pick any |
| 3052 | predicate, action = predicates[k], actions[k] |
| 3053 | other_predicates, other_actions = predicates[:k], actions[:k] |
| 3054 | |
| 3055 | def default_action(): |
| 3056 | others_msg = ("Implementation error: " |
| 3057 | "selected default action #%d was called, but some of other " |
| 3058 | "predicates are True: " % k) |
| 3059 | default_msg = ("Input error: " |
| 3060 | "None of conditions evaluated as True:", |
| 3061 | array_ops.stack(predicates, name="preds_c")) |
| 3062 | with ops.control_dependencies([ |
| 3063 | _assert_at_most_n_true(other_predicates, n=0, msg=others_msg), |
| 3064 | Assert(predicate, data=default_msg) |
| 3065 | ]): |
| 3066 | return action() |
| 3067 | |
| 3068 | return default_action, other_predicates, other_actions |
| 3069 | |
| 3070 | |
| 3071 | def _case_verify_and_canonicalize_args(pred_fn_pairs, exclusive, name, |