Skip to content

Commit d68ff42

Browse files
mdouzefacebook-github-bot
authored andcommitted
Fix OPQ dimension parsing (#2147)
Summary: Pull Request resolved: #2147 There was a bug in the OPQ string parsing. This diff adds a test and fixes the error. Reviewed By: aijanai Differential Revision: D33020167 fbshipit-source-id: 32e43653849b258a3b6d0cfdc44a6c637433f2c8
1 parent a0de37b commit d68ff42

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

faiss/index_factory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ VectorTransform* parse_VectorTransform(const std::string& description, int d) {
203203
}
204204
if (match("OPQ([0-9]+)(_[0-9]+)?")) {
205205
int M = std::stoi(sm[1].str());
206-
int d_out = mres_to_int(sm[2], d);
206+
int d_out = mres_to_int(sm[2], d, 1);
207207
return new OPQMatrix(d, M, d_out);
208208
}
209209
if (match("Pad([0-9]+)")) {

tests/test_factory.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def test_factory_2(self):
3939
index = faiss.index_factory(12, "SQ8")
4040
assert index.code_size == 12
4141

42+
4243
def test_factory_3(self):
4344

4445
index = faiss.index_factory(12, "IVF10,PQ4")
@@ -53,6 +54,13 @@ def test_factory_4(self):
5354
index = faiss.index_factory(12, "IVF10,FlatDedup")
5455
assert index.instances is not None
5556

57+
def test_factory_5(self):
58+
index = faiss.index_factory(128, "OPQ16,Flat")
59+
assert index.sa_code_size() == 128 * 4
60+
index = faiss.index_factory(128, "OPQ16_64,Flat")
61+
assert index.sa_code_size() == 64 * 4
62+
assert index.chain.at(0).d_out == 64
63+
5664
def test_factory_HNSW(self):
5765
index = faiss.index_factory(12, "HNSW32")
5866
assert index.storage.sa_code_size() == 12 * 4
@@ -61,7 +69,6 @@ def test_factory_HNSW(self):
6169
index = faiss.index_factory(12, "HNSW32_PQ4")
6270
assert index.storage.sa_code_size() == 4
6371

64-
6572
def test_factory_HNSW_newstyle(self):
6673
index = faiss.index_factory(12, "HNSW32,Flat")
6774
assert index.storage.sa_code_size() == 12 * 4

0 commit comments

Comments
 (0)