Skip to content

Commit

Permalink
Refactor UpdateConstraints loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesAuguste committed Sep 20, 2020
1 parent f554a24 commit 6b3d73d
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/treelearner/monotone_constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ class AdvancedLeafConstraints : public IntermediateLeafConstraints {
? -std::numeric_limits<double>::max()
: std::numeric_limits<double>::max();
double current_constraint;
for (size_t i = 0; i < feature_constraint->thresholds.size();) {
for (size_t i = 0; i < feature_constraint->thresholds.size(); ++i) {
current_constraint = feature_constraint->constraints[i];
// easy case when the thresholds match
if (feature_constraint->thresholds[i] == it_start) {
Expand Down Expand Up @@ -908,14 +908,13 @@ class AdvancedLeafConstraints : public IntermediateLeafConstraints {
feature_constraint->constraints.begin() + i, extremum);
feature_constraint->thresholds.insert(
feature_constraint->thresholds.begin() + i, it_start);
i += 1;
++i;
}
}
}
// easy case when the end thresholds match
if (feature_constraint->thresholds[i] == it_end) {
end_done = true;
i += 1;
break;
}
// if they don't then, the previous constraint needs to be added back
Expand All @@ -929,7 +928,6 @@ class AdvancedLeafConstraints : public IntermediateLeafConstraints {
feature_constraint->thresholds.begin() + i, it_end);
}
end_done = true;
i += 1;
break;
}
// If 2 successive constraints are the same then the second one may as
Expand All @@ -941,10 +939,9 @@ class AdvancedLeafConstraints : public IntermediateLeafConstraints {
feature_constraint->thresholds.erase(
feature_constraint->thresholds.begin() + i);
previous_constraint = current_constraint;
i -= 1;
--i;
}
previous_constraint = current_constraint;
i += 1;
}
// if the loop didn't get to an index greater than it_start, it needs to be
// added at the end
Expand Down

0 comments on commit 6b3d73d

Please sign in to comment.