Skip to content

Commit f010178

Browse files
authored
Add the ability to read from .npy file (#14)
1 parent 10ca808 commit f010178

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

bindings/python/src/pysvs/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
)
2020

2121
# Misc types and functions
22-
from .common import read_vecs, write_vecs, read_svs, k_recall_at, generate_test_dataset
22+
from .common import read_vecs, read_npy, write_vecs, read_svs, k_recall_at, generate_test_dataset
2323

bindings/python/src/pysvs/common.py

+15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
from .loader import library
1919
lib = library()
2020

21+
def read_npy(filename:str):
22+
"""
23+
Read a file in the `npy` format and return a NumPy array with the results.
24+
25+
Args:
26+
filename: The file to read.
27+
28+
Returns:
29+
Numpy array with the results.
30+
"""
31+
32+
X = np.load(filename)
33+
return np.ascontiguousarray(X)
34+
35+
2136
def read_vecs(filename: str):
2237
"""
2338
Read a file in the `bvecs/fvecs/ivecs` format and return a NumPy array with the results.

0 commit comments

Comments
 (0)