Skip to content

Commit

Permalink
[DF] Reduce duration of "simple" unit test
Browse files Browse the repository at this point in the history
by a factor ~2x (100s -> 50s)by eliminating jitting in favor of
fully compiled RDF instances where possible, i.e. w/o reducing
test coverage.
  • Loading branch information
dpiparo committed Sep 11, 2023
1 parent d4f699a commit 88d11e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tree/dataframe/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ROOT_ADD_GTEST(dataframe_redefine dataframe_redefine.cxx LIBRARIES ROOTDataFrame
ROOT_ADD_GTEST(dataframe_definepersample dataframe_definepersample.cxx LIBRARIES ROOTDataFrame)

if(NOT MSVC OR win_broken_tests)
ROOT_ADD_GTEST(dataframe_simple dataframe_simple.cxx LIBRARIES ROOTDataFrame)
ROOT_ADD_GTEST(dataframe_simple dataframe_simple.cxx LIBRARIES ROOTDataFrame GenVector)
target_include_directories(dataframe_simple PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
ROOT_GENERATE_DICTIONARY(DataFrameSimpleDict ${CMAKE_CURRENT_SOURCE_DIR}/MaxSlotHelper.h ${CMAKE_CURRENT_SOURCE_DIR}/SimpleFiller.h MODULE dataframe_simple
LINKDEF DataFrameSimpleLinkDef.h OPTIONS -inlineInputHeader DEPENDENCIES ROOTDataFrame Hist)
Expand Down
53 changes: 31 additions & 22 deletions tree/dataframe/test/dataframe_simple.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <TFile.h>
#include <TGraph.h>
#include <TInterpreter.h>
#include <Math/Vector4D.h>
#include <TRandom.h>
#include <TROOT.h>
#include <TSystem.h>
Expand Down Expand Up @@ -102,7 +103,7 @@ TEST_P(RDFSimpleTests, CreateZeroEntriesWithBranches)
}
RDataFrame tdf(treename, filename);
auto c = tdf.Count();
auto m = tdf.Mean("b1");
auto m = tdf.Mean<double>("b1");
EXPECT_EQ(0U, *c);
EXPECT_DOUBLE_EQ(0., *m);
}
Expand Down Expand Up @@ -148,7 +149,7 @@ TEST_P(RDFSimpleTests, Define_lambda)
{
RDataFrame tdf(10);
auto d = tdf.Define("i", []() { return 1; });
auto m = d.Mean("i");
auto m = d.Mean<int>("i");
EXPECT_DOUBLE_EQ(1., *m);
}

Expand All @@ -161,7 +162,7 @@ TEST_P(RDFSimpleTests, Define_function)
{
RDataFrame tdf(10);
auto d = tdf.Define("i", DefineFunction);
auto m = d.Mean("i");
auto m = d.Mean<int>("i");
EXPECT_DOUBLE_EQ(1., *m);
}

Expand All @@ -174,7 +175,7 @@ TEST_P(RDFSimpleTests, Define_functor)
RDataFrame tdf(10);
DefineStruct def;
auto d = tdf.Define("i", def);
auto m = d.Mean("i");
auto m = d.Mean<int>("i");
EXPECT_DOUBLE_EQ(1., *m);
}

Expand Down Expand Up @@ -343,7 +344,7 @@ TEST_P(RDFSimpleTests, Define_jitted_Filter_complex_array)
TEST_P(RDFSimpleTests, DefineSlotConsistency)
{
RDataFrame df(8);
auto m = df.DefineSlot("x", [](unsigned int) { return 1.; }).Max("x");
auto m = df.DefineSlot("x", [](unsigned int) { return 1.; }).Max<double>("x");
EXPECT_DOUBLE_EQ(1., *m);
}

Expand All @@ -354,7 +355,7 @@ TEST_P(RDFSimpleTests, DefineSlot)
values[i] = i;
RDataFrame df(NSLOTS);
auto ddf = df.DefineSlot("s", [values](unsigned int slot) { return values[slot]; });
auto m = ddf.Max("s");
auto m = ddf.Max<int>("s");
EXPECT_EQ(*m, NSLOTS - 1); // no matter the order of processing, the higher slot number is always taken at least once
}

Expand Down Expand Up @@ -436,11 +437,11 @@ TEST_P(RDFSimpleTests, GetNRuns)
RDataFrame df(3);
EXPECT_EQ(df.GetNRuns(), 0u);

auto sum1 = df.Sum("rdfentry_");
auto sum1 = df.Sum<ULong64_t>("rdfentry_");
sum1.GetValue();
EXPECT_EQ(df.GetNRuns(), 1u);

auto sum2 = df.Sum("rdfentry_");
auto sum2 = df.Sum<ULong64_t>("rdfentry_");
sum2.GetValue();
EXPECT_EQ(df.GetNRuns(), 2u);
}
Expand Down Expand Up @@ -665,7 +666,7 @@ class StdDevTestHelper {
ROOT::RDataFrame d(samples.size());
return *d.DefineSlotEntry("x", [this](unsigned int /*slot*/, ULong64_t entry) {
return samples[entry];
}).StdDev("x");
}).StdDev<double>("x");
}
};

