def test_gradient_paths(self):
    time_step = 3
    input_dim = 2
    output_dim = 4
    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, output_nonlinearity_layer=output_nonlinearity)
    self.sess.run(tf.compat.v1.global_variables_initializer())
    (outputs_t, output_t, h_t, hidden_init) = self.gru
    hidden = np.full((self.batch_size, self.hidden_dim), hidden_init.eval())
    grads_step_o_i = tf.gradients(output_t, step_input_var)
    grads_step_o_h = tf.gradients(output_t, self.step_hidden_var)
    grads_step_h = tf.gradients(h_t, step_input_var)
    self.sess.run([grads_step_o_i, grads_step_o_h, grads_step_h], feed_dict={step_input_var: obs_input, self.step_hidden_var: hidden})
    grads_step_o_i = tf.gradients(outputs_t, step_input_var)
    grads_step_o_h = tf.gradients(outputs_t, self.step_hidden_var)
    grads_step_h = tf.gradients(h_t, input_var)
    with pytest.raises(TypeError):
        self.sess.run(grads_step_o_i, feed_dict={step_input_var: obs_input, self.step_hidden_var: hidden})
    with pytest.raises(TypeError):
        self.sess.run(grads_step_o_h, feed_dict={step_input_var: obs_input, self.step_hidden_var: hidden})
    with pytest.raises(TypeError):
        self.sess.run(grads_step_h, feed_dict={input_var: obs_inputs})
def test_gradient_paths(self):
    time_step = 3
    input_dim = 2
    output_dim = 4
    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, output_nonlinearity_layer=output_nonlinearity)
    self.sess.run(tf.compat.v1.global_variables_initializer())
    (outputs_t, output_t, h_t, hidden_init) = self.gru
    hidden = np.full((self.batch_size, self.hidden_dim), hidden_init.eval())
    grads_step_o_i = tf.gradients(output_t, step_input_var)
    grads_step_o_h = tf.gradients(output_t, self.step_hidden_var)
    grads_step_h = tf.gradients(h_t, step_input_var)
    self.sess.run([grads_step_o_i, grads_step_o_h, grads_step_h], feed_dict={step_input_var: obs_input, self.step_hidden_var: hidden})
    grads_step_o_i = tf.gradients(outputs_t, step_input_var)
    grads_step_o_h = tf.gradients(outputs_t, self.step_hidden_var)
    grads_step_h = tf.gradients(h_t, input_var)
    with pytest.raises(TypeError):
        self.sess.run(grads_step_o_i, feed_dict={step_input_var: obs_input, self.step_hidden_var: hidden})
    with pytest.raises(TypeError):
        self.sess.run(grads_step_o_h, feed_dict={step_input_var: obs_input, self.step_hidden_var: hidden})
    with pytest.raises(TypeError):
        self.sess.run(grads_step_h, feed_dict={input_var: obs_inputs})