def test_repeats(self): rs = np.random.RandomState(123) dim = 32 for _i in range(1000): vec = np.floor((rs.rand(dim)**7) * 3).astype('float32') vecs = vec.copy() vecs.sort() repeats = faiss.Repeats(dim, swig_ptr(vecs)) code = repeats.encode(swig_ptr(vec)) vec2 = np.zeros(dim, dtype='float32') repeats.decode(code, swig_ptr(vec2)) # print(vec2) assert np.all(vec == vec2)
def test_repeats(self): rs = np.random.RandomState(123) dim = 32 for i in range(1000): vec = np.floor((rs.rand(dim)**7) * 3).astype('float32') vecs = vec.copy() vecs.sort() repeats = faiss.Repeats(dim, swig_ptr(vecs)) rr = [repeats.repeats.at(i) for i in range(repeats.repeats.size())] # print([(r.val, r.n) for r in rr]) code = repeats.encode(swig_ptr(vec)) #print(vec, code) vec2 = np.zeros(dim, dtype='float32') repeats.decode(code, swig_ptr(vec2)) # print(vec2) assert np.all(vec == vec2)