Skip to content

Commit 8e895c5

Browse files
committed
[matchcore] Replace const UInt_t with constexpr std::size_t in test
1 parent 75f92f7 commit 8e895c5

1 file changed

Lines changed: 32 additions & 32 deletions

File tree

math/mathcore/test/testkdTreeBinning.cxx

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ int testkdTreeBinning()
4040
// C r e a t e r a n d o m s a m p l e
4141
// -----------------------------------------------------------------------------------------------
4242

43-
const UInt_t DATASZ = 10000;
44-
const UInt_t DATADIM = 2;
45-
const UInt_t NBINS = 50;
43+
constexpr std::size_t DATASZ = 10000;
44+
constexpr std::size_t DATADIM = 2;
45+
constexpr std::size_t NBINS = 50;
4646

47-
Double_t smp[DATASZ * DATADIM];
47+
double smp[DATASZ * DATADIM];
4848

4949
double mu[2] = {0,2};
5050
double sig[2] = {2,3};
5151
TRandom3 r;
5252
r.SetSeed(1);
53-
for (UInt_t i = 0; i < DATADIM; ++i)
54-
for (UInt_t j = 0; j < DATASZ; ++j)
53+
for (std::size_t i = 0; i < DATADIM; ++i)
54+
for (std::size_t j = 0; j < DATASZ; ++j)
5555
smp[DATASZ * i + j] = r.Gaus(mu[i], sig[i]);
5656

57-
UInt_t h1bins = (UInt_t) std::sqrt(double(NBINS));
57+
std::size_t h1bins = std::sqrt(double(NBINS));
5858

5959
TH2D* h1 = new TH2D("h1BinTest", "Regular binning", h1bins, -5., 5., h1bins, -5., 5.);
60-
for (UInt_t j = 0; j < DATASZ; ++j)
60+
for (std::size_t j = 0; j < DATASZ; ++j)
6161
h1->Fill(smp[j], smp[DATASZ + j]);
6262

6363

@@ -67,20 +67,20 @@ int testkdTreeBinning()
6767

6868
TKDTreeBinning* kdBins = new TKDTreeBinning(DATASZ, DATADIM, smp, NBINS);
6969

70-
UInt_t nbins = kdBins->GetNBins();
71-
UInt_t dim = kdBins->GetDim();
70+
std::size_t nbins = kdBins->GetNBins();
71+
std::size_t dim = kdBins->GetDim();
7272

73-
const Double_t* binsMinEdges = kdBins->GetBinsMinEdges();
74-
const Double_t* binsMaxEdges = kdBins->GetBinsMaxEdges();
73+
const double *binsMinEdges = kdBins->GetBinsMinEdges();
74+
const double *binsMaxEdges = kdBins->GetBinsMaxEdges();
7575

7676
TH2Poly* h2pol = new TH2Poly("h2PolyBinTest", "KDTree binning", kdBins->GetDataMin(0), kdBins->GetDataMax(0), kdBins->GetDataMin(1), kdBins->GetDataMax(1));
7777

