code: def make_unary_function_test(
      name, limits=(0, 1), threshold=0, use_complex=False
  ):
      (a, b) = limits
      a = float(a)
      b = float(b)
  
      def test(ctx_factory):
          context = ctx_factory()
          queue = cl.CommandQueue(context)
  
          gpu_func = getattr(clmath, name)
          cpu_func = getattr(np, numpy_func_names.get(name, name))
  
          dev = context.devices[0]
  
          if has_double_support(dev):
              if (
                  use_complex
                  and has_struct_arg_count_bug(dev) == "apple"
              ):
                  dtypes = [np.float32, np.float64, np.complex64]
              elif use_complex:
                  dtypes = [
                      np.float32,
                      np.float64,
                      np.complex64,
                      np.complex128,
                  ]
              else:
                  dtypes = [np.float32, np.float64]
          else:
              if use_complex:
                  dtypes = [np.float32, np.complex64]
              else:
                  dtypes = [np.float32]
  
          for s in sizes:
              for dtype in dtypes:
                  dtype = np.dtype(dtype)
  
                  args = cl_array.arange(
                      queue, a, b, (b - a) / s, dtype=dtype
                  )
                  if dtype.kind == "c":
                      # args = args + dtype.type(1j) * args
                      args = args + args * dtype.type(1j)
  
                  gpu_results = gpu_func(args).get()
                  cpu_results = cpu_func(args.get())
  
                  my_threshold = threshold
                  if dtype.kind == "c" and isinstance(
                      use_complex, float
                  ):
                      my_threshold = use_complex
  
                  max_err = np.max(np.abs(cpu_results - gpu_results))
                  assert (max_err <= my_threshold).all(), (
                      max_err,
                      name,
                      dtype,
                  )
  
      return test
  
file_path: pyopencl/test/test_clmath.py
imports: import math
  import numpy
  import pytest
  import pyopencl.array
  import pyopencl
  import pyopencl.clmath
  from pyopencl.tools import pytest_generate_tests_for_pyopencl
  from pyopencl.characterize import has_double_support, has_struct_arg_count_bug
label_desc: Use image node_id 1 for calling a global function with example usage: make_unary_function_test(name, limits, threshold, use_complex) and returns: test