Skip to content

Commit 5e21d26

Browse files
committed
Handle NULLs in default metrics
1 parent 0ce2ce8 commit 5e21d26

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/core/config/custom_metric/custom_metric.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class DefaultCustomMetric : public ICustomMetric {
8585
public:
8686
double Dist(model::Type const* type, std::byte const* first,
8787
std::byte const* second) const override {
88+
if (!first || !second) {
89+
return 0;
90+
}
8891
return ConvertType(type)->Dist(first, second);
8992
}
9093
};

src/core/config/custom_metric/custom_vector_metric.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class DefaultCustomVectorMetric : public ICustomVectorMetric {
6565

6666
double result = 0;
6767
for (std::size_t i = 0; i < types.size(); ++i) {
68-
result += std::pow(ConvertType(types[i])->Dist(first[i], second[i]), 2);
68+
if (first[i] && second[i]) {
69+
result += std::pow(ConvertType(types[i])->Dist(first[i], second[i]), 2);
70+
}
6971
}
7072
return std::sqrt(result);
7173
}

0 commit comments

Comments
 (0)