Skip to content

Commit

Permalink
Use reserve() to pre-allocate for push_back() iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Jun 2, 2024
1 parent 5df7565 commit 206285a
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 206285a

Please sign in to comment.