Skip to content

Instantly share code, notes, and snippets.

@Enet4
Last active April 11, 2018 19:00
Show Gist options
  • Save Enet4/c6bf959e4f5953463b50dc46aeb740ad to your computer and use it in GitHub Desktop.
Save Enet4/c6bf959e4f5953463b50dc46aeb740ad to your computer and use it in GitHub Desktop.
index_factory at index/mod.rs in faiss-rs
/// Use the index factory to create a native instance of a Faiss index, for `d`-dimensional
/// vectors.
pub fn index_factory<D: AsRef<str>>(
d: u32,
description: D,
metric: MetricType,
) -> Result<IndexImpl> {
unsafe {
let metric = metric as c_uint;
let description = CString::new(description.as_ref()).map_err(|_| Error::IndexDescription)?;
let mut index_ptr = ::std::ptr::null_mut();
faiss_try!(faiss_index_factory(
&mut index_ptr,
(d & 0x7FFFFFFF) as i32,
description.as_ptr(),
metric
));
Ok(IndexImpl { inner: index_ptr })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment