Skip to content

Commit

Permalink
#4 pdist -> cdist; fixed logic for special shard; added numba (Alex S…
Browse files Browse the repository at this point in the history
…htuchkin's suggestion)
  • Loading branch information
DmitryKey committed Dec 10, 2021
1 parent dbbe1cc commit 89444a4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/util/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from memory_profiler import profile
from sklearn.preprocessing import normalize
import struct
import torch
Expand Down Expand Up @@ -110,6 +111,7 @@ def read_fbin(filename, start_idx=0, chunk_size=None):


# by Leo Joffe
#@profile
def read_bin(filename, dtype, start_idx=0, chunk_size=None):
with open(filename, "rb") as f:
# The header is two np.int32 values
Expand Down Expand Up @@ -192,6 +194,7 @@ def write_bin(filename, dtype, vecs):
f.write(struct.pack('<i', dim))
vecs.astype(dtype).flatten().tofile(f)


def buddy_up(points,friends):
#rearranges the points to put buddy dimensions next to each other.
#this will be used during PQ to get ideal subvectors without needing to modify Faiss
Expand Down Expand Up @@ -253,6 +256,7 @@ def shard_filename(path,name):


class Shard:
@profile
def __init__(self, shard_id: int, point_ids: np.array, points: np.array, size: int, shard_saturation_percent: float, dim: int):
self.shardid = shard_id
self.pointids = point_ids
Expand Down Expand Up @@ -282,7 +286,7 @@ def add_points(path, shard: Shard):
del index
gc.collect()


@profile
def save_shard(path, shard: Shard):
"""
Adds a batch of points to a specific shard
Expand Down

0 comments on commit 89444a4

Please sign in to comment.