code: def previous_event_indexer(data_query_cutoff_times,
                             all_sids,
                             event_dates,
                             event_timestamps,
                             event_sids):
      validate_event_metadata(event_dates, event_timestamps, event_sids)
      out = np.full(
          (len(data_query_cutoff_times), len(all_sids)),
          -1,
          dtype=np.int64,
      )
      eff_dts = np.maximum(event_dates, event_timestamps)
      sid_ixs = all_sids.searchsorted(event_sids)
      dt_ixs = data_query_cutoff_times.searchsorted(eff_dts, side='right')
      last_written = {}
      for i in range(len(event_dates) - 1, -1, -1):
          sid_ix = sid_ixs[i]
          dt_ix = dt_ixs[i]
          out[dt_ix:last_written.get(sid_ix, None), sid_ix] = i
          last_written[sid_ix] = dt_ix
      return out