code: def test_sort(ctx_factory, scan_kernel):
      from pytest import importorskip
  
      importorskip("mako")
  
      context = ctx_factory()
      queue = cl.CommandQueue(context)
  
      dtype = np.int32
  
      from pyopencl.algorithm import RadixSort
  
      sort = RadixSort(
          context,
          "int *ary",
          key_expr="ary[i]",
          sort_arg_names=["ary"],
          scan_kernel=scan_kernel,
      )
  
      from pyopencl.clrandom import RanluxGenerator
  
      rng = RanluxGenerator(queue, seed=15)
  
      from time import time
  
      # intermediate arrays for largest size cause out-of-memory on low-end GPUs
      for n in scan_test_counts[:-1]:
          if n >= 2000 and isinstance(
              scan_kernel, GenericDebugScanKernel
          ):
              continue
  
          print(n)
  
          print("  rng")
          a_dev = rng.uniform(queue, (n,), dtype=dtype, a=0, b=2**16)
          a = a_dev.get()
  
          dev_start = time()
          print("  device")
          (a_dev_sorted,), evt = sort(a_dev, key_bits=16)
          queue.finish()
          dev_end = time()
          print("  numpy")
          a_sorted = np.sort(a)
          numpy_end = time()
  
          assert (a_dev_sorted.get() == a_sorted).all()
  
          numpy_elapsed = numpy_end - dev_end
          dev_elapsed = dev_end - dev_start
  
          # windows clock has really low resolution (16 milliseconds) and the
          # difference in time will end up at zero for smaller array sizes.
          if numpy_elapsed != 0 and dev_elapsed != 0:
              print(
                  "  dev: {:.2f} MKeys/s numpy: {:.2f} MKeys/s ratio: {:.2f}x".format(
                      1e-6 * n / dev_elapsed,
                      1e-6 * n / numpy_elapsed,
                      numpy_elapsed / dev_elapsed,
                  )
              )
  
imports: import numpy
  import numpy.linalg
  import sys
  from pytools import memoize
  from test_array import general_clrand
  import pytest
  import pyopencl
  import pyopencl.array
  from pyopencl.tools import pytest_generate_tests_for_pyopencl
  from pyopencl.characterize import has_double_support, has_struct_arg_count_bug
  from pyopencl.scan import InclusiveScanKernel, ExclusiveScanKernel, GenericScanKernel, GenericDebugScanKernel
  from pyopencl.characterize import get_pocl_version
label_desc: Use image node_id 26 for calling a global function with example usage: test_sort(ctx_factory, scan_kernel) without return types