code: def cmplx_sort(p):
      """Sort roots based on magnitude.
  
      Parameters
      ----------
      p : array_like
          The roots to sort, as a 1-D array.
  
      Returns
      -------
      p_sorted : ndarray
          Sorted roots.
      indx : ndarray
          Array of indices needed to sort the input `p`.
  
      Examples
      --------
      >>> import cusignal
      >>> vals = [1, 4, 1+1.j, 3]
      >>> p_sorted, indx = cusignal.cmplx_sort(vals)
      >>> p_sorted
      array([1.+0.j, 1.+1.j, 3.+0.j, 4.+0.j])
      >>> indx
      array([0, 2, 3, 1])
  
      """
      p = cp.asarray(p)
      if cp.iscomplexobj(p):
          indx = cp.argsort(abs(p))
      else:
          indx = cp.argsort(p)
      return cp.take(p, indx, 0), indx
  
file_path: cusignal/python/cusignal/filter_design/fir_filter_design.py
imports: from math import ceil, log
  import cupy
  import numpy
  from scipy import signal
  from ..windows.windows import get_window
label_desc: Use image node_id 6 for calling a global function with example usage: cmplx_sort(p) and returns: cp,  indx