Skip to content

Commit

Permalink
fix ruff errors in indexes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmacavaney committed Nov 24, 2024
1 parent 9132e06 commit 602ef1d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pyterrier_dr/indexes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Deprecated module
# flake8: noqa
import torch
import itertools
import math
Expand Down Expand Up @@ -263,7 +262,7 @@ def index(self, inp):
fout.write(doc_vecs.tobytes())
docnos.extend([d['docno'] for d in docs])
count += len(docs)
DocnoFile.build(docnos, path/f'docnos.npy')
DocnoFile.build(docnos, path/'docnos.npy')
with open(path/'meta.json', 'wt') as f_meta:
json.dump({'dtype': self.dtype, 'vec_size': vec_size, 'count': count}, f_meta)

Expand Down Expand Up @@ -470,8 +469,7 @@ def transform(self, inp):
query_vecs = query_vecs / np.linalg.norm(query_vecs, axis=1, keepdims=True)
query_vecs = query_vecs.copy()
res = []
query_heaps = [[] for _ in range(query_vecs.shape[0])]
docnos = DocnoFile(self.index_path/f'docnos.npy')
docnos = DocnoFile(self.index_path/'docnos.npy')
num_q = query_vecs.shape[0]
ranked_lists = RankedLists(self.num_results, num_q)
dids_offset = 0
Expand Down Expand Up @@ -528,7 +526,7 @@ def index(self, inp):
index.add(doc_vecs)
docnos.extend(d['docno'] for d in batch)
faiss.write_index(index, str(path/f'{shardid}.faiss'))
DocnoFile.build(docnos, path/f'docnos.npy')
DocnoFile.build(docnos, path/'docnos.npy')


class FaissHnsw(pt.Indexer):
Expand Down Expand Up @@ -570,8 +568,7 @@ def transform(self, inp):
query_vecs = query_vecs / np.linalg.norm(query_vecs, axis=1, keepdims=True)
query_vecs = query_vecs.copy()
res = []
query_heaps = [[] for _ in range(query_vecs.shape[0])]
docnos = DocnoFile(self.index_path/f'docnos.npy')
docnos = DocnoFile(self.index_path/'docnos.npy')
num_q = query_vecs.shape[0]
ranked_lists = RankedLists(self.num_results, num_q)
dids_offset = 0
Expand Down Expand Up @@ -631,7 +628,7 @@ def index(self, inp):
index.add(doc_vecs)
docnos.extend(d['docno'] for d in batch)
faiss.write_index(index, str(path/f'{shardid}.faiss'))
DocnoFile.build(docnos, path/f'docnos.npy')
DocnoFile.build(docnos, path/'docnos.npy')



Expand Down

0 comments on commit 602ef1d

Please sign in to comment.