def _infer_state_dtype(explicit_dtype, state):
    "Infer the dtype of an RNN state.\n\n  Args:\n    explicit_dtype: explicitly declared dtype or None.\n    state: RNN's hidden state. Must be a Tensor or a nested iterable containing\n      Tensors.\n\n  Returns:\n    dtype: inferred dtype of hidden state.\n\n  Raises:\n    ValueError: if `state` has heterogeneous dtypes or is empty.\n  "
    if (explicit_dtype is not None):
        return explicit_dtype
    elif nest.is_sequence(state):
        inferred_dtypes = [element.dtype for element in nest.flatten(state)]
        if (not inferred_dtypes):
            raise ValueError('Unable to infer dtype from empty state.')
        all_same = all([(x == inferred_dtypes[0]) for x in inferred_dtypes])
        if (not all_same):
            raise ValueError('State has tensors of different inferred_dtypes. Unable to infer a single representative dtype.')
        return inferred_dtypes[0]
    else:
        return state.dtype
Infer the dtype of an RNN state.

Args:
  explicit_dtype: explicitly declared dtype or None.
  state: RNN's hidden state. Must be a Tensor or a nested iterable containing
    Tensors.

Returns:
  dtype: inferred dtype of hidden state.

Raises:
  ValueError: if `state` has heterogeneous dtypes or is empty.
def _infer_state_dtype(explicit_dtype, state):
    "Infer the dtype of an RNN state.\n\n  Args:\n    explicit_dtype: explicitly declared dtype or None.\n    state: RNN's hidden state. Must be a Tensor or a nested iterable containing\n      Tensors.\n\n  Returns:\n    dtype: inferred dtype of hidden state.\n\n  Raises:\n    ValueError: if `state` has heterogeneous dtypes or is empty.\n  "
    if (explicit_dtype is not None):
        return explicit_dtype
    elif nest.is_sequence(state):
        inferred_dtypes = [element.dtype for element in nest.flatten(state)]
        if (not inferred_dtypes):
            raise ValueError('Unable to infer dtype from empty state.')
        all_same = all([(x == inferred_dtypes[0]) for x in inferred_dtypes])
        if (not all_same):
            raise ValueError('State has tensors of different inferred_dtypes. Unable to infer a single representative dtype.')
        return inferred_dtypes[0]
    else:
        return state.dtype