fast-clustering-test.cc
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// sherpa-onnx/csrc/fast-clustering-test.cc
//
// Copyright (c) 2024 Xiaomi Corporation
#include "sherpa-onnx/csrc/fast-clustering.h"
#include <vector>
#include "gtest/gtest.h"
namespace sherpa_onnx {
TEST(FastClustering, TestTwoClusters) {
std::vector<float> features = {
// point 0
0.1,
0.1,
// point 2
0.4,
-0.5,
// point 3
0.6,
-0.7,
// point 1
0.2,
0.3,
};
FastClusteringConfig config;
config.num_clusters = 2;
FastClustering clustering(config);
auto labels = clustering.Cluster(features.data(), 4, 2);
int32_t k = 0;
for (auto i : labels) {
std::cout << "point " << k << ": label " << i << "\n";
++k;
}
}
TEST(FastClustering, TestClusteringWithThreshold) {
std::vector<float> features = {
// point 0
0.1,
0.1,
// point 2
0.4,
-0.5,
// point 3
0.6,
-0.7,
// point 1
0.2,
0.3,
};
FastClusteringConfig config;
config.threshold = 0.5;
FastClustering clustering(config);
auto labels = clustering.Cluster(features.data(), 4, 2);
int32_t k = 0;
for (auto i : labels) {
std::cout << "point " << k << ": label " << i << "\n";
++k;
}
}
} // namespace sherpa_onnx