code: def test_cast_tensor_type():
      inputs = torch.rand(10)
      if torch.cuda.is_available():
          inputs = inputs.cuda()
      with pytest.raises(AssertionError):
          cast_tensor_type(inputs, src_type=None, dst_type=None)
      # input is a float
      out = cast_tensor_type(10.0, dst_type=torch.half)
      assert out == 10.0 and isinstance(out, float)
      # convert Tensor to fp16 and re-convert to fp32
      fp16_out = cast_tensor_type(inputs, dst_type=torch.half)
      assert fp16_out.dtype == torch.half
      fp32_out = cast_tensor_type(fp16_out, dst_type=torch.float32)
      assert fp32_out.dtype == torch.float32
  
      # input is a list
      list_input = [inputs, inputs]
      list_outs = cast_tensor_type(list_input, dst_type=torch.half)
      assert len(list_outs) == len(list_input) and isinstance(
          list_outs, list
      )
      for out in list_outs:
          assert out.dtype == torch.half
      # input is a dict
      dict_input = {"test1": inputs, "test2": inputs}
      dict_outs = cast_tensor_type(dict_input, dst_type=torch.half)
      assert len(dict_outs) == len(dict_input) and isinstance(
          dict_outs, dict
      )
  
      # convert the input tensor to CPU and re-convert to GPU
      if torch.cuda.is_available():
          cpu_device = torch.empty(0).device
          gpu_device = inputs.device
          cpu_out = cast_tensor_type(inputs, dst_type=cpu_device)
          assert cpu_out.device == cpu_device
  
          gpu_out = cast_tensor_type(inputs, dst_type=gpu_device)
          assert gpu_out.device == gpu_device
  
imports: import numpy
  import pytest
  import torch
  from mmdet.utils import AvoidOOM
  from mmdet.utils.memory import cast_tensor_type
label_desc: Use image node_id 2 for calling a global function with example usage: test_cast_tensor_type() without return types