Skip to content

Commit

Permalink
Merge pull request #726 from MichaelChirico/reserve-push-back
Browse files Browse the repository at this point in the history
Use reserve() to pre-allocate for push_back() iteration
  • Loading branch information
mnwright committed Jun 11, 2024
2 parents 5df7565 + 206285a commit 682889e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Forest.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,23 @@ class Forest {

std::vector<std::vector<size_t>> getNumSamplesNodes() {
std::vector<std::vector<size_t>> result;
result.reserve(trees.size());
for (auto& tree : trees) {
result.push_back(tree->getNumSamplesNodes());
}
return result;
}
std::vector<std::vector<double>> getNodePredictions() {
std::vector<std::vector<double>> result;
result.reserve(trees.size());
for (auto& tree : trees) {
result.push_back(tree->getNodePredictions());
}
return result;
}
std::vector<std::vector<double>> getSplitStats() {
std::vector<std::vector<double>> result;
result.reserve(trees.size());
for (auto& tree : trees) {
result.push_back(tree->getSplitStats());
}
Expand Down

0 comments on commit 682889e

Please sign in to comment.