code: def test_complex_bessel(ctx_factory, ref_src):
      ctx = ctx_factory()
      queue = cl.CommandQueue(ctx)
  
      if not has_double_support(ctx.devices[0]):
          from pytest import skip
  
          skip(
              "no double precision support--cannot test complex bessel function"
          )
  
      v = 40
      n = 10**5
  
      rng = np.random.default_rng(seed=13)
      z = np.logspace(-5, 2, n) * np.exp(1j * 2 * np.pi * rng.random(n))
  
      if ref_src == "pyfmmlib":
          pyfmmlib = pytest.importorskip("pyfmmlib")
  
          jv_ref = np.zeros(len(z), "complex")
  
          vin = v + 1
  
          for i in range(len(z)):
              ier, fjs, _, _ = pyfmmlib.jfuns2d(vin, z[i], 1, 0, 10000)
              assert ier == 0
              jv_ref[i] = fjs[v]
  
      elif ref_src == "scipy":
          spec = pytest.importorskip("scipy.special")
          jv_ref = spec.jv(v, z)
  
      else:
          raise ValueError("ref_src")
  
      z_dev = cl_array.to_device(queue, z)
  
      jv_dev = clmath.bessel_jn(v, z_dev)
  
      abs_err_jv = np.abs(jv_dev.get() - jv_ref)
      abs_jv_ref = np.abs(jv_ref)
      rel_err_jv = abs_err_jv / abs_jv_ref
  
      # use absolute error instead if the function value itself is too small
      tiny = 1e-300
      ind = abs_jv_ref < tiny
      rel_err_jv[ind] = abs_err_jv[ind]
  
      # if the reference value is inf or nan, set the error to zero
      ind1 = np.isinf(abs_jv_ref)
      ind2 = np.isnan(abs_jv_ref)
  
      rel_err_jv[ind1] = 0
      rel_err_jv[ind2] = 0
  
      if 0:
          print(abs(z))
          print(np.abs(jv_ref))
          print(np.abs(jv_dev.get()))
          print(rel_err_jv)
  
      max_err = np.max(rel_err_jv)
      assert max_err <= 2e-13, max_err
  
      print("Jv", np.max(rel_err_jv))
  
      if 0:
          import matplotlib.pyplot as pt
  
          pt.loglog(np.abs(z), rel_err_jv)
          pt.show()
  
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 9 for calling a global function with example usage: test_complex_bessel(ctx_factory, ref_src) without return types