code: def test_torch_based_pinned_feature(dtype, idtype, shape):
      if dtype == torch.complex128:
          tensor = torch.complex(
              torch.randint(0, 13, shape, dtype=torch.float64),
              torch.randint(0, 13, shape, dtype=torch.float64),
          )
      else:
          tensor = torch.randint(0, 13, shape, dtype=dtype)
      test_tensor = tensor.clone().detach()
      test_tensor_cuda = test_tensor.cuda()
  
      feature = gb.TorchBasedFeature(tensor)
      feature.pin_memory_()
  
      # Test read entire pinned feature, the result should be on cuda.
      assert torch.equal(feature.read(), test_tensor_cuda)
      assert feature.read().is_cuda
      assert torch.equal(
          feature.read(torch.tensor([0], dtype=idtype).cuda()),
          test_tensor_cuda[[0]],
      )
  
      # Test read pinned feature with idx on cuda, the result should be on cuda.
      assert feature.read(
          torch.tensor([0], dtype=idtype).cuda()
      ).is_cuda
  
      # Test read pinned feature with idx on cpu, the result should be on cpu.
      assert torch.equal(
          feature.read(torch.tensor([0], dtype=idtype)),
          test_tensor[[0]],
      )
      assert not feature.read(torch.tensor([0], dtype=idtype)).is_cuda
  
imports: import os
  import tempfile
  import unittest
  from functools import reduce
  from operator import mul
  import backend
  import numpy
  import pydantic
  import pytest
  import torch
  from dgl import graphbolt
label_desc: Use image node_id 7 for calling a global function with example usage: test_torch_based_pinned_feature(dtype, idtype, shape) without return types