MCPcopy Create free account
hub / github.com/dmlc/xgboost / AggregateReferenceColumn

Function AggregateReferenceColumn

tests/cpp/common/test_quantile.h:424–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

422}
423
424inline ReferenceColumn AggregateReferenceColumn(GeneratedColumn const& col) {
425 std::vector<std::pair<float, double>> pairs;
426 pairs.reserve(col.values.size());
427 for (std::size_t i = 0; i < col.values.size(); ++i) {
428 if (col.weights[i] == 0.0f) {
429 continue;
430 }
431 pairs.emplace_back(col.values[i], static_cast<double>(col.weights[i]));
432 }
433 std::sort(pairs.begin(), pairs.end(),
434 [](auto const& lhs, auto const& rhs) { return lhs.first < rhs.first; });
435
436 std::vector<WeightedValue> out;
437 for (auto const& [value, weight] : pairs) {
438 if (!out.empty() && out.back().value == value) {
439 out.back().weight += weight;
440 } else {
441 out.push_back({value, weight});
442 }
443 }
444
445 ReferenceColumn ref;
446 ref.values.reserve(out.size());
447 ref.prefix_weights.reserve(out.size() + 1);
448 ref.prefix_weights.push_back(0.0);
449 for (auto const& v : out) {
450 ref.values.push_back(v.value);
451 ref.prefix_weights.push_back(ref.prefix_weights.back() + v.weight);
452 }
453 return ref;
454}
455
456inline double TotalWeight(ReferenceColumn const& col) { return col.prefix_weights.back(); }
457

Callers 1

TestSummaryInvariantsFunction · 0.85

Calls 4

sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected