'Gated recurrent unit (GRU) function.
Args:
inputs: A 2D batch x input_dim tensor of inputs.
state: The previous state from the last time step.
scope (optional): TF variable scope for defined GRU variables.
Returns:
A tuple (state, state), where state is the newly computed state at time t.
It is returned twice to respect an interface that works for LSTMs.'

def __call__(self, inputs, state, scope=None):

    x = inputs
    h = state
    if (inputs is not None):
        xh = tf.concat(axis=1, values=[x, h])
    else:
        xh = h
    with tf.variable_scope((scope or type(self).__name__)):
        with tf.variable_scope('Gates'):
            (r, u) = tf.split(axis=1, num_or_size_splits=2, value=linear(xh, (2 * self._num_units), alpha=self._weight_scale, name='xh_2_ru', collections=self._collections))
            (r, u) = (tf.sigmoid(r), tf.sigmoid((u + self._forget_bias)))
        with tf.variable_scope('Candidate'):
            xrh = tf.concat(axis=1, values=[x, (r * h)])
            c = tf.tanh(linear(xrh, self._num_units, name='xrh_2_c', collections=self._collections))
        new_h = ((u * h) + ((1 - u) * c))
        new_h = tf.clip_by_value(new_h, (- self._clip_value), self._clip_value)
    return (new_h, new_h)
