Faiss: in method 'IndexBinary_range_search', argument 3 of type 'uint8_t const *'

Created on 8 Mar 2019  路  2Comments  路  Source: facebookresearch/faiss

Summary

in method 'IndexBinary_range_search', argument 3 of type 'uint8_t const *'

Platform

-- macOS 10.14

Faiss version: 1.4.0

Running on:

  • [ ] CPU

Interface:

  • [ ] Python

Reproduction instructions

program:

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)

error:

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 *'?

enhancement question

Most helpful comment

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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukedeo picture lukedeo  路  3Comments

daniellevy picture daniellevy  路  3Comments

Ljferrer picture Ljferrer  路  3Comments

danny1984 picture danny1984  路  3Comments

zjjott picture zjjott  路  3Comments