@@ -218,8 +218,9 @@ class MetaInfo {
218218 * @brief Setter for categories.
219219 */
220220 void Cats (std::shared_ptr<CatContainer> cats);
221-
222- void SetReadFlag () { this ->has_been_read_ = true ; }
221+ // Flag to indicate whether one needs to refresh the DMatrix cache.
222+ void SetReadFlag (bool has_been_read) { this ->has_been_read_ = has_been_read; }
223+ [[nodiscard]] bool HasBeenRead () const { return this ->has_been_read_ ; }
223224
224225 private:
225226 void SetInfoFromHost (Context const * ctx, StringView key, Json arr);
@@ -743,7 +744,7 @@ class DMatrix {
743744
744745template <>
745746inline BatchSet<SparsePage> DMatrix::GetBatches () {
746- this ->Info ().SetReadFlag ();
747+ this ->Info ().SetReadFlag (true );
747748 return GetRowBatches ();
748749}
749750
@@ -764,37 +765,37 @@ inline bool DMatrix::PageExists<SparsePage>() const {
764765
765766template <>
766767inline BatchSet<SparsePage> DMatrix::GetBatches (Context const *) {
767- this ->Info ().SetReadFlag ();
768+ this ->Info ().SetReadFlag (true );
768769 return GetRowBatches ();
769770}
770771
771772template <>
772773inline BatchSet<CSCPage> DMatrix::GetBatches (Context const * ctx) {
773- this ->Info ().SetReadFlag ();
774+ this ->Info ().SetReadFlag (true );
774775 return GetColumnBatches (ctx);
775776}
776777
777778template <>
778779inline BatchSet<SortedCSCPage> DMatrix::GetBatches (Context const * ctx) {
779- this ->Info ().SetReadFlag ();
780+ this ->Info ().SetReadFlag (true );
780781 return GetSortedColumnBatches (ctx);
781782}
782783
783784template <>
784785inline BatchSet<EllpackPage> DMatrix::GetBatches (Context const * ctx, BatchParam const & param) {
785- this ->Info ().SetReadFlag ();
786+ this ->Info ().SetReadFlag (true );
786787 return GetEllpackBatches (ctx, param);
787788}
788789
789790template <>
790791inline BatchSet<GHistIndexMatrix> DMatrix::GetBatches (Context const * ctx, BatchParam const & param) {
791- this ->Info ().SetReadFlag ();
792+ this ->Info ().SetReadFlag (true );
792793 return GetGradientIndex (ctx, param);
793794}
794795
795796template <>
796797inline BatchSet<ExtSparsePage> DMatrix::GetBatches (Context const * ctx, BatchParam const & param) {
797- this ->Info ().SetReadFlag ();
798+ this ->Info ().SetReadFlag (true );
798799 return GetExtBatches (ctx, param);
799800}
800801} // namespace xgboost
0 commit comments