parameters: (xq, db_iterator, k, metric_type=faiss.METRIC_L2)
return_statement: return rh.D, rh.I
docstring: Computes the exact KNN search results for a dataset that possibly
      does not fit in RAM but for which we have an iterator that
      returns it block by block.
docstring_summary: Computes the exact KNN search results for a dataset that possibly
      does not fit in RAM but for which we have an iterator that
      returns it block by block.
docstring_tokens: Computes the exact KNN search results for a dataset that possibly does not fit in RAM but for which we have an iterator that returns it block by block .
function: def knn_ground_truth(xq, db_iterator, k, metric_type=faiss.METRIC_L2):
      """Computes the exact KNN search results for a dataset that possibly
      does not fit in RAM but for which we have an iterator that
      returns it block by block.
      """
      LOG.info("knn_ground_truth queries size %s k=%d" % (xq.shape, k))
      t0 = time.time()
      nq, d = xq.shape
      keep_max = metric_type == faiss.METRIC_INNER_PRODUCT
      rh = faiss.ResultHeap(nq, k, keep_max=keep_max)
  
      index = faiss.IndexFlat(d, metric_type)
      if faiss.get_num_gpus():
          LOG.info('running on %d GPUs' % faiss.get_num_gpus())
          index = faiss.index_cpu_to_all_gpus(index)
  
      # compute ground-truth by blocks, and add to heaps
      i0 = 0
      for xbi in db_iterator:
          ni = xbi.shape[0]
          index.add(xbi)
          D, I = index.search(xq, k)
          I += i0
          rh.add_result(D, I)
          index.reset()
          i0 += ni
          LOG.info("%d db elements, %.3f s" % (i0, time.time() - t0))
  
      rh.finalize()
      LOG.info("GT time: %.3f s (%d vectors)" % (time.time() - t0, i0))
  
      return rh.D, rh.I
function_tokens: def knn_ground_truth ( xq , db_iterator , k , metric_type = faiss . METRIC_L2 ) : LOG . info ( "knn_ground_truth queries size %s k=%d" % ( xq . shape , k ) ) t0 = time . time ( ) nq , d = xq . shape keep_max = metric_type == faiss . METRIC_INNER_PRODUCT rh = faiss . ResultHeap ( nq , k , keep_max = keep_max ) index = faiss . IndexFlat ( d , metric_type ) if faiss . get_num_gpus ( ) : LOG . info ( 'running on %d GPUs' % faiss . get_num_gpus ( ) ) index = faiss . index_cpu_to_all_gpus ( index ) # compute ground-truth by blocks, and add to heaps i0 = 0 for xbi in db_iterator : ni = xbi . shape [ 0 ] index . add ( xbi ) D , I = index . search ( xq , k ) I += i0 rh . add_result ( D , I ) index . reset ( ) i0 += ni LOG . info ( "%d db elements, %.3f s" % ( i0 , time . time ( ) - t0 ) ) rh . finalize ( ) LOG . info ( "GT time: %.3f s (%d vectors)" % ( time . time ( ) - t0 , i0 ) ) return rh . D , rh . I