in method 'IndexBinary_range_search', argument 3 of type 'uint8_t const *'
-- macOS 10.14
Faiss version: 1.4.0
Running on:
Interface:
index = faiss.IndexBinaryFlat(64)
xb = np.random.randint(low=0,high=255,size=(1000,64//8)).astype(np.uint8)
index.add(xb)
xq = np.random.randint(low=0,high=255,size=(2,64//8)).astype(np.uint8)
result=[]
index.range_search(len(xq),xq,2,result)
return _swigfaiss.IndexBinary_range_search(self, n, x, radius, result)
TypeError: in method 'IndexBinary_range_search', argument 3 of type 'uint8_t const *'
In python, how I give it a parameter of type 'uint8_t const *'?
Range search is currently not implemented on binary indices.
In case it is useful, here is a function that computes the pairwise distances between two matrices:
def pairwise_hamming_dis(a, b):
""" compute the pairwise Hamming distances between two matrices """
na, d = a.shape
nb, d2 = b.shape
assert d == d2
dis = np.empty((na, nb), dtype='int32')
faiss.hammings(
faiss.swig_ptr(a), faiss.swig_ptr(b),
na, nb, d,
faiss.swig_ptr(dis)
)
return dis
Then the range search can be performed with
dis = pairwise_hamming_dis(xq, xb)
I, J = np.where(dis < threshold)
It is not ideal but definitely faster than doing the loops in Python.
Most helpful comment
In case it is useful, here is a function that computes the pairwise distances between two matrices:
Then the range search can be performed with
It is not ideal but definitely faster than doing the loops in Python.