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

Function smart_cond

tensorflow/contrib/layers/python/layers/utils.py:197–217  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

195
196
197def 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
220def get_variable_collections(variables_collections, name):

Callers

nothing calls this directly

Calls 3

static_condFunction · 0.85
constant_valueFunction · 0.70
condMethod · 0.45

Tested by

no test coverage detected