Skip to content

Commit 1d37841

Browse files
author
Petr Jacka
committed
[RDF] Adding tests
1 parent a92ccf0 commit 1d37841

File tree

6 files changed

+164
-0
lines changed

6 files changed

+164
-0
lines changed

bindings/distrdf/test/test_operation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,14 @@ def test_histond_without_model(self):
112112
"""Creating a histogram without model raises ValueError."""
113113
with self.assertRaises(ValueError):
114114
_ = Operation.create_op("HistoND", ["a", "b", "c", "d"])
115+
116+
def test_histonsparsed_with_thnsparsedmodel(self):
117+
"""THnDModel"""
118+
op = Operation.create_op("HistoNSparseD", ROOT.RDF.THnSparseDModel(), ["a", "b", "c", "d"])
119+
self.assertIsInstance(op, Operation.Histo)
120+
self.assertEqual(op.name, "HistoNSparseD")
121+
122+
def test_histonsparsed_without_model(self):
123+
"""Creating a histogram without model raises ValueError."""
124+
with self.assertRaises(ValueError):
125+
_ = Operation.create_op("HistoNSparseD", ["a", "b", "c", "d"])

roottest/python/distrdf/backends/check_reducer_merge.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ def test_histond_merge(self, payload):
125125
assert histond_distrdf.GetEntries() == histond_rdf.GetEntries()
126126
assert histond_distrdf.GetNbins() == histond_rdf.GetNbins()
127127

128+
def test_histonsparsed_merge(self, payload):
129+
"""Check the working of HistoND merge operation in the reducer."""
130+
nbins = (10, 10, 10, 10)
131+
xmin = (0., 0., 0., 0.)
132+
xmax = (100., 100., 100., 100.)
133+
modelTHNSparseD = ("name", "title", 4, nbins, xmin, xmax)
134+
colnames = ("x0", "x1", "x2", "x3")
135+
136+
connection, _ = payload
137+
distrdf = ROOT.RDataFrame(100, executor=connection)
138+
139+
rdf = ROOT.RDataFrame(100)
140+
141+
distrdf_withcols = self.define_four_columns(distrdf, colnames)
142+
rdf_withcols = self.define_four_columns(rdf, colnames)
143+
144+
histond_distrdf = distrdf_withcols.HistoNSparseD(modelTHNSparseD, colnames)
145+
histond_rdf = rdf_withcols.HistoNSparseD(modelTHNSparseD, colnames)
146+
147+
assert histond_distrdf.GetEntries() == histond_rdf.GetEntries()
148+
assert histond_distrdf.GetNbins() == histond_rdf.GetNbins()
149+
128150
def test_profile1d_merge(self, payload):
129151
"""Check the working of Profile1D merge operation in the reducer."""
130152
# Operations with DistRDF

tree/dataframe/test/dataframe_cloning.cxx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,26 @@ TEST(RDataFrameCloning, HistoND)
188188
EXPECT_EQ(df.GetNRuns(), 1);
189189
}
190190

191+
TEST(RDataFrameCloning, HistoNSparseD)
192+
{
193+
ROOT::RDataFrame df{100};
194+
auto col1 = df.Define("x0", [](ULong64_t e) { return double(e); }, {"rdfentry_"});
195+
auto col2 = col1.Define("x1", [](ULong64_t e) { return double(e); }, {"rdfentry_"});
196+
auto col3 = col2.Define("x2", [](ULong64_t e) { return double(e); }, {"rdfentry_"});
197+
auto col4 = col3.Define("x3", [](ULong64_t e) { return double(e); }, {"rdfentry_"});
198+
199+
int nbins[4] = {10, 10, 10, 10};
200+
double xmin[4] = {0., 0., 0., 0.};
201+
double xmax[4] = {100., 100., 100., 100.};
202+
auto histo =
203+
col4.HistoNSparseD<double, double, double, double>({"name", "title", 4, nbins, xmin, xmax}, {"x0", "x1", "x2", "x3"});
204+
auto clone = CloneResultAndAction(histo);
205+
206+
EXPECT_EQ((*histo).GetEntries(), 100);
207+
EXPECT_EQ((*clone).GetEntries(), 100);
208+
EXPECT_EQ(df.GetNRuns(), 1);
209+
}
210+
191211
TEST(RDataFrameCloning, Profile1D)
192212
{
193213
ROOT::RDataFrame df{100};

tree/dataframe/test/dataframe_histomodels.cxx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,70 @@ TEST(RDataFrameHistoModels, HistoND)
336336
}
337337
}
338338

