Skip to content

Instantly share code, notes, and snippets.

@mdouze
Last active October 8, 2024 06:48
Show Gist options
  • 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
Loading
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