@pytest.mark.parametrize('time_step, input_dim, output_dim, hidden_init', [(1, 1, 1, 0), (1, 1, 3, 0), (1, 3, 1, 0), (3, 1, 1, 0), (3, 3, 1, 0), (3, 3, 3, 0), (1, 1, 1, 0.5), (1, 1, 3, 0.5), (1, 3, 1, 0.5), (3, 1, 1, 0.5), (3, 3, 1, 0.5), (3, 3, 3, 0.5)])
def test_output_same_as_rnn(self, time_step, input_dim, output_dim, hidden_init):
    obs_inputs = np.full((self.batch_size, time_step, input_dim), 1.0)
    obs_input = np.full((self.batch_size, input_dim), 1.0)
    input_var = tf.compat.v1.placeholder(tf.float32, shape=(None, None, input_dim), name='input')
    step_input_var = tf.compat.v1.placeholder(tf.float32, shape=(None, input_dim), name='step_input')
    output_nonlinearity = tf.keras.layers.Dense(units=output_dim, activation=None, kernel_initializer=tf.constant_initializer(1))
    with tf.compat.v1.variable_scope('GRU'):
        self.gru = gru(all_input_var=input_var, name='gru', gru_cell=self.gru_cell, step_input_var=step_input_var, step_hidden_var=self.step_hidden_var, hidden_state_init=tf.constant_initializer(hidden_init), output_nonlinearity_layer=output_nonlinearity)
    self.sess.run(tf.compat.v1.global_variables_initializer())
    rnn_layer = tf.keras.layers.RNN(cell=self.gru_cell, return_sequences=True, return_state=True)
    hidden_var = tf.compat.v1.get_variable(name='initial_hidden', shape=(self.batch_size, self.hidden_dim), initializer=tf.constant_initializer(hidden_init), trainable=False, dtype=tf.float32)
    (outputs, hiddens) = rnn_layer(input_var, initial_state=[hidden_var])
    outputs = output_nonlinearity(outputs)
    self.sess.run(tf.compat.v1.global_variables_initializer())
    (outputs, hiddens) = self.sess.run([outputs, hiddens], feed_dict={input_var: obs_inputs})
    hidden = np.full((self.batch_size, self.hidden_dim), hidden_init)
    (_, output_t, hidden_t, _) = self.gru
    for i in range(time_step):
        (output, hidden) = self.sess.run([output_t, hidden_t], feed_dict={step_input_var: obs_input, self.step_hidden_var: hidden})
        assert np.array_equal(output, outputs[:, i, :])
    assert np.array_equal(hidden, hiddens)
    full_outputs = self.sess.run(self.gru[0], feed_dict={input_var: obs_inputs})
    assert np.array_equal(outputs, full_outputs)
@pytest.mark.parametrize('time_step, input_dim, output_dim, hidden_init', [(1, 1, 1, 0), (1, 1, 3, 0), (1, 3, 1, 0), (3, 1, 1, 0), (3, 3, 1, 0), (3, 3, 3, 0), (1, 1, 1, 0.5), (1, 1, 3, 0.5), (1, 3, 1, 0.5), (3, 1, 1, 0.5), (3, 3, 1, 0.5), (3, 3, 3, 0.5)])
def test_output_same_as_rnn(self, time_step, input_dim, output_dim, hidden_init):
    obs_inputs = np.full((self.batch_size, time_step, input_dim), 1.0)
    obs_input = np.full((self.batch_size, input_dim), 1.0)
    input_var = tf.compat.v1.placeholder(tf.float32, shape=(None, None, input_dim), name='input')
    step_input_var = tf.compat.v1.placeholder(tf.float32, shape=(None, input_dim), name='step_input')
    output_nonlinearity = tf.keras.layers.Dense(units=output_dim, activation=None, kernel_initializer=tf.constant_initializer(1))
    with tf.compat.v1.variable_scope('GRU'):
        self.gru = gru(all_input_var=input_var, name='gru', gru_cell=self.gru_cell, step_input_var=step_input_var, step_hidden_var=self.step_hidden_var, hidden_state_init=tf.constant_initializer(hidden_init), output_nonlinearity_layer=output_nonlinearity)
    self.sess.run(tf.compat.v1.global_variables_initializer())
    rnn_layer = tf.keras.layers.RNN(cell=self.gru_cell, return_sequences=True, return_state=True)
    hidden_var = tf.compat.v1.get_variable(name='initial_hidden', shape=(self.batch_size, self.hidden_dim), initializer=tf.constant_initializer(hidden_init), trainable=False, dtype=tf.float32)
    (outputs, hiddens) = rnn_layer(input_var, initial_state=[hidden_var])
    outputs = output_nonlinearity(outputs)
    self.sess.run(tf.compat.v1.global_variables_initializer())
    (outputs, hiddens) = self.sess.run([outputs, hiddens], feed_dict={input_var: obs_inputs})
    hidden = np.full((self.batch_size, self.hidden_dim), hidden_init)
    (_, output_t, hidden_t, _) = self.gru
    for i in range(time_step):
        (output, hidden) = self.sess.run([output_t, hidden_t], feed_dict={step_input_var: obs_input, self.step_hidden_var: hidden})
        assert np.array_equal(output, outputs[:, i, :])
    assert np.array_equal(hidden, hiddens)
    full_outputs = self.sess.run(self.gru[0], feed_dict={input_var: obs_inputs})
    assert np.array_equal(outputs, full_outputs)