Skip to content

Commit a02dc62

Browse files
committed
fix(tdigest): add check result for byrank
1 parent 01f303a commit a02dc62

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/types/tdigest.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ struct DoubleComparator {
174174
template <bool Reverse, typename TD>
175175
inline Status TDigestByRank(TD&& td, const std::vector<int>& inputs, std::vector<double>& result) {
176176
result.clear();
177-
result.resize(inputs.size(), -2);
177+
result.resize(inputs.size(), std::numeric_limits<double>::quiet_NaN());
178178

179179
std::map<int, size_t> rank_to_index;
180180
for (size_t i = 0; i < inputs.size(); ++i) {
@@ -203,6 +203,13 @@ inline Status TDigestByRank(TD&& td, const std::vector<int>& inputs, std::vector
203203
}
204204
++it;
205205
}
206+
207+
// check if all results are valid
208+
for (auto r : result) {
209+
if (std::isnan(r)) {
210+
return Status{Status::InvalidArgument, "invalid result when getting byrank or byrevrank"};
211+
}
212+
}
206213
return Status::OK();
207214
}
208215

0 commit comments

Comments
 (0)