code: def argsort_which(
      eigenvalues, typ, k, which, sigma=None, OPpart=None, mode=None
  ):
      """Return sorted indices of eigenvalues using the "which" keyword
      from eigs and eigsh"""
      if sigma is None:
          reval = np.round(eigenvalues, decimals=_ndigits[typ])
      else:
          if mode is None or mode == "normal":
              if OPpart is None:
                  reval = 1.0 / (eigenvalues - sigma)
              elif OPpart == "r":
                  reval = 0.5 * (
                      1.0 / (eigenvalues - sigma)
                      + 1.0 / (eigenvalues - np.conj(sigma))
                  )
              elif OPpart == "i":
                  reval = -0.5j * (
                      1.0 / (eigenvalues - sigma)
                      - 1.0 / (eigenvalues - np.conj(sigma))
                  )
          elif mode == "cayley":
              reval = (eigenvalues + sigma) / (eigenvalues - sigma)
          elif mode == "buckling":
              reval = eigenvalues / (eigenvalues - sigma)
          else:
              raise ValueError("mode='%s' not recognized" % mode)
  
          reval = np.round(reval, decimals=_ndigits[typ])
  
      if which in ["LM", "SM"]:
          ind = np.argsort(abs(reval))
      elif which in ["LR", "SR", "LA", "SA", "BE"]:
          ind = np.argsort(np.real(reval))
      elif which in ["LI", "SI"]:
          # for LI,SI ARPACK returns largest,smallest abs(imaginary) why?
          if typ.islower():
              ind = np.argsort(abs(np.imag(reval)))
          else:
              ind = np.argsort(np.imag(reval))
      else:
          raise ValueError("which='%s' is unrecognized" % which)
  
      if which in ["LM", "LA", "LR", "LI"]:
          return ind[-k:]
      elif which in ["SM", "SA", "SR", "SI"]:
          return ind[:k]
      elif which == "BE":
          return np.concatenate((ind[: k // 2], ind[k // 2 - k :]))
  
imports: import threading
  import itertools
  import sys
  import platform
  import numpy
  from numpy.testing import assert_allclose, assert_array_almost_equal_nulp, assert_equal, assert_array_equal, suppress_warnings
  from pytest import raises
  import pytest
  from numpy import dot, conj, random
  from scipy.linalg import eig, eigh, hilbert, svd
  from scipy.sparse import csc_matrix, csr_matrix, isspmatrix, diags, rand
  from scipy.sparse.linalg import LinearOperator, aslinearoperator
  from scipy.sparse.linalg.eigen.arpack import eigs, eigsh, svds, ArpackNoConvergence, arpack
  from scipy._lib._gcutils import assert_deallocated, IS_PYPY
label_desc: Use image node_id 6 for calling a global function with example usage: argsort_which(eigenvalues, typ, k, which, sigma, OPpart, mode) and returns: ind, ind, np