78-
for (UInt_t i = 0; i < nbins; ++i) {
79-
UInt_t edgeDim = i * dim;
78+
for (std::size_t i = 0; i < nbins; ++i) {
79+
std::size_t edgeDim = i * dim;
8080
h2pol->AddBin(binsMinEdges[edgeDim], binsMinEdges[edgeDim + 1], binsMaxEdges[edgeDim], binsMaxEdges[edgeDim + 1]);
8181
}
8282

83-
for (UInt_t i = 1; i <= kdBins->GetNBins(); ++i)
83+
for (std::size_t i = 1; i <= kdBins->GetNBins(); ++i)
8484
h2pol->SetBinContent(i, kdBins->GetBinDensity(i - 1));
8585

8686
int ibinMin = kdBins->GetBinMinDensity();
@@ -179,47 +179,47 @@ int testkdTreeBinningFindBinRange()
179179

180180
int nfail = 0;
181181

182-
const UInt_t DATASZ = 100500; // deliberately NOT a multiple of NBINS
183-
const UInt_t DATADIM = 5;
184-
const UInt_t NBINS = 1000;
182+
constexpr std::size_t DATASZ = 100500; // deliberately NOT a multiple of NBINS
183+
constexpr std::size_t DATADIM = 5;
184+
constexpr std::size_t NBINS = 1000;
185185

186-
std::vector<Double_t> smp(DATASZ * DATADIM);
186+
std::vector<double> smp(DATASZ * DATADIM);
187187
TRandom3 r;
188188
r.SetSeed(1);
189-
for (UInt_t i = 0; i < DATADIM; ++i)
190-
for (UInt_t j = 0; j < DATASZ; ++j)
189+
for (std::size_t i = 0; i < DATADIM; ++i)
190+
for (std::size_t j = 0; j < DATASZ; ++j)
191191
smp[DATASZ * i + j] = r.Uniform(-1., 1.);
192192

193193
TKDTreeBinning kdBins(DATASZ, DATADIM, smp, NBINS);
194194

195-
const UInt_t nbins = kdBins.GetNBins();
195+
const std::size_t nbins = kdBins.GetNBins();
196196

197197
// The number of bins must match the number of terminal nodes of the kd-tree.
198198
if ((int)nbins != kdBins.GetTree()->GetNNodes() + 1) {
199-
Error("testkdTreeBinningFindBinRange", "GetNBins() (%u) != number of kd-tree terminal nodes (%d)", nbins,
199+
Error("testkdTreeBinningFindBinRange", "GetNBins() (%zu) != number of kd-tree terminal nodes (%d)", nbins,
200200
kdBins.GetTree()->GetNNodes() + 1);
201201
++nfail;
202202
}
203203

204204
// Every data point must be assigned to a valid bin.
205-
std::vector<Double_t> point(DATADIM);
206-
for (UInt_t j = 0; j < DATASZ; ++j) {
207-
for (UInt_t i = 0; i < DATADIM; ++i)
205+
std::vector<double> point(DATADIM);
206+
for (std::size_t j = 0; j < DATASZ; ++j) {
207+
for (std::size_t i = 0; i < DATADIM; ++i)
208208
point[i] = smp[DATASZ * i + j];
209-
UInt_t bin = kdBins.FindBin(point.data());
209+
std::size_t bin = kdBins.FindBin(point.data());
210210
if (bin >= nbins) {
211-
Error("testkdTreeBinningFindBinRange", "FindBin returned out-of-range bin %u (NBins = %u)", bin, nbins);
211+
Error("testkdTreeBinningFindBinRange", "FindBin returned out-of-range bin %zu (NBins = %zu)", bin, nbins);
212212
++nfail;
213213
break;
214214
}
215215
}
216216

217217
// The total bin content must add up to the data size.
218218
Long64_t total = 0;
219-
for (UInt_t i = 0; i < nbins; ++i)
219+
for (std::size_t i = 0; i < nbins; ++i)
220220
total += kdBins.GetBinContent(i);
221221
if (total != (Long64_t)DATASZ) {
222-
Error("testkdTreeBinningFindBinRange", "Sum of bin contents (%lld) != data size (%u)", total, DATASZ);
222+
Error("testkdTreeBinningFindBinRange", "Sum of bin contents (%lld) != data size (%zu)", total, DATASZ);
223223
++nfail;
224224
}
225225

@@ -229,7 +229,7 @@ int testkdTreeBinningFindBinRange()
229229
int main(int argc, char **argv)
230230
{
231231
// Parse command line arguments
232-
for (Int_t i=1 ; i<argc ; i++) {
232+
for (int i = 1; i < argc; i++) {
233233
std::string arg = argv[i] ;
234234
if (arg == "-g") {
235235
showGraphics = true;
@@ -246,7 +246,7 @@ int main(int argc, char **argv)
246246
cerr << endl;
247247
return -1;
248248
}
249-
}
249+
}
250250

251251
TApplication* theApp = nullptr;
252252
if ( showGraphics )

0 commit comments

Comments
 (0)