docstr: Test resolution of built-in torch types(e.g. torch.Tensor, torch.device) when a class is recursively compiled.
docstr_tok: ["Test","resolution","of","built-in","torch","types","(","e.g",".","torch.Tensor",",","torch.device",")","when","a","class","is","recursively","compiled","."]
code: def test_recursive_script_builtin_type_resolution(self):
      """
      Test resolution of built-in torch types(e.g. torch.Tensor, torch.device) when a class is recursively compiled.
      """
      # A will be implicitly compiled because it is not annotated with @torch.jit.script
      # but is used in g() below.
      tensor_t = torch.Tensor
      device_t = torch.device
      device_ty = torch.device
  
      class A:
          def __init__(self):
              pass
  
          def f(self, x: tensor_t, y: torch.device) -> tensor_t:
              return x.to(device=y)
  
          def g(self, x: device_t) -> device_ty:
              return x
  
          def h(self, a: "A") -> "A":
              return A()
  
          def i(self, a: List[int]) -> int:
              return a[0]
  
          def j(self, l: List[device_t]) -> device_ty:
              return l[0]
  
      def call_f():
          a = A()
          return a.f(torch.tensor([1]), torch.device("cpu"))
  
      def call_g():
          a = A()
          return a.g(torch.device("cpu"))
  
      def call_i():
          a = A()
          return a.i([3])
  
      def call_j():
          a = A()
          return a.j([torch.device("cpu"), torch.device("cpu")])
  
      for fn in [call_f, call_g, call_i, call_j]:
          self.checkScript(fn, ())
          s = self.getExportImportCopy(torch.jit.script(fn))
          self.assertEqual(s(), fn())
  
imports: import io
  import os
  import sys
  import unittest
  import torch
  import torch.nn
  from torch.testing import FileCheck
  from typing import Any
  from torch.testing._internal.jit_utils import JitTestCase, make_global
  import torch.testing._internal.jit_utils
  from torch.testing._internal.common_utils import IS_SANDCASTLE, skipIfTorchDynamo
  from typing import List, Tuple, Iterable, Optional, Dict
label_desc: Use image node_id 40 for calling the TestClassType obj's underlying member method code with example usage: obj.test_recursive_script_builtin_type_resolution() and returns: a, a, a, a, x, x, A, a, l