code: def generic_stack_test_helper(
      buffer_size, trajectory_lengths, stack_size
  ):
      batch = setup_buffer(
          buffer_size, trajectory_lengths, stack_size=stack_size
      )
  
      expected = {
          k: [] for k in ["state", "action", "reward", "extra1"]
      }
      terminal_array = []
  
      actual_rb_index = stack_size - 1
      i = 0
      for traj_len in trajectory_lengths:
          traj_start = i
          for j in range(traj_len):
              cur = get_stacked_transition(i, stack_size, traj_start)
              for k in expected:
                  expected[k].append(cur[k])
              terminal_array.append(bool(j == traj_len - 1))
  
              actual_rb_index += 1
              i += 1
          actual_rb_index += stack_size - 1
  
      expected["terminal"] = np.expand_dims(terminal_array, axis=1)
      for k in expected:
          expected[k] = torch.tensor(expected[k])
  
      for k in expected:
          batch_val = getattr(batch, k)
          npt.assert_array_equal(
              batch_val,
              expected[k],
              err_msg=f"key {k}; expected {expected[k]}, got {batch_val}",
              verbose=True,
          )
  
file_path: ReAgent/reagent/test/replay_memory/extra_replay_buffer_test.py
imports: import logging
  import numpy
  import numpy.testing
  import torch
  from reagent.replay_memory.circular_replay_buffer import ReplayBuffer
  from reagent.test.base.horizon_test_base import HorizonTestBase
label_desc: Use image node_id 4 for calling a global function with example usage: generic_stack_test_helper(buffer_size, trajectory_lengths, stack_size) without return types