From a16cbedfabff6efc40704cc20692598cfecc075f Mon Sep 17 00:00:00 2001 From: tqchen Date: Tue, 10 Feb 2015 21:49:29 -0800 Subject: [PATCH] try fix memleak when test data have more features than training --- src/gbm/gblinear-inl.hpp | 7 ++++--- src/tree/model.h | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gbm/gblinear-inl.hpp b/src/gbm/gblinear-inl.hpp index de9ee6173..3d2f36f5f 100644 --- a/src/gbm/gblinear-inl.hpp +++ b/src/gbm/gblinear-inl.hpp @@ -159,7 +159,7 @@ class GBLinear : public IGradBooster { } fo << "weight:\n"; for (int i = 0; i < model.param.num_output_group; ++i) { - for (int j = 0; j = model.param.num_feature) continue; psum += inst[i].fvalue * model[inst[i].index][gid]; } preds[gid] = psum; @@ -229,7 +230,7 @@ class GBLinear : public IGradBooster { // model parameter struct Param { // number of feature dimension - int num_feature; + unsigned num_feature; // number of output group int num_output_group; // reserved field @@ -242,7 +243,7 @@ class GBLinear : public IGradBooster { } inline void SetParam(const char *name, const char *val) { using namespace std; - if (!strcmp(name, "bst:num_feature")) num_feature = atoi(val); + if (!strcmp(name, "bst:num_feature")) num_feature = static_cast(atoi(val)); if (!strcmp(name, "num_output_group")) num_output_group = atoi(val); } }; diff --git a/src/tree/model.h b/src/tree/model.h index f3575488a..4d325ea8c 100644 --- a/src/tree/model.h +++ b/src/tree/model.h @@ -503,12 +503,14 @@ class RegTree: public TreeModel{ /*! \brief fill the vector with sparse vector */ inline void Fill(const RowBatch::Inst &inst) { for (bst_uint i = 0; i < inst.length; ++i) { + if (inst[i].index >= data.size()) continue; data[inst[i].index].fvalue = inst[i].fvalue; } } /*! \brief drop the trace after fill, must be called after fill */ inline void Drop(const RowBatch::Inst &inst) { for (bst_uint i = 0; i < inst.length; ++i) { + if (inst[i].index >= data.size()) continue; data[inst[i].index].flag = -1; } }