code: def ap_split_trials(
      o_idxs, o_vals, l_idxs, l_vals, gamma, gamma_cap=DEFAULT_LF
  ):
      """Split the elements of `o_vals` (observations values) into two groups: those for
      trials whose losses (`l_vals`) were above gamma, and those below gamma. Note that
      only unique elements are returned, so the total number of returned elements might
      be lower than `len(o_vals)`
      """
      o_idxs, o_vals, l_idxs, l_vals = list(
          map(np.asarray, [o_idxs, o_vals, l_idxs, l_vals])
      )
  
      # XXX if this is working, refactor this sort for efficiency
  
      # Splitting is done this way to cope with duplicate loss values.
      n_below = min(
          int(np.ceil(gamma * np.sqrt(len(l_vals)))), gamma_cap
      )
      l_order = np.argsort(l_vals)
  
      keep_idxs = set(l_idxs[l_order[:n_below]])
      below = [v for i, v in zip(o_idxs, o_vals) if i in keep_idxs]
  
      keep_idxs = set(l_idxs[l_order[n_below:]])
      above = [v for i, v in zip(o_idxs, o_vals) if i in keep_idxs]
  
      return np.asarray(below), np.asarray(above)
  
imports: import logging
  import time
  import numpy
  from scipy.special import erf
  from .None import pyll
  from .pyll import scope
  from .pyll.stochastic import implicit_stochastic
  from .base import miscs_to_idxs_vals
  from .base import miscs_update_idxs_vals
  from .None import rand
label_desc: Use image node_id 27 for calling a global function with example usage: ap_split_trials(o_idxs, o_vals, l_idxs, l_vals, gamma, gamma_cap) and returns: np,  np