Trace function for detecting any NaN/Inf in the tensor.
(tensor)
| 539 | """ |
| 540 | |
| 541 | def _detect_nan_inf(tensor): |
| 542 | """Trace function for detecting any NaN/Inf in the tensor.""" |
| 543 | |
| 544 | if tensor.dtype.is_floating: |
| 545 | mask = math_ops.reduce_any( |
| 546 | gen_math_ops.logical_or( |
| 547 | gen_math_ops.is_nan(tensor), gen_math_ops.is_inf(tensor))) |
| 548 | output_tensor = control_flow_ops.cond(mask, |
| 549 | lambda: constant_op.constant(1.0), |
| 550 | lambda: constant_op.constant(0.0)) |
| 551 | else: |
| 552 | output_tensor = constant_op.constant(0.0) |
| 553 | # The shape has to be 1. Set it if it does not have the information. |
| 554 | output_tensor = array_ops.reshape(output_tensor, [1]) |
| 555 | return output_tensor |
| 556 | |
| 557 | def _compute_signature(tensor, tf_op, cast_to_f32=True): |
| 558 | if cast_to_f32: |