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

Function errstate

tensorflow/python/eager/execution_callbacks.py:351–378  ·  view source on GitHub ↗

Context manager setting error state. Example: ``` c = tf.math.log(0.) # -inf with errstate(inf_or_nan=ExecutionCallback.RAISE): tf.math.log(0.) # <-- Raises InfOrNanError. ``` Args: inf_or_nan: An `ExecutionCallback` determining the action for infinity (`inf`) and NaN

(inf_or_nan=None)

Source from the content-addressed store, hash-verified

349
350@contextlib.contextmanager
351def errstate(inf_or_nan=None):
352 """Context manager setting error state.
353
354 Example:
355 ```
356 c = tf.math.log(0.) # -inf
357
358 with errstate(inf_or_nan=ExecutionCallback.RAISE):
359 tf.math.log(0.) # <-- Raises InfOrNanError.
360 ```
361
362 Args:
363 inf_or_nan: An `ExecutionCallback` determining the action for infinity
364 (`inf`) and NaN (`nan`) values. A value of `None` leads to no change in
365 the action of the condition.
366
367 Yields:
368 None.
369
370 Raises:
371 ValueError: If the value of any keyword arguments is invalid.
372 """
373 if not context.executing_eagerly():
374 yield
375 else:
376 old_settings = seterr(inf_or_nan=inf_or_nan)
377 yield
378 seterr(**old_settings)

Callers

nothing calls this directly

Calls 2

seterrFunction · 0.85
executing_eagerlyMethod · 0.80

Tested by

no test coverage detected