Skip to content

Commit

Permalink
Fix clang-tidy range for loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Aug 7, 2018
1 parent 5d3ca22 commit abe7705
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
6 changes: 3 additions & 3 deletions src/gbm/gblinear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ class GBLinear : public GradientBooster {
inline void Pred(const SparsePage::Inst &inst, bst_float *preds, int gid,
bst_float base) {
bst_float psum = model_.bias()[gid] + base;
for (bst_uint i = 0; i < inst.size(); ++i) {
if (inst[i].index >= model_.param.num_feature) continue;
psum += inst[i].fvalue * model_[inst[i].index][gid];
for (const auto& ins : inst) {
if (ins.index >= model_.param.num_feature) continue;
psum += ins.fvalue * model_[ins.index][gid];
}
preds[gid] = psum;
}
Expand Down
6 changes: 3 additions & 3 deletions src/tree/updater_basemaker-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class BaseMaker: public TreeUpdater {
inline static int NextLevel(const SparsePage::Inst &inst, const RegTree &tree, int nid) {
const RegTree::Node &n = tree[nid];
bst_uint findex = n.SplitIndex();
for (unsigned i = 0; i < inst.size(); ++i) {
if (findex == inst[i].index) {
if (inst[i].fvalue < n.SplitCond()) {
for (const auto& ins : inst) {
if (findex == ins.index) {
if (ins.fvalue < n.SplitCond()) {
return n.LeftChild();
} else {
return n.RightChild();
Expand Down
54 changes: 27 additions & 27 deletions src/tree/updater_histmaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,13 @@ class CQHistMaker: public HistMaker<TStats> {
}

inline void UpdateHistCol(const std::vector<GradientPair> &gpair,
const SparsePage::Inst &c,
const SparsePage::Inst &col,
const MetaInfo &info,
const RegTree &tree,
const std::vector<bst_uint> &fset,
bst_uint fid_offset,
std::vector<HistEntry> *p_temp) {
if (c.size() == 0) return;
if (col.size() == 0) return;
// initialize sbuilder for use
std::vector<HistEntry> &hbuilder = *p_temp;
hbuilder.resize(tree.param.num_nodes);
Expand All @@ -514,46 +514,46 @@ class CQHistMaker: public HistMaker<TStats> {
}
if (TStats::kSimpleStats != 0 && this->param_.cache_opt != 0) {
constexpr bst_uint kBuffer = 32;
bst_uint align_length = c.size() / kBuffer * kBuffer;
bst_uint align_length = col.size() / kBuffer * kBuffer;
int buf_position[kBuffer];
GradientPair buf_gpair[kBuffer];
for (bst_uint j = 0; j < align_length; j += kBuffer) {
for (bst_uint i = 0; i < kBuffer; ++i) {
bst_uint ridx = c[j + i].index;
bst_uint ridx = col[j + i].index;
buf_position[i] = this->position_[ridx];
buf_gpair[i] = gpair[ridx];
}
for (bst_uint i = 0; i < kBuffer; ++i) {
const int nid = buf_position[i];
if (nid >= 0) {
hbuilder[nid].Add(c[j + i].fvalue, buf_gpair[i]);
hbuilder[nid].Add(col[j + i].fvalue, buf_gpair[i]);
}
}
}
for (bst_uint j = align_length; j < c.size(); ++j) {
const bst_uint ridx = c[j].index;
for (bst_uint j = align_length; j < col.size(); ++j) {
const bst_uint ridx = col[j].index;
const int nid = this->position_[ridx];
if (nid >= 0) {
hbuilder[nid].Add(c[j].fvalue, gpair[ridx]);
hbuilder[nid].Add(col[j].fvalue, gpair[ridx]);
}
}
} else {
for (bst_uint j = 0; j < c.size(); ++j) {
const bst_uint ridx = c[j].index;
for (const auto& c : col) {
const bst_uint ridx = c.index;
const int nid = this->position_[ridx];
if (nid >= 0) {
hbuilder[nid].Add(c[j].fvalue, gpair, info, ridx);
hbuilder[nid].Add(c.fvalue, gpair, info, ridx);
}
}
}
}
inline void UpdateSketchCol(const std::vector<GradientPair> &gpair,
const SparsePage::Inst &c,
const SparsePage::Inst &col,
const RegTree &tree,
size_t work_set_size,
bst_uint offset,
std::vector<BaseMaker::SketchEntry> *p_temp) {
if (c.size() == 0) return;
if (col.size() == 0) return;
// initialize sbuilder for use
std::vector<BaseMaker::SketchEntry> &sbuilder = *p_temp;
sbuilder.resize(tree.param.num_nodes);
Expand All @@ -565,18 +565,18 @@ class CQHistMaker: public HistMaker<TStats> {
}

// first pass, get sum of weight, TODO, optimization to skip first pass
for (bst_uint j = 0; j < c.size(); ++j) {
const bst_uint ridx = c[j].index;
for (const auto& c : col) {
const bst_uint ridx = c.index;
const int nid = this->position_[ridx];
if (nid >= 0) {
sbuilder[nid].sum_total += gpair[ridx].GetHess();
sbuilder[nid].sum_total += gpair[ridx].GetHess();
}
}
// if only one value, no need to do second pass
if (c[0].fvalue == c[c.size()-1].fvalue) {
if (col[0].fvalue == col[col.size()-1].fvalue) {
for (size_t i = 0; i < this->qexpand_.size(); ++i) {
const int nid = this->qexpand_[i];
sbuilder[nid].sketch->Push(c[0].fvalue, static_cast<bst_float>(sbuilder[nid].sum_total));
sbuilder[nid].sketch->Push(col[0].fvalue, static_cast<bst_float>(sbuilder[nid].sum_total));
}
return;
}
Expand All @@ -589,35 +589,35 @@ class CQHistMaker: public HistMaker<TStats> {
// second pass, build the sketch
if (TStats::kSimpleStats != 0 && this->param_.cache_opt != 0) {
constexpr bst_uint kBuffer = 32;
bst_uint align_length = c.size() / kBuffer * kBuffer;
bst_uint align_length = col.size() / kBuffer * kBuffer;
int buf_position[kBuffer];
bst_float buf_hess[kBuffer];
for (bst_uint j = 0; j < align_length; j += kBuffer) {
for (bst_uint i = 0; i < kBuffer; ++i) {
bst_uint ridx = c[j + i].index;
bst_uint ridx = col[j + i].index;
buf_position[i] = this->position_[ridx];
buf_hess[i] = gpair[ridx].GetHess();
}
for (bst_uint i = 0; i < kBuffer; ++i) {
const int nid = buf_position[i];
if (nid >= 0) {
sbuilder[nid].Push(c[j + i].fvalue, buf_hess[i], max_size);
sbuilder[nid].Push(col[j + i].fvalue, buf_hess[i], max_size);
}
}
}
for (bst_uint j = align_length; j < c.size(); ++j) {
const bst_uint ridx = c[j].index;
for (bst_uint j = align_length; j < col.size(); ++j) {
const bst_uint ridx = col[j].index;
const int nid = this->position_[ridx];
if (nid >= 0) {
sbuilder[nid].Push(c[j].fvalue, gpair[ridx].GetHess(), max_size);
sbuilder[nid].Push(col[j].fvalue, gpair[ridx].GetHess(), max_size);
}
}
} else {
for (bst_uint j = 0; j < c.size(); ++j) {
const bst_uint ridx = c[j].index;
for (const auto& c : col) {
const bst_uint ridx = c.index;
const int nid = this->position_[ridx];
if (nid >= 0) {
sbuilder[nid].Push(c[j].fvalue, gpair[ridx].GetHess(), max_size);
sbuilder[nid].Push(c.fvalue, gpair[ridx].GetHess(), max_size);
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/tree/updater_skmaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ class SketchMaker: public BaseMaker {
}
// update sketch information in column fid
inline void UpdateSketchCol(const std::vector<GradientPair> &gpair,
const SparsePage::Inst &c,
const SparsePage::Inst &col,
const RegTree &tree,
const std::vector<SKStats> &nstats,
bst_uint fid,
bool col_full,
std::vector<SketchEntry> *p_temp) {
if (c.size() == 0) return;
if (col.size() == 0) return;
// initialize sbuilder for use
std::vector<SketchEntry> &sbuilder = *p_temp;
sbuilder.resize(tree.param.num_nodes * 3);
Expand All @@ -192,10 +192,10 @@ class SketchMaker: public BaseMaker {
}
}
if (!col_full) {
for (bst_uint j = 0; j < c.size(); ++j) {
const bst_uint ridx = c[j].index;
for (const auto& c : col) {
const bst_uint ridx = c.index;
const int nid = this->position_[ridx];
if (nid >= 0) {
if (nid > 0) {
const GradientPair &e = gpair[ridx];
if (e.GetGrad() >= 0.0f) {
sbuilder[3 * nid + 0].sum_total += e.GetGrad();
Expand All @@ -213,10 +213,10 @@ class SketchMaker: public BaseMaker {
}
}
// if only one value, no need to do second pass
if (c[0].fvalue == c[c.size()-1].fvalue) {
if (col[0].fvalue == col[col.size()-1].fvalue) {
for (int nid : this->qexpand_) {
for (int k = 0; k < 3; ++k) {
sbuilder[3 * nid + k].sketch->Push(c[0].fvalue,
sbuilder[3 * nid + k].sketch->Push(col[0].fvalue,
static_cast<bst_float>(
sbuilder[3 * nid + k].sum_total));
}
Expand All @@ -231,17 +231,17 @@ class SketchMaker: public BaseMaker {
}
}
// second pass, build the sketch
for (bst_uint j = 0; j < c.size(); ++j) {
const bst_uint ridx = c[j].index;
for (const auto& c : col) {
const bst_uint ridx = c.index;
const int nid = this->position_[ridx];
if (nid >= 0) {
const GradientPair &e = gpair[ridx];
if (e.GetGrad() >= 0.0f) {
sbuilder[3 * nid + 0].Push(c[j].fvalue, e.GetGrad(), max_size);
sbuilder[3 * nid + 0].Push(c.fvalue, e.GetGrad(), max_size);
} else {
sbuilder[3 * nid + 1].Push(c[j].fvalue, -e.GetGrad(), max_size);
sbuilder[3 * nid + 1].Push(c.fvalue, -e.GetGrad(), max_size);
}
sbuilder[3 * nid + 2].Push(c[j].fvalue, e.GetHess(), max_size);
sbuilder[3 * nid + 2].Push(c.fvalue, e.GetHess(), max_size);
}
}
for (int nid : this->qexpand_) {
Expand Down

0 comments on commit abe7705

Please sign in to comment.