docstr: Tests, whether slicing can be done on SampleBatches.
docstr_tok: ["Tests",",","whether","slicing","can","be","done","on","SampleBatches","."]
code: def test_slicing(self):
      """Tests, whether slicing can be done on SampleBatches."""
      s1 = SampleBatch(
          {
              "a": np.array([1, 2, 3, 2, 3, 4]),
              "b": {"c": np.array([4, 5, 6, 5, 6, 7])},
          }
      )
      check(
          s1[:3],
          {
              "a": [1, 2, 3],
              "b": {"c": [4, 5, 6]},
          },
      )
      check(
          s1[0:3],
          {
              "a": [1, 2, 3],
              "b": {"c": [4, 5, 6]},
          },
      )
      check(
          s1[1:4],
          {
              "a": [2, 3, 2],
              "b": {"c": [5, 6, 5]},
          },
      )
      check(
          s1[1:],
          {
              "a": [2, 3, 2, 3, 4],
              "b": {"c": [5, 6, 5, 6, 7]},
          },
      )
      check(
          s1[3:4],
          {
              "a": [2],
              "b": {"c": [5]},
          },
      )
  
      # When we change the slice, the original SampleBatch should also
      # change (shared underlying data).
      s1[:3]["a"][0] = 100
      s1[1:2]["a"][0] = 200
      check(s1["a"][0], 100)
      check(s1["a"][1], 200)
  
      # Seq-len batches should be auto-sliced along sequences,
      # no matter what.
      s2 = SampleBatch(
          {
              "a": np.array([1, 2, 3, 2, 3, 4]),
              "b": {"c": np.array([4, 5, 6, 5, 6, 7])},
              SampleBatch.SEQ_LENS: [2, 3, 1],
              "state_in_0": [1.0, 3.0, 4.0],
          }
      )
      # We would expect a=[1, 2, 3] now, but due to the sequence
      # boundary, we stop earlier.
      check(
          s2[:3],
          {
              "a": [1, 2],
              "b": {"c": [4, 5]},
              SampleBatch.SEQ_LENS: [2],
              "state_in_0": [1.0],
          },
      )
      # Split exactly at a seq-len boundary.
      check(
          s2[:5],
          {
              "a": [1, 2, 3, 2, 3],
              "b": {"c": [4, 5, 6, 5, 6]},
              SampleBatch.SEQ_LENS: [2, 3],
              "state_in_0": [1.0, 3.0],
          },
      )
      # Split above seq-len boundary.
      check(
          s2[:50],
          {
              "a": [1, 2, 3, 2, 3, 4],
              "b": {"c": [4, 5, 6, 5, 6, 7]},
              SampleBatch.SEQ_LENS: [2, 3, 1],
              "state_in_0": [1.0, 3.0, 4.0],
          },
      )
      check(
          s2[:],
          {
              "a": [1, 2, 3, 2, 3, 4],
              "b": {"c": [4, 5, 6, 5, 6, 7]},
              SampleBatch.SEQ_LENS: [2, 3, 1],
              "state_in_0": [1.0, 3.0, 4.0],
          },
      )
  
imports: import copy
  import functools
  import os
  import unittest
  import numpy
  import torch
  import tree
  import ray
  from ray.rllib.models.repeated_values import RepeatedValues
  from ray.rllib.policy.sample_batch import SampleBatch, attempt_count_timesteps, concat_samples
  from ray.rllib.utils.compression import is_compressed
  from ray.rllib.utils.framework import try_import_torch
  from ray.rllib.utils.test_utils import check
  from ray.rllib.utils.torch_utils import convert_to_torch_tensor
label_desc: Use image node_id 10 for calling the TestSampleBatch obj's underlying member method code with example usage: obj.test_slicing() without return types