File indexing completed on 2026-08-16 09:21:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROOT_INTERNAL_ML_RBATCHLOADER
0017 #define ROOT_INTERNAL_ML_RBATCHLOADER
0018
0019 #include <condition_variable>
0020 #include <memory>
0021 #include <mutex>
0022 #include <queue>
0023 #include <string>
0024 #include <vector>
0025
0026 #include "ROOT/ML/RFlat2DMatrix.hxx"
0027
0028 namespace ROOT::Experimental::Internal::ML {
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 class RBatchLoader {
0039 private:
0040 std::size_t fBatchSize;
0041
0042 std::vector<std::string> fCols;
0043 std::mutex &fLock;
0044 std::condition_variable &fCV;
0045 std::vector<std::size_t> fVecSizes;
0046 std::size_t fSumVecSizes;
0047 std::size_t fNumColumns;
0048 std::size_t fNumEntries;
0049 bool fDropRemainder;
0050
0051 std::size_t fNumFullBatches;
0052 std::size_t fNumBatches;
0053 std::size_t fLeftoverBatchSize;
0054
0055 bool fIsActive = false;
0056 bool fProducerDone = true;
0057
0058
0059 std::queue<std::unique_ptr<RFlat2DMatrix>> fBatchQueue;
0060
0061
0062 std::unique_ptr<RFlat2DMatrix> fCurrentBatch;
0063
0064
0065 std::unique_ptr<RFlat2DMatrix> fPrimaryLeftoverBatch;
0066 std::unique_ptr<RFlat2DMatrix> fSecondaryLeftoverBatch;
0067
0068 public:
0069 RBatchLoader(std::size_t batchSize, const std::vector<std::string> &cols, std::mutex &sharedMutex,
0070 std::condition_variable &sharedCV, const std::vector<std::size_t> &vecSizes = {},
0071 std::size_t numEntries = 0, bool dropRemainder = false);
0072
0073 void Activate();
0074 void DeActivate();
0075 void Reset();
0076 void MarkProducerDone();
0077
0078 std::unique_ptr<RFlat2DMatrix> CreateBatch(RFlat2DMatrix &chunkTensor, std::size_t idxs);
0079 RFlat2DMatrix GetBatch();
0080 void CreateBatches(RFlat2DMatrix &chunkTensor, bool isLastBatch);
0081 void RecalculateBatchCounts(std::size_t numEntries);
0082
0083 bool isProducerDone() { return fProducerDone; }
0084 std::size_t GetNumBatches() { return fNumBatches; }
0085 std::size_t GetNumEntries() { return fNumEntries; }
0086 std::size_t GetNumRemainderRows() { return fLeftoverBatchSize; }
0087 std::size_t GetNumBatchQueue() { return fBatchQueue.size(); }
0088 };
0089
0090 }
0091
0092 #endif