code: def eval_dataset(index, preproc):
      ps = faiss.GpuParameterSpace()
      ps.initialize(index)
  
      nq_gt = gt_I.shape[0]
      print("search...")
      sl = query_batch_size
      nq = xq.shape[0]
      for nprobe in nprobes:
          ps.set_index_parameter(index, "nprobe", nprobe)
          t0 = time.time()
  
          if sl == 0:
              D, I = index.search(preproc.apply_py(sanitize(xq)), nnn)
          else:
              I = np.empty((nq, nnn), dtype="int32")
              D = np.empty((nq, nnn), dtype="float32")
  
              inter_res = ""
  
              for i0, xs in dataset_iterator(xq, preproc, sl):
                  print(
                      "\r%d/%d (%.3f s%s)   "
                      % (i0, nq, time.time() - t0, inter_res),
                      end=" ",
                  )
                  sys.stdout.flush()
  
                  i1 = i0 + xs.shape[0]
                  Di, Ii = index.search(xs, nnn)
  
                  I[i0:i1] = Ii
                  D[i0:i1] = Di
  
                  if knngraph and not inter_res and i1 >= nq_gt:
                      ires = eval_intersection_measure(
                          gt_I[:, :nnn], I[:nq_gt]
                      )
                      inter_res = ", %.4f" % ires
  
          t1 = time.time()
          if knngraph:
              ires = eval_intersection_measure(gt_I[:, :nnn], I[:nq_gt])
              print(
                  "  probe=%-3d: %.3f s rank-%d intersection results: %.4f"
                  % (nprobe, t1 - t0, nnn, ires)
              )
          else:
              print("  probe=%-3d: %.3f s" % (nprobe, t1 - t0), end=" ")
              gtc = gt_I[:, :1]
              nq = xq.shape[0]
              for rank in 1, 10, 100:
                  if rank > nnn:
                      continue
                  nok = (I[:, :rank] == gtc).sum()
                  print(
                      "1-R@%d: %.4f" % (rank, nok / float(nq)), end=" "
                  )
              print()
          if I_fname:
              I_fname_i = I_fname % I
              print("storing", I_fname_i)
              np.save(I, I_fname_i)
          if D_fname:
              D_fname_i = I_fname % I
              print("storing", D_fname_i)
              np.save(D, D_fname_i)
  
imports: from __future__ import print_function
  import numpy
  import time
  import os
  import sys
  import faiss
  import re
  from multiprocessing.pool import ThreadPool
  from datasets import ivecs_read
label_desc: Use image node_id 18 for calling a global function with example usage: eval_dataset(index, preproc) without return types