code: def _psislw(log_weights, cutoff_ind, cutoffmin):
      """
      Pareto smoothed importance sampling (PSIS) for a 1D vector.
  
      Parameters
      ----------
      log_weights: array
          Array of length n_observations
      cutoff_ind: int
      cutoffmin: float
      k_min: float
  
      Returns
      -------
      lw_out: array
          Smoothed log weights
      kss: float
          Pareto tail index
      """
      x = np.asarray(log_weights)
  
      # improve numerical accuracy
      x -= np.max(x)
      # sort the array
      x_sort_ind = np.argsort(x)
      # divide log weights into body and right tail
      xcutoff = max(x[x_sort_ind[cutoff_ind]], cutoffmin)
  
      expxcutoff = np.exp(xcutoff)
      (tailinds,) = np.where(
          x > xcutoff
      )  # pylint: disable=unbalanced-tuple-unpacking
      x_tail = x[tailinds]
      tail_len = len(x_tail)
      if tail_len <= 4:
          # not enough tail samples for gpdfit
          k = np.inf
      else:
          # order of tail samples
          x_tail_si = np.argsort(x_tail)
          # fit generalized Pareto distribution to the right tail samples
          x_tail = np.exp(x_tail) - expxcutoff
          k, sigma = _gpdfit(x_tail[x_tail_si])
  
          if np.isfinite(k):
              # no smoothing if GPD fit failed
              # compute ordered statistic for the fit
              sti = np.arange(0.5, tail_len) / tail_len
              smoothed_tail = _gpinv(sti, k, sigma)
              smoothed_tail = (
                  np.log(  # pylint: disable=assignment-from-no-return
                      smoothed_tail + expxcutoff
                  )
              )
              # place the smoothed tail into the output array
              x[tailinds[x_tail_si]] = smoothed_tail
              # truncate smoothed values to the largest raw weight 0
              x[x > 0] = 0
      # renormalize weights
      x -= _logsumexp(x)
  
      return x, k
  
imports: import itertools
  import warnings
  from copy import deepcopy
  from typing import List, Optional, Tuple, Union, Mapping, cast, Callable
  import numpy
  import pandas
  import scipy.stats
  from xarray_einstats import stats
  import xarray
  from scipy.optimize import minimize
  from typing_extensions import Literal
  from ..None import _log
  from ..data import InferenceData, convert_to_dataset, convert_to_inference_data, extract
  from ..rcparams import rcParams, ScaleKeyword, ICKeyword
  from ..utils import Numba, _numba_var, _var_names, get_coords
  from .density_utils import get_bins
  from .density_utils import histogram
  from .density_utils import kde
  from .diagnostics import _mc_error, _multichain_statistics, ess
  from .stats_utils import ELPDData, _circular_standard_deviation, smooth_data
  from .stats_utils import get_log_likelihood
  from .stats_utils import get_log_prior
  from .stats_utils import logsumexp
  from .stats_utils import make_ufunc
  from .stats_utils import stats_variance_2d
  from .stats_utils import wrap_xarray_ufunc
  from ..sel_utils import xarray_var_iter
  from ..labels import BaseLabeller
label_desc: Use image node_id 9 for calling a global function with example usage: _psislw(log_weights, cutoff_ind, cutoffmin) and returns: x,  k