Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
tmva002_RDataFrameAsTensor.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_tmva
3 /// \notebook -nodraw
4 /// This tutorial shows how the content of an RDataFrame can be converted to an
5 /// RTensor object.
6 ///
7 /// \macro_code
8 /// \macro_output
9 ///
10 /// \date December 2018
11 /// \author Stefan Wunsch
12 
13 using namespace TMVA::Experimental;
14 
15 void tmva002_RDataFrameAsTensor()
16 {
17  // Creation of an RDataFrame with five entries filled with ascending numbers
18  ROOT::RDataFrame df(5);
19  auto df2 = df.Define("x", "1.f*rdfentry_").Define("y", "-1.f*rdfentry_");
20 
21  // Convert content of columns to an RTensor object
22  auto x = AsTensor<float>(df2);
23 
24  std::cout << "RTensor from an RDataFrame:\n" << x << "\n\n";
25 
26  // The utility also supports reading only a part of the RDataFrame and different
27  // memory layouts.
28  auto x2 = AsTensor<float>(df2, {"x"}, MemoryLayout::ColumnMajor);
29 
30  std::cout << "RTensor from a single column of the RDataFrame:\n" << x2 << "\n\n";
31 }