339+
340+
TEST(RDataFrameHistoModels, HistoNSparseD)
341+
{
342+
ROOT::RDataFrame tdf(10);
343+
auto x = 0.;
344+
auto d = tdf.Define("x0", [&x]() { return x++; })
345+
.Define("x1", [&x]() { return x + .1; })
346+
.Define("x2", [&x]() { return x + .1; })
347+
.Define("x3", [&x]() { return x + .1; });
348+
int nbins[4] = {10, 5, 2, 2};
349+
double xmin[4] = {0., 0., 0., 0.};
350+
double xmax[4] = {10., 10., 10., 10.};
351+
auto h1 = d.HistoNSparseD(::THnSparseD("h1", "h1", 4, nbins, xmin, xmax), {"x0", "x1", "x2", "x3"});
352+
auto h2 = d.HistoNSparseD({"h2", "h2", 4, nbins, xmin, xmax}, {"x0", "x1", "x2", "x3"});
353+
354+
std::vector<double> edges0{1, 2, 3, 4, 5, 6, 10};
355+
std::vector<double> edges1{1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 10.1};
356+
std::vector<double> edges2{1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 10.2};
357+
std::vector<double> edges3{1.3, 2.3, 3.3, 4.3, 5.3, 6.3, 10.3};
358+
std::vector<std::vector<double>> edges = {edges0, edges1, edges2, edges3};
359+
int nbinse[4];
360+
for (unsigned int idim = 0; idim < edges.size(); ++idim) {
361+
nbinse[idim] = edges[idim].size() - 1;
362+
}
363+
auto h1e = d.HistoNSparseD(::THnSparseD("h1e", "h1e", 4, nbinse, edges), {"x0", "x1", "x2", "x3"});
364+
auto h2e = d.HistoNSparseD({"h2e", "h2e", 4, nbinse, edges}, {"x0", "x1", "x2", "x3"});
365+
366+
THnSparseDModel m0("m0", "m0", 4, nbins, xmin, xmax);
367+
THnSparseDModel m1(::THnSparseD("m1", "m1", 4, nbins, xmin, xmax));
368+
369+
auto hm0 = d.HistoNSparseD(m0, {"x0", "x1", "x2", "x3"});
370+
auto hm1 = d.HistoNSparseD(m1, {"x0", "x1", "x2", "x3"});
371+
auto hm0w = d.HistoNSparseD(m0, {"x0", "x1", "x2", "x3", "x3"});
372+
auto hm1w = d.HistoNSparseD(m1, {"x0", "x1", "x2", "x3", "x3"});
373+
374+
std::vector<double> ref0({0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.});
375+
std::vector<double> ref1({0., 2., 4., 6., 8., 10.});
376+
std::vector<double> ref2({0., 5., 10.});
377+
std::vector<double> ref3({0., 5., 10.});
378+
379+
std::vector<std::vector<double>> ref = {ref0, ref1, ref2, ref3};
380+
381+
for (unsigned int idim = 0; idim < edges.size(); ++idim) {
382+
CheckBins(h1e->GetAxis(idim), edges[idim]);
383+
}
384+
for (unsigned int idim = 0; idim < edges.size(); ++idim) {
385+
CheckBins(h2e->GetAxis(idim), edges[idim]);
386+
}
387+
for (unsigned int idim = 0; idim < ref.size(); ++idim) {
388+
CheckBins(h1->GetAxis(idim), ref[idim]);
389+
}
390+
for (unsigned int idim = 0; idim < ref.size(); ++idim) {
391+
CheckBins(h2->GetAxis(idim), ref[idim]);
392+
}
393+
for (unsigned int idim = 0; idim < ref.size(); ++idim) {
394+
CheckBins(hm0->GetAxis(idim), ref[idim]);
395+
}
396+
for (unsigned int idim = 0; idim < ref.size(); ++idim) {
397+
CheckBins(hm0w->GetAxis(idim), ref[idim]);
398+
}
399+
}
400+
401+
402+
339403
TEST(RDataFrameHisto, FillVecBool)
340404
{
341405
const auto n = 10u;

tree/dataframe/test/dataframe_merge_results.cxx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,34 @@ TEST(RDataFrameMergeResults, MergeHistoND)
161161
EXPECT_EQ(mh.GetEntries(), 200);
162162
}
163163

