Skip to content

Commit

Permalink
Check cluster centers size in copy constructor of inlined kmeans (net…
Browse files Browse the repository at this point in the history
…data#19356)

Co-authored-by: Costa Tsaousis <costa@netdata.cloud>
  • Loading branch information
vkalintiris and ktsaou authored Jan 14, 2025
1 parent 4f072e6 commit 592ee98
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/ml/ml_kmeans.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ struct ml_kmeans_inlined_t {

explicit ml_kmeans_inlined_t(const ml_kmeans_t &km)
{
if (km.cluster_centers.size() != 2) {
throw std::runtime_error("ml_kmeans_t must have exactly 2 cluster centers");
if (km.cluster_centers.size() == 2) {
cluster_centers[0] = km.cluster_centers[0];
cluster_centers[1] = km.cluster_centers[1];
}

cluster_centers[0] = km.cluster_centers[0];
cluster_centers[1] = km.cluster_centers[1];
min_dist = km.min_dist;
max_dist = km.max_dist;
after = km.after;
Expand All @@ -51,11 +50,10 @@ struct ml_kmeans_inlined_t {

ml_kmeans_inlined_t &operator=(const ml_kmeans_t &km)
{
if (km.cluster_centers.size() != 2) {
throw std::runtime_error("ml_kmeans_t must have exactly 2 cluster centers");
if (km.cluster_centers.size() == 2) {
cluster_centers[0] = km.cluster_centers[0];
cluster_centers[1] = km.cluster_centers[1];
}
cluster_centers[0] = km.cluster_centers[0];
cluster_centers[1] = km.cluster_centers[1];
min_dist = km.min_dist;
max_dist = km.max_dist;
after = km.after;
Expand Down

0 comments on commit 592ee98

Please sign in to comment.