Skip to content
Open
Changes from all commits
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
9 changes: 9 additions & 0 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ func (idx *faissIndex) Reconstruct(key int64) (recons []float32, err error) {
func (idx *faissIndex) ReconstructBatch(keys []int64, recons []float32) ([]float32, error) {
var err error
n := int64(len(keys))
if recons == nil {
recons = make([]float32, n*int64(idx.D()))
}

// exit in case of invalid input
if n == 0 || len(recons) != int(n)*idx.D() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the n == 0 check should be moved up before the recons alloc - line 333.5.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically speaking this is still the first validation check, so i dont think it would cause issues if we keep it over here. (just that moving the n == 0 check will have three separate if conditions which wouldn't look good i guess)

the condition at 334 doesn't exit the function, since its for when some user doesn't know what exactly to give for recons (which is like a prealloc) - in which case the function explicitly allocs the slice.

return nil, fmt.Errorf("invalid input")
}

if c := C.faiss_Index_reconstruct_batch(
idx.idx,
C.idx_t(n),
Expand Down