code: def test_slice(self):
      for arity in (2, 4):
          for vals in (
              torch.rand(8, 2, dtype=torch.float16),
              torch.rand(8, 3, 2, dtype=torch.float16),
          ):
              indices = torch.stack(
                  [torch.randperm(len(vals))[:arity] for _ in range(4)]
              )
              event_shape = (arity * vals.shape[1],) + vals.shape[2:]
              with self.assertRaisesRegex(
                  ValueError, "Shapes .* incompatible"
              ):
                  SliceContainer(
                      values=vals,
                      indices=indices,
                      event_shape=(10 * event_shape[0],)
                      + event_shape[1:],
                  )
  
              # Test some basic propeties
              groups = SliceContainer(
                  vals, indices, event_shape=event_shape
              )
              self.assertEqual(groups.device, vals.device)
              self.assertEqual(groups.dtype, vals.dtype)
              self.assertEqual(groups.shape, groups().shape)
  
              # Test `__eq__`
              self.assertEqual(
                  groups, SliceContainer(vals, indices, event_shape)
              )
              self.assertNotEqual(
                  groups,
                  SliceContainer(
                      torch.rand_like(vals), indices, event_shape
                  ),
              )
  
              # Test `__call__`
              dense = groups()
              index = int(torch.randint(high=len(dense), size=()))
              other = torch.cat([vals[i] for i in indices[index]])
              self.assertTrue(dense[index].equal(other))
  
file_path: botorch/test/utils/test_containers.py
imports: from dataclasses import dataclass
  from unittest.mock import patch
  import torch
  from botorch.utils.containers import BotorchContainer, DenseContainer, SliceContainer
  from botorch.utils.testing import BotorchTestCase
  from torch import Size
label_desc: Use image node_id 3 for calling the TestContainers obj's underlying member method code with example usage: obj.test_slice() without return types