code: def test_tensor_like_functions(self):
      boxes = ToyBaseBoxes(torch.rand(3, 4, 4))
      # new_tensor
      boxes.new_tensor([1, 2, 3])
      # new_full
      boxes.new_full((3, 4), 0)
      # new_empty
      boxes.new_empty((3, 4))
      # new_ones
      boxes.new_ones((3, 4))
      # new_zeros
      boxes.new_zeros((3, 4))
      # size
      self.assertEqual(boxes.size(0), 3)
      self.assertEqual(tuple(boxes.size()), (3, 4, 4))
      # dim
      self.assertEqual(boxes.dim(), 3)
      # device
      self.assertIsInstance(boxes.device, torch.device)
      # dtype
      self.assertIsInstance(boxes.dtype, torch.dtype)
      # numpy
      np_boxes = boxes.numpy()
      self.assertIsInstance(np_boxes, np.ndarray)
      self.assertTrue((np_boxes == np_boxes).all())
      # to
      new_boxes = boxes.to(torch.uint8)
      self.assertEqual(new_boxes.tensor.dtype, torch.uint8)
      if torch.cuda.is_available():
          new_boxes = boxes.to(device="cuda")
          self.assertTrue(new_boxes.tensor.is_cuda)
      # cpu
      if torch.cuda.is_available():
          new_boxes = boxes.to(device="cuda")
          new_boxes = new_boxes.cpu()
          self.assertFalse(new_boxes.tensor.is_cuda)
      # cuda
      if torch.cuda.is_available():
          new_boxes = boxes.cuda()
          self.assertTrue(new_boxes.tensor.is_cuda)
      # clone
      boxes.clone()
      # detach
      boxes.detach()
      # view
      new_boxes = boxes.view(12, 4)
      self.assertEqual(tuple(new_boxes.size()), (12, 4))
      new_boxes = boxes.view(-1, 4)
      self.assertEqual(tuple(new_boxes.size()), (12, 4))
      with self.assertRaises(AssertionError):
          new_boxes = boxes.view(-1)
      # reshape
      new_boxes = boxes.reshape(12, 4)
      self.assertEqual(tuple(new_boxes.size()), (12, 4))
      new_boxes = boxes.reshape(-1, 4)
      self.assertEqual(tuple(new_boxes.size()), (12, 4))
      with self.assertRaises(AssertionError):
          new_boxes = boxes.reshape(-1)
      # expand
      new_boxes = boxes[None, ...].expand(4, -1, -1, -1)
      self.assertEqual(tuple(new_boxes.size()), (4, 3, 4, 4))
      # repeat
      new_boxes = boxes.repeat(2, 2, 1)
      self.assertEqual(tuple(new_boxes.size()), (6, 8, 4))
      with self.assertRaises(AssertionError):
          new_boxes = boxes.repeat(2, 2, 2)
      # transpose
      new_boxes = boxes.transpose(0, 1)
      self.assertEqual(tuple(new_boxes.size()), (4, 3, 4))
      with self.assertRaises(AssertionError):
          new_boxes = boxes.transpose(1, 2)
      # permute
      new_boxes = boxes.permute(1, 0, 2)
      self.assertEqual(tuple(new_boxes.size()), (4, 3, 4))
      with self.assertRaises(AssertionError):
          new_boxes = boxes.permute(2, 1, 0)
      # split
      boxes_list = boxes.split(1, dim=0)
      for box in boxes_list:
          self.assertIsInstance(box, ToyBaseBoxes)
          self.assertEqual(tuple(box.size()), (1, 4, 4))
      boxes_list = boxes.split([1, 2], dim=0)
      with self.assertRaises(AssertionError):
          boxes_list = boxes.split(1, dim=2)
      # chunk
      boxes_list = boxes.split(3, dim=1)
      self.assertEqual(len(boxes_list), 2)
      for box in boxes_list:
          self.assertIsInstance(box, ToyBaseBoxes)
      with self.assertRaises(AssertionError):
          boxes_list = boxes.split(3, dim=2)
      # unbind
      boxes_list = boxes.unbind(dim=1)
      self.assertEqual(len(boxes_list), 4)
      for box in boxes_list:
          self.assertIsInstance(box, ToyBaseBoxes)
          self.assertEqual(tuple(box.size()), (3, 4))
      with self.assertRaises(AssertionError):
          boxes_list = boxes.unbind(dim=2)
      # flatten
      new_boxes = boxes.flatten()
      self.assertEqual(tuple(new_boxes.size()), (12, 4))
      with self.assertRaises(AssertionError):
          new_boxes = boxes.flatten(end_dim=2)
      # squeeze
      boxes = ToyBaseBoxes(torch.rand(1, 3, 1, 4, 4))
      new_boxes = boxes.squeeze()
      self.assertEqual(tuple(new_boxes.size()), (3, 4, 4))
      new_boxes = boxes.squeeze(dim=2)
      self.assertEqual(tuple(new_boxes.size()), (1, 3, 4, 4))
      # unsqueeze
      boxes = ToyBaseBoxes(torch.rand(3, 4, 4))
      new_boxes = boxes.unsqueeze(0)
      self.assertEqual(tuple(new_boxes.size()), (1, 3, 4, 4))
      with self.assertRaises(AssertionError):
          new_boxes = boxes.unsqueeze(3)
      # cat
      with self.assertRaises(ValueError):
          ToyBaseBoxes.cat([])
      box_list = []
      box_list.append(ToyBaseBoxes(torch.rand(3, 4, 4)))
      box_list.append(ToyBaseBoxes(torch.rand(1, 4, 4)))
      with self.assertRaises(AssertionError):
          ToyBaseBoxes.cat(box_list, dim=2)
      cat_boxes = ToyBaseBoxes.cat(box_list, dim=0)
      self.assertIsInstance(cat_boxes, ToyBaseBoxes)
      self.assertEqual((cat_boxes.size()), (4, 4, 4))
      # stack
      with self.assertRaises(ValueError):
          ToyBaseBoxes.stack([])
      box_list = []
      box_list.append(ToyBaseBoxes(torch.rand(3, 4, 4)))
      box_list.append(ToyBaseBoxes(torch.rand(3, 4, 4)))
      with self.assertRaises(AssertionError):
          ToyBaseBoxes.stack(box_list, dim=3)
      stack_boxes = ToyBaseBoxes.stack(box_list, dim=1)
      self.assertIsInstance(stack_boxes, ToyBaseBoxes)
      self.assertEqual((stack_boxes.size()), (3, 2, 4, 4))
  
file_path: mmdetection/tests/test_structures/test_bbox/test_base_boxes.py
imports: from unittest import TestCase
  import numpy
  import torch
  from mmengine.testing import assert_allclose
  from .utils import ToyBaseBoxes
label_desc: Use image node_id 4 for calling the TestBaseBoxes obj's underlying member method code with example usage: obj.test_tensor_like_functions() without return types