Skip to content

Instantly share code, notes, and snippets.

@mdouze
Last active February 27, 2023 19:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mdouze/b0a65aba70a64b00d6425b0e268a4c80 to your computer and use it in GitHub Desktop.
Save mdouze/b0a65aba70a64b00d6425b0e268a4c80 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mdouze
Copy link
Author

mdouze commented Aug 31, 2020

A function that properly copies the data:

def get_invlist(invlists, l):
    """ returns the inverted lists content. """
    ls = invlists.list_size(l)
    list_ids = np.zeros(ls, dtype='int64')
    x = invlists.get_ids(l)
    faiss.memcpy(faiss.swig_ptr(list_ids), x, list_ids.nbytes)
    invlists.release_ids(l, x)
    x = invlists.get_codes(l)
    list_codes = np.zeros((ls, invlists.code_size), dtype='uint8')
    faiss.memcpy(faiss.swig_ptr(list_codes), x, list_codes.nbytes)
    invlists.release_codes(l, x)    
    return list_ids, list_codes

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