Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions include/rabitqlib/clustering/qgkmeans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ class QGAssigner {
, graph_build_iterations_(graph_build_iterations)
, seed_(seed) {
validate_configuration(num_threads);
// Cosine belongs to the indexes, which normalize vectors; the assigner's exact
// distances are raw L2 or inner product.
validate_metric_type(metric_type);
num_workers_ = static_cast<uint32_t>(resolve_num_threads(num_threads));

graph_ = std::make_unique<symqg::QuantizedGraph<float>>(
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/rabitqlib/clustering/qgkmeans_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,18 @@ TEST(QGAssignerTest, RejectsTooFewClustersForGraphDegree) {
EXPECT_THROW(QGAssigner(64, 32, 32, 64, 16, 1, 1), std::invalid_argument);
}

// Like the quantizers and FastScan, clustering takes only L2 and inner product.
TEST(QGAssignerTest, RejectsTheCosineMetric) {
try {
const QGAssigner assigner(64, 33, 32, 64, 16, 1, 1, 42, METRIC_COSINE);
ADD_FAILURE() << "accepted METRIC_COSINE";
} catch (const std::invalid_argument& error) {
EXPECT_STREQ(error.what(), "Metric type must be METRIC_L2 or METRIC_IP");
}
EXPECT_NO_THROW(QGAssigner(64, 33, 32, 64, 16, 1, 1, 42, METRIC_L2));
EXPECT_NO_THROW(QGAssigner(64, 33, 32, 64, 16, 1, 1, 42, METRIC_IP));
}

TEST(QGKMeansTest, RejectsTooFewClustersForGraphDegreeInBothFinalModes) {
constexpr size_t kDim = 64, kPoints = 65;
const std::vector<float> data(kPoints * kDim, 0.0F);
Expand Down
Loading