def test_IP(self): # this one is not optimized with SIMD but just in case rs = np.random.RandomState(123) swig_ptr = faiss.swig_ptr for d in 1, 2, 4, 8, 12, 16: x = rs.rand(d).astype('float32') for ny in 128, 129, 130: print("d=%d ny=%d" % (d, ny)) y = rs.rand(ny, d).astype('float32') ref = (x * y).sum(1) new = np.zeros(ny, dtype='float32') faiss.fvec_inner_products_ny(swig_ptr(new), swig_ptr(x), swig_ptr(y), d, ny) assert np.abs(ref - new).max() < 1e-4
faiss.omp_set_num_threads(1) print('xd=%d yd=%d' % (xd, yd)) print('Running inner products test..') for d in 3, 4, 12, 36, 64: x = faiss.rand(xd * d).reshape(xd, d) y = faiss.rand(yd * d).reshape(yd, d) distances = np.empty((xd, yd), dtype='float32') t0 = time.time() for i in xrange(xd): faiss.fvec_inner_products_ny(swig_ptr(distances[i]), swig_ptr(x[i]), swig_ptr(y), d, yd) t1 = time.time() # sparse verification ntry = 100 num, denom = 0, 0 for t in range(ntry): xi = np.random.randint(xd) yi = np.random.randint(yd) num += abs(distances[xi, yi] - np.dot(x[xi], y[yi])) denom += abs(distances[xi, yi]) print('d=%d t=%.3f s diff=%g' % (d, t1 - t0, num / denom)) print('Running L2sqr test..') for d in 3, 4, 12, 36, 64: