A polymorphic assert, works with tensors and boolean expressions. If `cond` is not a tensor, behave like an ordinary assert statement, except that a empty list is returned. If `cond` is a tensor, return a list containing a single TensorFlow assert op. Args: cond: Something evaluates to
(cond, ex_type, msg)
| 61 | |
| 62 | # pylint: disable=invalid-name |
| 63 | def _assert(cond, ex_type, msg): |
| 64 | """A polymorphic assert, works with tensors and boolean expressions. |
| 65 | |
| 66 | If `cond` is not a tensor, behave like an ordinary assert statement, except |
| 67 | that a empty list is returned. If `cond` is a tensor, return a list |
| 68 | containing a single TensorFlow assert op. |
| 69 | |
| 70 | Args: |
| 71 | cond: Something evaluates to a boolean value. May be a tensor. |
| 72 | ex_type: The exception class to use. |
| 73 | msg: The error message. |
| 74 | |
| 75 | Returns: |
| 76 | A list, containing at most one assert op. |
| 77 | """ |
| 78 | if _is_tensor(cond): |
| 79 | return [control_flow_ops.Assert(cond, [msg])] |
| 80 | else: |
| 81 | if not cond: |
| 82 | raise ex_type(msg) |
| 83 | else: |
| 84 | return [] |
| 85 | |
| 86 | |
| 87 | def _is_tensor(x): |
no test coverage detected