Skip to content

Commit d670ceb

Browse files
committed
[tmva] Fix Clang 21 compiler warnings in RBatchLoader
Follow up on root-project#20071. Fix the following compiler warnings: ```txt /home/rembserj/code/root/root_src/tmva/tmva/inc/TMVA/BatchGenerator/RBatchLoader.hxx:46:16: warning: private field 'fChunkSize' is not used [-Wunused-private-field] 46 | std::size_t fChunkSize; | ^ /home/rembserj/code/root/root_src/tmva/tmva/inc/TMVA/BatchGenerator/RBatchLoader.hxx:49:16: warning: private field 'fMaxBatches' is not used [-Wunused-private-field] 49 | std::size_t fMaxBatches; | ^ /home/rembserj/code/root/root_src/tmva/tmva/inc/TMVA/BatchGenerator/RBatchLoader.hxx:50:16: warning: private field 'fTrainingRemainderRow' is not used [-Wunused-private-field] 50 | std::size_t fTrainingRemainderRow = 0; | ^ /home/rembserj/code/root/root_src/tmva/tmva/inc/TMVA/BatchGenerator/RBatchLoader.hxx:51:16: warning: private field 'fValidationRemainderRow' is not used [-Wunused-private-field] 51 | std::size_t fValidationRemainderRow = 0; | ^ ``` Also, use inline namespaces for code brevity and remove some comments that trigger clang-format to not run on the doc string, although it only suggests harmless line breaks that don't change how the rendered doxygen looks like.
1 parent 0f34653 commit d670ceb

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

tmva/tmva/inc/TMVA/BatchGenerator/RBatchGenerator.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public:
144144
fChunkLoader =
145145
std::make_unique<RChunkLoader<Args...>>(f_rdf, fNumEntries, fEntries, fChunkSize, fBlockSize, fValidationSplit,
146146
fCols, vecSizes, vecPadding, fShuffle, fSetSeed);
147-
fBatchLoader = std::make_unique<RBatchLoader>(fChunkSize, fBatchSize, fNumChunkCols);
147+
fBatchLoader = std::make_unique<RBatchLoader>(fBatchSize, fNumChunkCols);
148148

149149
// split the dataset into training and validation sets
150150
fChunkLoader->SplitDataset();

tmva/tmva/inc/TMVA/BatchGenerator/RBatchLoader.hxx

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,21 @@
2727
#include "TMVA/RTensor.hxx"
2828
#include "TMVA/Tools.h"
2929

