code: def test_train_add_with_ids(self):
      d = 32
      nlist = 5
  
      quantizer = faiss.IndexFlatL2(d)
      index = faiss.IndexIVFFlat(quantizer, d, nlist, faiss.METRIC_L2)
      xb = torch.rand(1000, d, dtype=torch.float32)
      index.train(xb)
  
      # Test add_with_ids with torch cpu
      ids = torch.arange(1000, 1000 + xb.shape[0], dtype=torch.int64)
      index.add_with_ids(xb, ids)
      _, I = index.search(xb[10:20], 1)
      self.assertTrue(torch.equal(I.view(10), ids[10:20]))
  
      # Test add_with_ids with numpy
      index.reset()
      index.train(xb.numpy())
      index.add_with_ids(xb.numpy(), ids.numpy())
      _, I = index.search(xb.numpy()[10:20], 1)
      self.assertTrue(np.array_equal(I.reshape(10), ids.numpy()[10:20]))
  
file_path: faiss/tests/torch_test_contrib.py
imports: import faiss
  import torch
  import unittest
  import numpy
  import faiss.contrib.torch_utils
label_desc: Use image node_id 2 for calling the TestTorchUtilsCPU obj's underlying member method code with example usage: obj.test_train_add_with_ids() without return types