code: def test_output_same_as_rnn(
      self, time_step, input_dim, output_dim, hidden_init, cell_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="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=tf.constant_initializer(hidden_init),
              cell_state_init=tf.constant_initializer(cell_init),
              output_nonlinearity_layer=_output_nonlinearity,
          )
  
      self.sess.run(tf.compat.v1.global_variables_initializer())
  
      # Create a RNN and compute the entire outputs
      rnn_layer = tf.keras.layers.RNN(
          cell=self.lstm_cell, return_sequences=True, return_state=True
      )
  
      # Set initial state to all 0s
      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,
      )
      cell_var = tf.compat.v1.get_variable(
          name="initial_cell",
          shape=(self.batch_size, self.hidden_dim),
          initializer=tf.constant_initializer(cell_init),
          trainable=False,
          dtype=tf.float32,
      )
      outputs, hiddens, cells = rnn_layer(
          _input_var, initial_state=[hidden_var, cell_var]
      )
      outputs = _output_nonlinearity(outputs)
  
      self.sess.run(tf.compat.v1.global_variables_initializer())
  
      outputs, hiddens, cells = self.sess.run(
          [outputs, hiddens, cells], feed_dict={_input_var: obs_inputs}
      )
  
      # Compute output by doing t step() on the lstm cell
      hidden = np.full((self.batch_size, self.hidden_dim), hidden_init)
      cell = np.full((self.batch_size, self.hidden_dim), cell_init)
      _, output_t, hidden_t, cell_t, _, _ = self.lstm
      for i in range(time_step):
          output, hidden, cell = self.sess.run(
              [output_t, hidden_t, cell_t],
              feed_dict={
                  _step_input_var: obs_input,
                  self._step_hidden_var: hidden,
                  self._step_cell_var: cell,
              },
          )
          # The output from i-th timestep
          assert np.array_equal(output, outputs[:, i, :])
      assert np.array_equal(hidden, hiddens)
      assert np.array_equal(cell, cells)
  
      # Also the full output from lstm
      full_outputs = self.sess.run(
          self.lstm[0], feed_dict={_input_var: obs_inputs}
      )
      assert np.array_equal(outputs, full_outputs)
  
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 6 for calling the TestLSTM obj's underlying member method code with example usage: obj.test_output_same_as_rnn(time_step, input_dim, output_dim, hidden_init, cell_init) without return types