164+
TEST(RDataFrameMergeResults, MergeHistoNSparseD)
165+
{
166+
ROOT::RDataFrame df{100};
167+
168+
auto col1 = df.Define("x0", [](ULong64_t e) { return double(e); }, {"rdfentry_"});
169+
auto col2 = col1.Define("x1", [](ULong64_t e) { return double(e); }, {"rdfentry_"});
170+
auto col3 = col2.Define("x2", [](ULong64_t e) { return double(e); }, {"rdfentry_"});
171+
auto col4 = col3.Define("x3", [](ULong64_t e) { return double(e); }, {"rdfentry_"});
172+
173+
int nbins[4] = {10, 10, 10, 10};
174+
double xmin[4] = {0., 0., 0., 0.};
175+
double xmax[4] = {100., 100., 100., 100.};
176+
auto hist1 =
177+
col4.HistoNSparseD<double, double, double, double>({"name", "title", 4, nbins, xmin, xmax}, {"x0", "x1", "x2", "x3"});
178+
auto hist2 =
179+
col4.HistoNSparseD<double, double, double, double>({"name", "title", 4, nbins, xmin, xmax}, {"x0", "x1", "x2", "x3"});
180+
181+
auto mh1 = GetMergeableValue(hist1);
182+
auto mh2 = GetMergeableValue(hist2);
183+
184+
auto mergedptr = MergeValues(std::move(mh1), std::move(mh2));
185+
186+
const auto &mh = mergedptr->GetValue();
187+
188+
EXPECT_EQ(mh.GetEntries(), 200);
189+
}
190+
191+
164192
TEST(RDataFrameMergeResults, MergeProfile1D)
165193
{
166194
ROOT::RDataFrame df{100};

tree/dataframe/test/dataframe_vary.cxx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,25 @@ TEST_P(RDFVary, VaryHistos)
13481348
res = hNs["x:1"].Projection(3);
13491349
EXPECT_DOUBLE_EQ(res->GetMean(), 5.);
13501350
delete res;
1351+
1352+
auto hNSparse = df.HistoNSparseD<ROOT::RVecI, ROOT::RVecI, ROOT::RVecI, ROOT::RVecI>({"", "", 4, nbins, xmin, xmax},
1353+
{"x", "x", "x", "x"});
1354+
auto hNSparses = VariationsFor(hNSparse);
1355+
1356+
auto res = hNSparse->Projection(3);
1357+
EXPECT_DOUBLE_EQ(res->GetMean(), 5.);
1358+
delete res;
1359+
res = hNSparses["nominal"].Projection(3);
1360+
EXPECT_DOUBLE_EQ(res->GetMean(), 5.);
1361+
delete res;
1362+
res = hNSparses["x:0"].Projection(3);
1363+
EXPECT_DOUBLE_EQ(res->GetMean(), 0.);
1364+
delete res;
1365+
res = hNSparses["x:1"].Projection(3);
1366+
EXPECT_DOUBLE_EQ(res->GetMean(), 5.);
1367+
delete res;
1368+
1369+
13511370
}
13521371

13531372
TEST_P(RDFVary, VaryMax)

0 commit comments

Comments
 (0)