code: def test_lookup(self):
      d = 128
      index = faiss.IndexFlatL2(d)
  
      # Add to CPU index with torch CPU
      xb_torch = torch.rand(10000, d)
      index.add(xb_torch)
  
      # Test reconstruct
      y_torch = index.reconstruct(10)
      self.assertTrue(torch.equal(y_torch, xb_torch[10]))
  
      # Add to CPU index with numpy CPU
      xb_np = torch.rand(500, d).numpy()
      index.add(xb_np)
      self.assertEqual(index.ntotal, 10500)
  
      y_np = np.zeros(d, dtype=np.float32)
      index.reconstruct(10100, y_np)
      self.assertTrue(np.array_equal(y_np, xb_np[100]))
  
      # Search with np cpu
      xq_torch = torch.rand(10, d, dtype=torch.float32)
      d_np, I_np = index.search(xq_torch.numpy(), 5)
  
      # Search with torch cpu
      d_torch, I_torch = index.search(xq_torch, 5)
  
      # The two should be equivalent
      self.assertTrue(np.array_equal(d_np, d_torch.numpy()))
      self.assertTrue(np.array_equal(I_np, I_torch.numpy()))
  
      # Search with np cpu using pre-allocated arrays
      d_np_input = np.zeros((10, 5), dtype=np.float32)
      I_np_input = np.zeros((10, 5), dtype=np.int64)
      index.search(xq_torch.numpy(), 5, d_np_input, I_np_input)
  
      self.assertTrue(np.array_equal(d_np, d_np_input))
      self.assertTrue(np.array_equal(I_np, I_np_input))
  
      # Search with torch cpu using pre-allocated arrays
      d_torch_input = torch.zeros(10, 5, dtype=torch.float32)
      I_torch_input = torch.zeros(10, 5, dtype=torch.int64)
      index.search(xq_torch, 5, d_torch_input, I_torch_input)
  
      self.assertTrue(np.array_equal(d_torch_input.numpy(), d_np))
      self.assertTrue(np.array_equal(I_torch_input.numpy(), I_np))
  
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 1 for calling the TestTorchUtilsCPU obj's underlying member method code with example usage: obj.test_lookup() without return types