Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks
TFDeeplearner opened this issue Mar 8, 2019 · 2 comments
Closed
2 tasks

Comments

@TFDeeplearner
Copy link

TFDeeplearner commented Mar 8, 2019

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

@beauby
Copy link
Contributor

beauby commented Mar 8, 2019

Range search is currently not implemented on binary indices.

@mdouze
Copy link
Contributor

mdouze commented Mar 8, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants