code: def _unpack_index(index):
      """Parse index. Always return a tuple of the form (row, col).
      Valid type for row/col is integer, slice, or array of integers.
      """
      # First, check if indexing with single boolean matrix.
      from ._base import _spbase, issparse
  
      if (
          isinstance(index, (_spbase, np.ndarray))
          and index.ndim == 2
          and index.dtype.kind == "b"
      ):
          return index.nonzero()
  
      # Parse any ellipses.
      index = _check_ellipsis(index)
  
      # Next, parse the tuple or object
      if isinstance(index, tuple):
          if len(index) == 2:
              row, col = index
          elif len(index) == 1:
              row, col = index[0], slice(None)
          else:
              raise IndexError("invalid number of indices")
      else:
          idx = _compatible_boolean_index(index)
          if idx is None:
              row, col = index, slice(None)
          elif idx.ndim < 2:
              return _boolean_index_to_array(idx), slice(None)
          elif idx.ndim == 2:
              return idx.nonzero()
      # Next, check for validity and transform the index as needed.
      if issparse(row) or issparse(col):
          # Supporting sparse boolean indexing with both row and col does
          # not work because spmatrix.ndim is always 2.
          raise IndexError(
              "Indexing with sparse matrices is not supported "
              "except boolean indexing where matrix and index "
              "are equal shapes."
          )
      bool_row = _compatible_boolean_index(row)
      bool_col = _compatible_boolean_index(col)
      if bool_row is not None:
          row = _boolean_index_to_array(bool_row)
      if bool_col is not None:
          col = _boolean_index_to_array(bool_col)
      return row, col
  
imports: import numpy
  from ._sputils import isintlike
label_desc: Use image node_id 2 for calling a global function with example usage: _unpack_index(index) and returns: row,  col, index, _boolean_index_to_array,  slice, idx