code: def do_encode_twice(self, factory_key):
      d = 96
      nb = 1000
      nq = 0
      nt = 2000
  
      xt, x, _ = get_dataset_2(d, nt, nb, nq)
  
      assert x.size > 0
  
      codec = faiss.index_factory(d, factory_key)
  
      codec.train(xt)
  
      codes = codec.sa_encode(x)
      x2 = codec.sa_decode(codes)
  
      codes2 = codec.sa_encode(x2)
  
      if "IVF" in factory_key or "RQ" in factory_key:
          # some rows are not reconstructed exactly because they
          # flip into another quantization cell
          nrowdiff = (codes != codes2).any(axis=1).sum()
          self.assertTrue(nrowdiff < 10)
      else:
          self.assertTrue(np.all(codes == codes2))
  
      x3 = codec.sa_decode(codes2)
  
      if "IVF" in factory_key or "RQ" in factory_key:
          diffs = np.abs(x2 - x3).sum(axis=1)
          avg = np.abs(x2).sum(axis=1).mean()
          diffs.sort()
          assert diffs[-10] < avg * 1e-5
      else:
          self.assertTrue(np.allclose(x2, x3))
  
imports: from __future__ import print_function
  import numpy
  import unittest
  import faiss
  from common_faiss_tests import get_dataset_2
  from faiss.contrib.datasets import SyntheticDataset
  from faiss.contrib.inspect_tools import get_additive_quantizer_codebooks
label_desc: Use image node_id 1 for calling the TestEncodeDecode obj's underlying member method code with example usage: obj.do_encode_twice(factory_key) without return types