code: def counts_to_PR(ngt, nres, ninter, mode="overall"):
      """computes a  precision-recall for a ser of queries.
      ngt = nb of GT results per query
      nres = nb of found results per query
      ninter = nb of correct results per query (smaller than nres of course)
      """
  
      if mode == "overall":
          ngt, nres, ninter = ngt.sum(), nres.sum(), ninter.sum()
  
          if nres > 0:
              precision = ninter / nres
          else:
              precision = 1.0
  
          if ngt > 0:
              recall = ninter / ngt
          elif nres == 0:
              recall = 1.0
          else:
              recall = 0.0
  
          return precision, recall
  
      elif mode == "average":
          # average precision and recall over queries
  
          mask = ngt == 0
          ngt[mask] = 1
  
          recalls = ninter / ngt
          recalls[mask] = (nres[mask] == 0).astype(float)
  
          # avoid division by 0
          mask = nres == 0
          assert np.all(ninter[mask] == 0)
          ninter[mask] = 1
          nres[mask] = 1
  
          precisions = ninter / nres
  
          return precisions.mean(), recalls.mean()
  
      else:
          raise AssertionError()
  
imports: import numpy
  import unittest
  import time
  import faiss
  from multiprocessing.pool import ThreadPool
label_desc: Use image node_id 4 for calling a global function with example usage: counts_to_PR(ngt, nres, ninter, mode) and returns: precision,  recall, precisions,  recalls