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

Improve RefineFlatIndex #60

Merged
merged 6 commits into from
Dec 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/index/refine_flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,25 @@ impl<BI> FromInnerPtr for RefineFlatIndexImpl<BI> {
}
}

impl<BI> TryFromInnerPtr for RefineFlatIndexImpl<BI> {
Enet4 marked this conversation as resolved.
Show resolved Hide resolved
unsafe fn try_from_inner_ptr(inner_ptr: *mut FaissIndex) -> Result<Self>
where
Self: Sized,
{
// safety: `inner_ptr` is documented to be a valid pointer to an index,
// so the dynamic cast should be safe.
#[allow(unused_unsafe)]
unsafe {
let new_inner = faiss_IndexRefineFlat_cast(inner_ptr);
if new_inner.is_null() {
Err(Error::BadCast)
} else {
Ok(RefineFlatIndexImpl { inner: new_inner, base_index: PhantomData })
}
}
}
}

impl<BI> Index for RefineFlatIndexImpl<BI> {
fn is_trained(&self) -> bool {
unsafe { faiss_Index_is_trained(self.inner_ptr()) != 0 }
Expand Down