Return either fn1() or fn2() based on the boolean predicate/value `pred`. If `pred` is bool or has a constant value it would use `static_cond`, otherwise it would use `tf.cond`. Args: pred: A scalar determining whether to return the result of `fn1` or `fn2`. fn1: The callable to be p
(pred, fn1, fn2, name=None)
| 195 | |
| 196 | |
| 197 | def smart_cond(pred, fn1, fn2, name=None): |
| 198 | """Return either fn1() or fn2() based on the boolean predicate/value `pred`. |
| 199 | |
| 200 | If `pred` is bool or has a constant value it would use `static_cond`, |
| 201 | otherwise it would use `tf.cond`. |
| 202 | |
| 203 | Args: |
| 204 | pred: A scalar determining whether to return the result of `fn1` or `fn2`. |
| 205 | fn1: The callable to be performed if pred is true. |
| 206 | fn2: The callable to be performed if pred is false. |
| 207 | name: Optional name prefix when using tf.cond |
| 208 | Returns: |
| 209 | Tensors returned by the call to either `fn1` or `fn2`. |
| 210 | """ |
| 211 | pred_value = constant_value(pred) |
| 212 | if pred_value is not None: |
| 213 | # Use static_cond if pred has a constant value. |
| 214 | return static_cond(pred_value, fn1, fn2) |
| 215 | else: |
| 216 | # Use dynamic cond otherwise. |
| 217 | return control_flow_ops.cond(pred, fn1, fn2, name) |
| 218 | |
| 219 | |
| 220 | def get_variable_collections(variables_collections, name): |
nothing calls this directly
no test coverage detected