code: def test_shards(self):
      k = 32
      ref_index = faiss.IndexFlatL2(d)
  
      print("ref search")
      ref_index.add(xb)
      _Dref, Iref = ref_index.search(xq, k)
      print(Iref[:5, :6])
  
      shard_index = faiss.IndexShards(d)
      shard_index_2 = faiss.IndexShards(d, True, False)
  
      ni = 3
      for i in range(ni):
          i0 = int(i * nb / ni)
          i1 = int((i + 1) * nb / ni)
          index = faiss.IndexFlatL2(d)
          index.add(xb[i0:i1])
          shard_index.add_shard(index)
  
          index_2 = faiss.IndexFlatL2(d)
          irm = faiss.IndexIDMap(index_2)
          shard_index_2.add_shard(irm)
  
      # test parallel add
      shard_index_2.verbose = True
      shard_index_2.add(xb)
  
      for test_no in range(3):
          with_threads = test_no == 1
  
          print("shard search test_no = %d" % test_no)
          if with_threads:
              remember_nt = faiss.omp_get_max_threads()
              faiss.omp_set_num_threads(1)
              shard_index.threaded = True
          else:
              shard_index.threaded = False
  
          if test_no != 2:
              _D, I = shard_index.search(xq, k)
          else:
              _D, I = shard_index_2.search(xq, k)
  
          print(I[:5, :6])
  
          if with_threads:
              faiss.omp_set_num_threads(remember_nt)
  
          ndiff = (I != Iref).sum()
  
          print("%d / %d differences" % (ndiff, nq * k))
          assert ndiff < nq * k / 1000.0
  
file_path: faiss/tests/test_meta_index.py
imports: import os
  import numpy
  import faiss
  import unittest
  from common_faiss_tests import Randu10k
  from faiss.contrib.datasets import SyntheticDataset
label_desc: Use image node_id 1 for calling the Shards obj's underlying member method code with example usage: obj.test_shards() without return types