diff --git a/booster/xgboost_data.h b/booster/xgboost_data.h index 128544e55..01c567777 100644 --- a/booster/xgboost_data.h +++ b/booster/xgboost_data.h @@ -305,6 +305,27 @@ namespace xgboost{ FMatrixS::LoadBinary( fi, col_ptr_, col_data_ ); } } + /*! + * \brief load from text file + * \param fi input file pointer + */ + inline void LoadText( FILE *fi ){ + this->Clear(); + int ninst; + while( fscanf( fi, "%d", &ninst ) == 1 ){ + std::vector findex; + std::vector fvalue; + while( -- ninst ){ + unsigned index; float value; + utils::Assert( fscanf( fi, "%u:%f", &index, &value ) == 2 ); + findex.push_back( index ); fvalue.push_back( value ); + } + this->AddRow( findex, fvalue ); + } + // initialize column support as well + this->InitData(); + fclose(fi); + } private: /*! * \brief save data to binary stream