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)
| 349 | |
| 350 | @contextlib.contextmanager |
| 351 | def 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) |
nothing calls this directly
no test coverage detected