class_docstr: Sort an array (or one axis of one) using a sorting network.
  
  Will only work if the axis of the array to be sorted has a length
  that is a power of 2.
  
  .. versionadded:: 2015.2
  
  .. seealso:: :class:`pyopencl.algorithm.RadixSort`
  
  .. automethod:: __call__
class_docstr_tok: ["Sort","an","array","(","or","one","axis","of","one",")","using","a","sorting","network",".","Will","only","work","if","the","axis","of","the","array","to","be","sorted","has","a","length","that","is","a","power","of","2",".","..","versionadded",":",":","2015.2","..","seealso",":",":",":","class",":","`","pyopencl.algorithm.RadixSort","`","..","automethod",":",":","__call__"]
docstr: :arg arr: the array to be sorted. Will be overwritten with the sorted array.
  :arg idx: an array of indices to be tracked along with the sorting of *arr*
  :arg queue: a :class:`pyopencl.CommandQueue`, defaults to the array's queue
      if None
  :arg wait_for: a list of :class:`pyopencl.Event` instances or None
  :arg axis: the axis of the array by which to sort
  
  :returns: a tuple (sorted_array, event)
docstr_tok: [":","arg","arr",":","the","array","to","be","sorted",".","Will","be","overwritten","with","the","sorted","array",".",":","arg","idx",":","an","array","of","indices","to","be","tracked","along","with","the","sorting","of","*","arr","*",":","arg","queue",":","a",":","class",":","`","pyopencl.CommandQueue","`",",","defaults","to","the","array","'s","queue","if","None",":","arg","wait_for",":","a","list","of",":","class",":","`","pyopencl.Event","`","instances","or","None",":","arg","axis",":","the","axis","of","the","array","by","which","to","sort",":","returns",":","a","tuple","(","sorted_array",",","event",")"]
code: def __call__(self, arr, idx=None, queue=None, wait_for=None, axis=0):
      """
      :arg arr: the array to be sorted. Will be overwritten with the sorted array.
      :arg idx: an array of indices to be tracked along with the sorting of *arr*
      :arg queue: a :class:`pyopencl.CommandQueue`, defaults to the array's queue
          if None
      :arg wait_for: a list of :class:`pyopencl.Event` instances or None
      :arg axis: the axis of the array by which to sort
  
      :returns: a tuple (sorted_array, event)
      """
  
      if queue is None:
          queue = arr.queue
  
      if wait_for is None:
          wait_for = []
      wait_for = wait_for + arr.events
  
      last_evt = cl.enqueue_marker(queue, wait_for=wait_for)
  
      if arr.shape[axis] == 0:
          return arr, last_evt
  
      if not _is_power_of_2(arr.shape[axis]):
          raise ValueError(
              "sorted array axis length must be a power of 2"
          )
  
      if idx is None:
          argsort = 0
      else:
          argsort = 1
  
      run_queue = self.sort_b_prepare_wl(
          argsort,
          arr.dtype,
          idx.dtype if idx is not None else None,
          arr.shape,
          axis,
      )
  
      knl, nt, wg, aux = run_queue[0]
  
      if idx is not None:
          if aux:
              last_evt = knl(
                  queue,
                  (nt,),
                  wg,
                  arr.data,
                  idx.data,
                  cl.LocalMemory(
                      _tmpl.LOCAL_MEM_FACTOR
                      * wg[0]
                      * arr.dtype.itemsize
                  ),
                  cl.LocalMemory(
                      _tmpl.LOCAL_MEM_FACTOR
                      * wg[0]
                      * idx.dtype.itemsize
                  ),
                  wait_for=[last_evt],
              )
          for knl, nt, wg, _ in run_queue[1:]:
              last_evt = knl(
                  queue,
                  (nt,),
                  wg,
                  arr.data,
                  idx.data,
                  wait_for=[last_evt],
              )
  
      else:
          if aux:
              last_evt = knl(
                  queue,
                  (nt,),
                  wg,
                  arr.data,
                  cl.LocalMemory(
                      _tmpl.LOCAL_MEM_FACTOR
                      * wg[0]
                      * 4
                      * arr.dtype.itemsize
                  ),
                  wait_for=[last_evt],
              )
          for knl, nt, wg, _ in run_queue[1:]:
              last_evt = knl(
                  queue, (nt,), wg, arr.data, wait_for=[last_evt]
              )
  
      return arr, last_evt
  
file_path: pyopencl/pyopencl/bitonic_sort.py
imports: import pyopencl
  from pyopencl.tools import dtype_to_ctype
  from operator import mul
  from functools import reduce
  from pytools import memoize_method
  from mako.template import Template
  import pyopencl.bitonic_sort_templates
label_desc: Use image node_id 2 for calling the BitonicSort obj's underlying member method code with example usage: obj.__call__(arr, idx, queue, wait_for, axis) and returns: arr,  last_evt, arr,  last_evt