docstr: Tests, whether n-step also works on a shared obs/new-obs array.
docstr_tok: ["Tests",",","whether","n-step","also","works","on","a","shared","obs\/new-obs","array","."]
code: def test_n_step_from_same_obs_source_array(self):
      """Tests, whether n-step also works on a shared obs/new-obs array."""
      gamma = 0.99
      # The underlying observation data. Both obs and next_obs will
      # be references into that same np.array.
      underlying_obs = np.arange(0, 8)
      obs = underlying_obs[:7]
      next_obs = underlying_obs[1:]
  
      actions = np.random.randint(-1, 3, size=(7,))
      check_actions = actions.copy()
      rewards = [10.0, 0.0, 100.0, 50.0, 60.0, 10.0, 100.0]
      terminateds = [False, False, False, False, False, False, False]
      truncateds = [False, False, False, False, False, False, True]
  
      batch = SampleBatch(
          {
              SampleBatch.OBS: obs,
              SampleBatch.ACTIONS: actions,
              SampleBatch.REWARDS: rewards,
              SampleBatch.TERMINATEDS: terminateds,
              SampleBatch.TRUNCATEDS: truncateds,
              SampleBatch.NEXT_OBS: next_obs,
          }
      )
      adjust_nstep(4, gamma, batch)
  
      check(batch[SampleBatch.OBS], [0, 1, 2, 3, 4, 5, 6])
      check(batch[SampleBatch.ACTIONS], check_actions)
      check(batch[SampleBatch.NEXT_OBS], [4, 5, 6, 7, 7, 7, 7])
      check(
          batch[SampleBatch.TERMINATEDS],
          [False, False, False, False, False, False, False],
      )
      check(
          batch[SampleBatch.TRUNCATEDS],
          [False, False, False, True, True, True, True],
      )
      check(
          batch[SampleBatch.REWARDS],
          [
              discount_cumsum(np.array(rewards[0:4]), gamma)[0],
              discount_cumsum(np.array(rewards[1:5]), gamma)[0],
              discount_cumsum(np.array(rewards[2:6]), gamma)[0],
              discount_cumsum(np.array(rewards[3:7]), gamma)[0],
              discount_cumsum(np.array(rewards[4:]), gamma)[0],
              discount_cumsum(np.array(rewards[5:]), gamma)[0],
              discount_cumsum(np.array(rewards[6:]), gamma)[0],
          ],
      )
  
file_path: ray/rllib/evaluation/tests/test_postprocessing.py
imports: import numpy
  import unittest
  import ray
  from ray.rllib.evaluation.postprocessing import adjust_nstep, discount_cumsum
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.test_utils import check
label_desc: Use image node_id 7 for calling the TestPostprocessing obj's underlying member method code with example usage: obj.test_n_step_from_same_obs_source_array() without return types