code: def reference_polygamma(x, n):
      # WEIRD `scipy.special.polygamma` behavior
      # >>> scipy.special.polygamma(0, np.array(501, dtype=np.float32)).dtype
      # dtype('float64')
      # >>> scipy.special.polygamma(0, np.array([501], dtype=np.float32)).dtype
      # dtype('float32')
      #
      # Thus we cast output to the default torch dtype or preserve double
      result_dtype = torch_to_numpy_dtype_dict[
          torch.get_default_dtype()
      ]
      if x.dtype == np.double:
          result_dtype = np.double
      return scipy.special.polygamma(n, x).astype(result_dtype)
  
file_path: pytorch/torch/testing/_internal/opinfo/definitions/special.py
imports: import unittest
  from functools import partial
  from itertools import product
  from typing import List
  import numpy
  import torch
  from torch.testing import make_tensor
  from torch.testing._internal.common_device_type import precisionOverride, tol, toleranceOverride
  from torch.testing._internal.common_dtype import all_types_and, floating_types
  from torch.testing._internal.common_utils import TEST_SCIPY, torch_to_numpy_dtype_dict
  from torch.testing._internal.opinfo.core import BinaryUfuncInfo, DecorateInfo, L, NumericsFilter, OpInfo, S, SampleInput, UnaryUfuncInfo
  from torch.testing._internal.opinfo.refs import ElementwiseBinaryPythonRefInfo, ElementwiseUnaryPythonRefInfo
  from torch.testing._internal.opinfo.utils import np_unary_ufunc_integer_promotion_wrapper
label_desc: Use image node_id 3 for calling a global function with example usage: reference_polygamma(x, n) and returns: scipy