code: def recurrent_step_gru(
      input_val,
      num_units,
      step_hidden,
      w_x_init,
      w_h_init,
      b_init,
      nonlinearity,
      gate_nonlinearity,
      forget_bias=1.0,
  ):
      """Helper function for performing feedforward of a GRU cell.
  
      Args:
          input_val (tf.Tensor): Input placeholder.
          num_units (int): Hidden dimension for GRU cell.
          step_hidden (tf.Tensor): Place holder for step hidden state.
          nonlinearity (callable): Activation function for intermediate
              dense layer(s). It should return a tf.Tensor. Set it to
              None to maintain a linear activation.
          w_x_init (callable): Initializer function for the weight
              of intermediate dense layer(s). The function should return a
              tf.Tensor.
          b_init (callable): Initializer function for the bias
              of intermediate dense layer(s). The function should return a
              tf.Tensor.
          gate_nonlinearity (callable): Activation function for recurrent
              layers. It should return a tf.Tensor. Set it to None to
              maintain a linear activation.
          w_h_init (callable): Initializer function for the weight
              of recurrent layer(s). The function should return a
              tf.Tensor.
          forget_bias (float): Bias to be added to the forget gate at
              initialization. It's used to reduce the scale of forgetting at the
              beginning of the training.
  
      Returns:
          tf.Tensor: Final hidden state after feedforward.
  
      Note:
          Reset gate:        r(t) = f_r(x(t) @ W_xr + h(t-1) @ W_hr + b_r)
          Update gate:       u(t) = f_u(x(t) @ W_xu + h(t-1) @ W_hu + b_u)
          Cell gate:         c(t) = f_c(x(t) @ W_xc + r(t) *
                                    (h(t-1) @ W_hc) + b_c)
          New hidden state:  h(t) = u_t * h(t-1) + (1 - u(t)) * c(t)
          The reset, update, and cell vectors must have the same dimension
          as the hidden state.
  
      """
  
      def f(x):
          """Linear function.
  
          Args:
              x (float): Input variable.
  
          Returns:
              float: Ouput variable.
  
          """
          return x
  
      del forget_bias
      if nonlinearity is None:
          nonlinearity = f
      if gate_nonlinearity is None:
          gate_nonlinearity = f
  
      input_dim = np.prod(input_val.shape[1:])
      # Weights for the update gate
      w_xz = np.full((input_dim, num_units), w_x_init)
      w_hz = np.full((num_units, num_units), w_h_init)
      b_z = np.full((num_units,), b_init)
      # Weights for the reset gate
      w_xr = np.full((input_dim, num_units), w_x_init)
      w_hr = np.full((num_units, num_units), w_h_init)
      b_r = np.full((num_units,), b_init)
      # Weights for the hidden gate
      w_xh = np.full((input_dim, num_units), w_x_init)
      w_hh = np.full((num_units, num_units), w_h_init)
      b_h = np.full((num_units,), b_init)
  
      w_x_zrh = np.concatenate([w_xz, w_xr, w_xh], axis=1)
      w_h_zrh = np.concatenate([w_hz, w_hr, w_hh], axis=1)
  
      x_zrh = np.matmul(input_val, w_x_zrh)
      h_zrh = np.matmul(step_hidden, w_h_zrh)
  
      x_z = x_zrh[:, :num_units]
      x_r = x_zrh[:, num_units : num_units * 2]
      x_h = x_zrh[:, num_units * 2 : num_units * 3]
  
      h_z = h_zrh[:, :num_units]
      h_r = h_zrh[:, num_units : num_units * 2]
      h_h = h_zrh[:, num_units * 2 : num_units * 3]
  
      z = gate_nonlinearity(x_z + h_z + b_z)
      r = gate_nonlinearity(x_r + h_r + b_r)
      hh = nonlinearity(x_h + r * h_h + b_h)
      h = z * step_hidden + (1 - z) * hh
  
      return h
  
file_path: garage/tests/helpers.py
imports: import cloudpickle
  import numpy
  import pytest
  from garage import Environment
  from tests.quirks import KNOWN_GYM_RENDER_NOT_IMPLEMENTED
label_desc: Use image node_id 5 for calling a global function with example usage: recurrent_step_gru(input_val, num_units, step_hidden, w_x_init, w_h_init, b_init, nonlinearity, gate_nonlinearity, forget_bias) and returns: h, x