@@ -31,7 +31,7 @@ namespace xgboost{
31
31
* \brief a regression booter associated with training and evaluating data
32
32
* \param mats array of pointers to matrix whose prediction result need to be cached
33
33
*/
34
- RegRankBoostLearner (const std::vector<const DMatrix *>& mats){
34
+ RegRankBoostLearner (const std::vector<DMatrix *>& mats){
35
35
silent = 0 ;
36
36
obj_ = NULL ;
37
37
name_obj_ = " reg:linear" ;
@@ -45,7 +45,7 @@ namespace xgboost{
45
45
* data matrices to continue training otherwise it will cause error
46
46
* \param mats array of pointers to matrix whose prediction result need to be cached
47
47
*/
48
- inline void SetCacheData (const std::vector<const DMatrix *>& mats){
48
+ inline void SetCacheData (const std::vector<DMatrix *>& mats){
49
49
// estimate feature bound
50
50
int num_feature = 0 ;
51
51
// assign buffer index
@@ -58,7 +58,9 @@ namespace xgboost{
58
58
if ( mats[i] == mats[j] ) dupilicate = true ;
59
59
}
60
60
if ( dupilicate ) continue ;
61
- cache_.push_back ( CacheEntry ( mats[i], buffer_size ) );
61
+ // set mats[i]'s cache learner pointer to this
62
+ mats[i]->cache_learner_ptr_ = this ;
63
+ cache_.push_back ( CacheEntry ( mats[i], buffer_size, mats[i]->Size () ) );
62
64
buffer_size += static_cast <unsigned >(mats[i]->Size ());
63
65
num_feature = std::max (num_feature, (int )(mats[i]->data .NumCol ()));
64
66
}
@@ -342,17 +344,25 @@ namespace xgboost{
342
344
private:
343
345
struct CacheEntry {
344
346
const DMatrix *mat_;
345
- int buffer_offset_;
346
- CacheEntry (const DMatrix *mat, int buffer_offset)
347
- :mat_(mat), buffer_offset_(buffer_offset){}
347
+ int buffer_offset_;
348
+ size_t num_row_;
349
+ CacheEntry (const DMatrix *mat, int buffer_offset, size_t num_row)
350
+ :mat_(mat), buffer_offset_(buffer_offset), num_row_(num_row){}
348
351
};
349
352
/* ! \brief the entries indicates that we have internal prediction cache */
350
353
std::vector<CacheEntry> cache_;
351
354
private:
352
355
// find internal bufer offset for certain matrix, if not exist, return -1
353
356
inline int FindBufferOffset (const DMatrix &mat){
354
357
for (size_t i = 0 ; i < cache_.size (); ++i){
355
- if ( cache_[i].mat_ == &mat ) return cache_[i].buffer_offset_ ;
358
+ if ( cache_[i].mat_ == &mat && mat.cache_learner_ptr_ == this ) {
359
+ if ( cache_[i].num_row_ == mat.Size () ){
360
+ return cache_[i].buffer_offset_ ;
361
+ }else {
362
+ fprintf ( stderr, " warning: number of rows in input matrix changed as remembered in cachelist, ignore cached results\n " );
363
+ fflush ( stderr );
364
+ }
365
+ }
356
366
}
357
367
return -1 ;
358
368
}
0 commit comments