code: def test_output_value_trainable_hidden_and_cell(
      self, time_step, input_dim, output_dim
  ):
      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="input"
      )
      _output_nonlinearity = tf.keras.layers.Dense(
          units=output_dim,
          activation=None,
          kernel_initializer=tf.constant_initializer(1),
      )
      with tf.compat.v1.variable_scope("LSTM"):
          self.lstm = lstm(
              all_input_var=_input_var,
              name="lstm",
              lstm_cell=self.lstm_cell,
              step_input_var=_step_input_var,
              step_hidden_var=self._step_hidden_var,
              step_cell_var=self._step_cell_var,
              hidden_state_init_trainable=True,
              cell_state_init_trainable=True,
              output_nonlinearity_layer=_output_nonlinearity,
          )
  
      self.sess.run(tf.compat.v1.global_variables_initializer())
  
      # Compute output by doing t step() on the lstm cell
      outputs_t, _, h_t, c_t, hidden_init, cell_init = self.lstm
      hidden = np.full(
          (self.batch_size, self.hidden_dim), hidden_init.eval()
      )
      cell = np.full(
          (self.batch_size, self.hidden_dim), cell_init.eval()
      )
  
      hidden, cell = self.sess.run(
          [h_t, c_t],
          feed_dict={
              _step_input_var: obs_input,
              self._step_hidden_var: hidden,
              self._step_cell_var: cell,
          },
      )
      with tf.compat.v1.variable_scope("LSTM/lstm", reuse=True):
          hidden_init_var = tf.compat.v1.get_variable(
              name="initial_hidden"
          )
          cell_init_var = tf.compat.v1.get_variable(name="initial_cell")
          assert hidden_init_var in tf.compat.v1.trainable_variables()
          assert cell_init_var in tf.compat.v1.trainable_variables()
  
      full_output1 = self.sess.run(
          outputs_t, feed_dict={_input_var: obs_inputs}
      )
  
      hidden2 = np.full(
          (self.batch_size, self.hidden_dim), hidden_init.eval()
      )
      cell2 = np.full(
          (self.batch_size, self.hidden_dim), cell_init.eval()
      )
      stack_hidden = None
      for i in range(time_step):
          hidden2, cell2 = recurrent_step_lstm(
              input_val=obs_inputs[:, i, :],
              num_units=self.hidden_dim,
              step_hidden=hidden2,
              step_cell=cell2,
              w_x_init=1.0,
              w_h_init=1.0,
              b_init=0.0,
              nonlinearity=np.tanh,
              gate_nonlinearity=lambda x: 1.0 / (1.0 + np.exp(-x)),
          )
          if stack_hidden is None:
              stack_hidden = hidden2[:, np.newaxis, :]
          else:
              stack_hidden = np.concatenate(
                  (stack_hidden, hidden2[:, np.newaxis, :]), axis=1
              )
      output_nonlinearity = np.full(
          (np.prod(hidden2.shape[1:]), output_dim), 1.0
      )
      full_output2 = np.matmul(stack_hidden, output_nonlinearity)
      assert np.allclose(full_output1, full_output2)
  
file_path: garage/tests/garage/tf/models/test_lstm.py
imports: import numpy
  import pytest
  import tensorflow
  from garage.tf.models.lstm import lstm
  from tests.fixtures import TfGraphTestCase
  from tests.helpers import recurrent_step_lstm
label_desc: Use image node_id 4 for calling the TestLSTM obj's underlying member method code with example usage: obj.test_output_value_trainable_hidden_and_cell(time_step, input_dim, output_dim) without return types