Raises a TypeError if cell is not like an RNNCell. NOTE: Do not rely on the error message (in particular in tests) which can be subject to change to increase readability. Use ASSERT_LIKE_RNNCELL_ERROR_REGEXP. Args: cell_name: A string to give a meaningful error referencing to the name
(cell_name, cell)
| 69 | |
| 70 | |
| 71 | def assert_like_rnncell(cell_name, cell): |
| 72 | """Raises a TypeError if cell is not like an RNNCell. |
| 73 | |
| 74 | NOTE: Do not rely on the error message (in particular in tests) which can be |
| 75 | subject to change to increase readability. Use |
| 76 | ASSERT_LIKE_RNNCELL_ERROR_REGEXP. |
| 77 | |
| 78 | Args: |
| 79 | cell_name: A string to give a meaningful error referencing to the name of |
| 80 | the functionargument. |
| 81 | cell: The object which should behave like an RNNCell. |
| 82 | |
| 83 | Raises: |
| 84 | TypeError: A human-friendly exception. |
| 85 | """ |
| 86 | conditions = [ |
| 87 | _hasattr(cell, "output_size"), |
| 88 | _hasattr(cell, "state_size"), |
| 89 | _hasattr(cell, "get_initial_state") or _hasattr(cell, "zero_state"), |
| 90 | callable(cell), |
| 91 | ] |
| 92 | errors = [ |
| 93 | "'output_size' property is missing", "'state_size' property is missing", |
| 94 | "either 'zero_state' or 'get_initial_state' method is required", |
| 95 | "is not callable" |
| 96 | ] |
| 97 | |
| 98 | if not all(conditions): |
| 99 | |
| 100 | errors = [error for error, cond in zip(errors, conditions) if not cond] |
| 101 | raise TypeError("The argument {!r} ({}) is not an RNNCell: {}.".format( |
| 102 | cell_name, cell, ", ".join(errors))) |
| 103 | |
| 104 | |
| 105 | def _concat(prefix, suffix, static=False): |