code: def test_float(self):
      ds = datasets.SyntheticDataset(128, 2000, 2000, 200)
  
      d = ds.d
      xt = ds.get_train()
      xq = ds.get_queries()
      xb = ds.get_database()
  
      # define alternative quantizer on the 20 first dims of vectors
      km = faiss.Kmeans(20, 50)
      km.train(xt[:, :20].copy())
      alt_quantizer = km.index
  
      index = faiss.index_factory(d, "IVF50,PQ16np")
      index.by_residual = False
  
      # (optional) fake coarse quantizer
      fake_centroids = np.zeros((index.nlist, index.d), dtype="float32")
      index.quantizer.add(fake_centroids)
  
      # train the PQ part
      index.train(xt)
  
      # add elements xb
      a = alt_quantizer.search(xb[:, :20].copy(), 1)[1].ravel()
      ivf_tools.add_preassigned(index, xb, a)
  
      # search elements xq, increase nprobe, check 4 first results w/
      # groundtruth
      prev_inter_perf = 0
      for nprobe in 1, 10, 20:
          index.nprobe = nprobe
          a = alt_quantizer.search(xq[:, :20].copy(), index.nprobe)[1]
          D, I = ivf_tools.search_preassigned(index, xq, 4, a)
          inter_perf = faiss.eval_intersection(
              I, ds.get_groundtruth()[:, :4]
          )
          self.assertTrue(inter_perf >= prev_inter_perf)
          prev_inter_perf = inter_perf
  
      # test range search
  
      index.nprobe = 20
  
      a = alt_quantizer.search(xq[:, :20].copy(), index.nprobe)[1]
  
      # just to find a reasonable radius
      D, I = ivf_tools.search_preassigned(index, xq, 4, a)
      radius = D.max() * 1.01
  
      lims, DR, IR = ivf_tools.range_search_preassigned(
          index, xq, radius, a
      )
  
      # with that radius the k-NN results are a subset of the range search
      # results
      for q in range(len(xq)):
          l0, l1 = lims[q], lims[q + 1]
          self.assertTrue(set(I[q]) <= set(IR[l0:l1]))
  
imports: import faiss
  import unittest
  import numpy
  import platform
  import os
  import random
  import tempfile
  from faiss.contrib import datasets
  from faiss.contrib import inspect_tools
  from faiss.contrib import evaluation
  from faiss.contrib import ivf_tools
  from faiss.contrib import clustering
  from faiss.contrib import big_batch_search
  from common_faiss_tests import get_dataset_2
label_desc: Use image node_id 1 for calling the TestPreassigned obj's underlying member method code with example usage: obj.test_float() without return types