import SPTAG
import numpy as np
n = 1024*1024 #this szie will encounted a fatal error
k = 3
r = 3
Dimension=512 #the size of vectors.bin will be 1024×1024×512×4=2G n×Dimension×4
def testBuild(algo, distmethod, x, out):
i = SPTAG.AnnIndex(algo, 'Float', x.shape[1])
i.SetBuildParam("NumberOfThreads", '4')
i.SetBuildParam("DistCalcMethod", distmethod)
ret = i.Build(x.tobytes(), x.shape[0])
i.Save(out)
def Test(algo, distmethod):
x = np.ones((n, Dimension), dtype=np.float32) * np.reshape(np.arange(n, dtype=np.float32), (n, 1))
q = np.ones((r, Dimension), dtype=np.float32) * np.reshape(np.arange(r, dtype=np.float32), (r, 1)) * 2
print ("Build.............................")
testBuild(algo, distmethod, x, 'testindices')
testSearch('testindices', q, k)
if __name__ == '__main__':
Test('BKT', 'L2')
import SPTAG
import numpy as np
n = 1024*1024 -1 #Note the difference here, 1 less than the parameters of the above code.
k = 3
r = 3
Dimension=512 #the size of vectors.bin will be 1024×1024×512×4=2G n×Dimension×4
def testBuild(algo, distmethod, x, out):
i = SPTAG.AnnIndex(algo, 'Float', x.shape[1])
i.SetBuildParam("NumberOfThreads", '4')
i.SetBuildParam("DistCalcMethod", distmethod)
ret = i.Build(x.tobytes(), x.shape[0])
i.Save(out)
def Test(algo, distmethod):
x = np.ones((n, Dimension), dtype=np.float32) * np.reshape(np.arange(n, dtype=np.float32), (n, 1))
q = np.ones((r, Dimension), dtype=np.float32) * np.reshape(np.arange(r, dtype=np.float32), (r, 1)) * 2
print ("Build.............................")
testBuild(algo, distmethod, x, 'testindices')
testSearch('testindices', q, k)
if __name__ == '__main__':
Test('BKT', 'L2')