From abe77055c3692c8323303721829c2f5e1b2bf663 Mon Sep 17 00:00:00 2001 From: fis Date: Tue, 7 Aug 2018 04:55:55 +0800 Subject: [PATCH] Fix clang-tidy range for loop. --- src/gbm/gblinear.cc | 6 ++-- src/tree/updater_basemaker-inl.h | 6 ++-- src/tree/updater_histmaker.cc | 54 ++++++++++++++++---------------- src/tree/updater_skmaker.cc | 24 +++++++------- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/gbm/gblinear.cc b/src/gbm/gblinear.cc index 31c329b248bf..ca1a0399cd16 100644 --- a/src/gbm/gblinear.cc +++ b/src/gbm/gblinear.cc @@ -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; } diff --git a/src/tree/updater_basemaker-inl.h b/src/tree/updater_basemaker-inl.h index fd55b75cee0b..c64c5b29a5b1 100644 --- a/src/tree/updater_basemaker-inl.h +++ b/src/tree/updater_basemaker-inl.h @@ -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(); diff --git a/src/tree/updater_histmaker.cc b/src/tree/updater_histmaker.cc index 42717fec45f9..cdf7e64d09c9 100644 --- a/src/tree/updater_histmaker.cc +++ b/src/tree/updater_histmaker.cc @@ -496,13 +496,13 @@ class CQHistMaker: public HistMaker { } inline void UpdateHistCol(const std::vector &gpair, - const SparsePage::Inst &c, + const SparsePage::Inst &col, const MetaInfo &info, const RegTree &tree, const std::vector &fset, bst_uint fid_offset, std::vector *p_temp) { - if (c.size() == 0) return; + if (col.size() == 0) return; // initialize sbuilder for use std::vector &hbuilder = *p_temp; hbuilder.resize(tree.param.num_nodes); @@ -514,46 +514,46 @@ class CQHistMaker: public HistMaker { } 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 &gpair, - const SparsePage::Inst &c, + const SparsePage::Inst &col, const RegTree &tree, size_t work_set_size, bst_uint offset, std::vector *p_temp) { - if (c.size() == 0) return; + if (col.size() == 0) return; // initialize sbuilder for use std::vector &sbuilder = *p_temp; sbuilder.resize(tree.param.num_nodes); @@ -565,18 +565,18 @@ class CQHistMaker: public HistMaker { } // 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(sbuilder[nid].sum_total)); + sbuilder[nid].sketch->Push(col[0].fvalue, static_cast(sbuilder[nid].sum_total)); } return; } @@ -589,35 +589,35 @@ class CQHistMaker: public HistMaker { // 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); } } } diff --git a/src/tree/updater_skmaker.cc b/src/tree/updater_skmaker.cc index a913e381f934..0696d6329666 100644 --- a/src/tree/updater_skmaker.cc +++ b/src/tree/updater_skmaker.cc @@ -174,13 +174,13 @@ class SketchMaker: public BaseMaker { } // update sketch information in column fid inline void UpdateSketchCol(const std::vector &gpair, - const SparsePage::Inst &c, + const SparsePage::Inst &col, const RegTree &tree, const std::vector &nstats, bst_uint fid, bool col_full, std::vector *p_temp) { - if (c.size() == 0) return; + if (col.size() == 0) return; // initialize sbuilder for use std::vector &sbuilder = *p_temp; sbuilder.resize(tree.param.num_nodes * 3); @@ -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(); @@ -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( sbuilder[3 * nid + k].sum_total)); } @@ -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_) {