Expand Down Expand Up @@ -715,21 +716,21 @@ TEST_P(RDFSimpleTests, StandardDeviationCollections)
TEST_P(RDFSimpleTests, StandardDeviationZero)
{
RDataFrame rd1(8);
auto stdDev = rd1.Define("b1", []() { return 0; }).StdDev("b1");
auto stdDev = rd1.Define("b1", []() { return 0; }).StdDev<int>("b1");
EXPECT_DOUBLE_EQ(*stdDev, 0);
}

TEST_P(RDFSimpleTests, StandardDeviationOne)
{
RDataFrame rd1(1);
auto stdDev = rd1.Define("b1", []() { return 1; }).StdDev("b1");
auto stdDev = rd1.Define("b1", []() { return 1; }).StdDev<int>("b1");
EXPECT_DOUBLE_EQ(*stdDev, 0);
}

TEST_P(RDFSimpleTests, StandardDeviationEmpty)
{
RDataFrame rd1(0);
auto stdDev = rd1.Define("b1", []() { return 0; }).StdDev("b1");
auto stdDev = rd1.Define("b1", []() { return 0; }).StdDev<int>("b1");
EXPECT_DOUBLE_EQ(*stdDev, 0);
}

Expand All @@ -743,11 +744,17 @@ TEST(RDFSimpleTests, SumOfStrings)
}
*/

template <typename T>
T KahanHelper(ULong64_t i)
{
return T(i + 1);
}

TEST_P(RDFSimpleTests, KahanSum_Double)
{
constexpr std::uint64_t N = 1e7;
ROOT::RDataFrame d(N);
auto df = d.Define("x", "double(rdfentry_ +1)");
auto df = d.Define("x", KahanHelper<double>, {"rdfentry_"});
double true_sum = (N + 1.0) / 2.0;
EXPECT_DOUBLE_EQ(*df.Sum<double>({"x"}) / N, true_sum);
}
Expand All @@ -756,7 +763,7 @@ TEST_P(RDFSimpleTests, KahanSum_Float)
{
constexpr std::uint64_t N = 1e7;
ROOT::RDataFrame d(N);
auto df = d.Define("x", "float(rdfentry_ +1)");
auto df = d.Define("x", KahanHelper<float>, {"rdfentry_"});
float true_sum = (N + 1.0) / 2.0;
EXPECT_FLOAT_EQ(*df.Sum<float>({"x"}) / N, true_sum);
}
Expand All @@ -765,7 +772,7 @@ TEST_P(RDFSimpleTests, KahanMean_Double)
{
constexpr std::uint64_t N = 1e7;
ROOT::RDataFrame d(N);
auto df = d.Define("x", "double(rdfentry_ +1)");
auto df = d.Define("x", KahanHelper<double>, {"rdfentry_"});
double true_sum = (N + 1.0) / 2.0;
EXPECT_DOUBLE_EQ(*df.Mean<double>({"x"}), true_sum);
}
Expand All @@ -774,27 +781,29 @@ TEST_P(RDFSimpleTests, KahanMean_Float)
{
constexpr std::uint64_t N = 1e7;
ROOT::RDataFrame d(N);
auto df = d.Define("x", "float(rdfentry_ +1)");
auto df = d.Define("x", KahanHelper<float>, {"rdfentry_"});
float true_sum = (N + 1.0) / 2.0;
EXPECT_FLOAT_EQ(*df.Mean<float>({"x"}), true_sum);
}

TEST(RDFSimpleTests, GenVector)
{
// The leading underscore of "_hh" tests against ROOT-10305.
using MVector = ROOT::Math::PtEtaPhiMVector;
ROOT::RDataFrame t(1);
auto aa = t.Define("_hh", "ROOT::Math::PtEtaPhiMVector(1,1,1,1)").Define("h", "_hh.Rapidity()");
auto m = aa.Mean("h");
auto aa = t.Define("_hh", []() { return MVector(1, 1, 1, 1); })
.Define("h", [](MVector &v) { return v.Rapidity(); }, {"_hh"});
auto m = aa.Mean<double>("h");
EXPECT_TRUE(0 != *m);
}

TEST(RDFSimpleTests, AutomaticNamesOfHisto1DAndGraph)
{
auto df = RDataFrame(1).Define("x", [](){return 1;})
.Define("y", [](){return 1;});
auto hx = df.Histo1D("x");
auto hxy = df.Histo1D("x", "y");
auto gxy = df.Graph("x", "y");
auto hx = df.Histo1D<int>("x");
auto hxy = df.Histo1D<int, int>("x", "y");
auto gxy = df.Graph<int, int>("x", "y");

EXPECT_STREQ(hx->GetName(), "x");
EXPECT_STREQ(hx->GetTitle(), "x");
Expand Down Expand Up @@ -1003,7 +1012,7 @@ TEST_P(RDFSimpleTests, ChainWithDifferentTreeNames)

// pass chain to RDF and process trees with different names
ROOT::RDataFrame df2(c);
EXPECT_DOUBLE_EQ(*df2.Mean("x"), 2);
EXPECT_DOUBLE_EQ(*df2.Mean<int>("x"), 2);

gSystem->Unlink(fname1);
gSystem->Unlink(fname2);
Expand Down

0 comments on commit 88d11e4

Please sign in to comment.