30-
namespace TMVA {
31-
namespace Experimental {
32-
namespace Internal {
30+
namespace TMVA::Experimental::Internal {
3331

34-
// clang-format off
3532
/**
3633
\class ROOT::TMVA::Experimental::Internal::RBatchLoader
3734
\ingroup tmva
3835
\brief Building and loading the batches from loaded chunks in RChunkLoader
3936
40-
In this class the chunks that are loaded into memory (see RChunkLoader) are split into batches used in the ML training which are loaded into a queue. This is done for both the training and validation chunks separatly.
37+
In this class the chunks that are loaded into memory (see RChunkLoader) are split into batches used in the ML training
38+
which are loaded into a queue. This is done for both the training and validation chunks separately.
4139
*/
4240

4341
class RBatchLoader {
4442
private:
45-
// clang-format on
46-
std::size_t fChunkSize;
4743
std::size_t fBatchSize;
4844
std::size_t fNumColumns;
49-
std::size_t fMaxBatches;
50-
std::size_t fTrainingRemainderRow = 0;
51-
std::size_t fValidationRemainderRow = 0;
5245

5346
bool fIsActive = false;
5447

@@ -63,7 +56,7 @@ private:
6356
std::size_t fNumTrainingBatchQueue;
6457
std::size_t fNumValidationBatchQueue;
6558

66-
// current batch that is loaded into memeory
59+
// current batch that is loaded into memory
6760
std::unique_ptr<TMVA::Experimental::RTensor<float>> fCurrentBatch;
6861

6962
// primary and secondary batches used to create batches from a chunk
@@ -74,8 +67,7 @@ private:
7467
std::unique_ptr<TMVA::Experimental::RTensor<float>> fSecondaryLeftoverValidationBatch;
7568

7669
public:
77-
RBatchLoader(std::size_t chunkSize, std::size_t batchSize, std::size_t numColumns)
78-
: fChunkSize(chunkSize), fBatchSize(batchSize), fNumColumns(numColumns)
70+
RBatchLoader(std::size_t batchSize, std::size_t numColumns) : fBatchSize(batchSize), fNumColumns(numColumns)
7971
{
8072

8173
fPrimaryLeftoverTrainingBatch =
@@ -95,9 +87,6 @@ public:
9587
public:
9688
void Activate()
9789
{
98-
// fTrainingRemainderRow = 0;
99-
// fValidationRemainderRow = 0;
100-
10190
{
10291
std::lock_guard<std::mutex> lock(fBatchLock);
10392
fIsActive = true;
@@ -132,7 +121,6 @@ public:
132121
return batch;
133122
}
134123

135-
136124
/// \brief Loading the training batch from the queue
137125
/// \return Training batch
138126
TMVA::Experimental::RTensor<float> GetTrainBatch()
@@ -220,7 +208,7 @@ public:
220208

221209
// copy LeftoverBatch to both fPrimaryLeftoverTrainingBatch and fSecondaryLeftoverTrainingBatch
222210
else if (emptySlots < LeftoverBatchSize) {
223-
// copy the first part of LeftoverBatch to end of fPrimaryLeftoverTrainingBatch
211+
// copy the first part of LeftoverBatch to end of fPrimaryLeftoverTrainingBatch
224212
(*fPrimaryLeftoverTrainingBatch) = (*fPrimaryLeftoverTrainingBatch).Resize({fBatchSize, fNumColumns});
225213
std::copy(LeftoverBatch.GetData(), LeftoverBatch.GetData() + (emptySlots * fNumColumns),
226214
fPrimaryLeftoverTrainingBatch->GetData() + (PrimaryLeftoverSize * fNumColumns));
@@ -231,18 +219,18 @@ public:
231219
std::copy(LeftoverBatch.GetData() + (emptySlots * fNumColumns),
232220
LeftoverBatch.GetData() + (LeftoverBatchSize * fNumColumns),
233221
fSecondaryLeftoverTrainingBatch->GetData());
234-
222+
235223
// add fPrimaryLeftoverTrainingBatch to the batch vector
236224
auto copy =
237225
std::make_unique<TMVA::Experimental::RTensor<float>>(std::vector<std::size_t>{fBatchSize, fNumColumns});
238226
std::copy(fPrimaryLeftoverTrainingBatch->GetData(),
239227
fPrimaryLeftoverTrainingBatch->GetData() + (fBatchSize * fNumColumns), copy->GetData());
240228
batches.emplace_back(std::move(copy));
241-
229+
242230
// exchange fPrimaryLeftoverTrainingBatch and fSecondaryLeftoverValidationBatch
243231
*fPrimaryLeftoverTrainingBatch = *fSecondaryLeftoverTrainingBatch;
244-
245-
// restet fSecondaryLeftoverValidationBatch
232+
233+
// reset fSecondaryLeftoverValidationBatch
246234
fSecondaryLeftoverValidationBatch =
247235
std::make_unique<TMVA::Experimental::RTensor<float>>(std::vector<std::size_t>{0, fNumColumns});
248236
}
@@ -269,7 +257,7 @@ public:
269257
fTrainingBatchQueue.push(std::move(batches[i]));
270258
}
271259
}
272-
260+
273261
/// \brief Creating the validation batches from a chunk and adding them to the queue
274262
/// \param[in] chunkTensor RTensor with the data from the chunk
275263
/// \param[in] lastbatch Check if the batch in the chunk is the last one
@@ -359,8 +347,6 @@ public:
359347
std::size_t GetNumValidationBatchQueue() { return fValidationBatchQueue.size(); }
360348
};
361349

362-
} // namespace Internal
363-
} // namespace Experimental
364-
} // namespace TMVA
350+
} // namespace TMVA::Experimental::Internal
365351

366352
#endif // TMVA_RBATCHLOADER

0 commit comments

Comments
 (0)