Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tmva001_RTensor.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_tmva
3/// \notebook -nodraw
4/// This tutorial illustrates the basic features of the RTensor class,
5/// RTensor is a std::vector-like container with additional shape information.
6/// The class serves as an interface in C++ between multi-dimensional data and
7/// the algorithm such as in machine learning workflows. The interface is similar
8/// to Numpy arrays and provides a subset of the functionality.
9///
10/// \macro_code
11/// \macro_output
12///
13/// \date December 2018
14/// \author Stefan Wunsch
15
16using namespace TMVA::Experimental;
17
18void tmva001_RTensor()
19{
20 // Create RTensor from scratch
21 RTensor<float> x({2, 2});
22 cout << x << endl;
23
24 // Assign some data
25 x(0, 0) = 1;
26 x(0, 1) = 2;
27 x(1, 0) = 3;
28 x(1, 1) = 4;
29
30 // Apply transformations
31 auto x2 = x.Reshape({1, 4}).Squeeze();
32 cout << x2 << endl;
33
34 // Slice
35 auto x3 = x.Reshape({2, 2}).Slice({{0, 2}, {0, 1}});
36 cout << x3 << endl;
37
38 // Create tensor as view on data without ownership
39 float data[] = {5, 6, 7, 8};
40 RTensor<float> y(data, {2, 2});
41 cout << y << endl;
42
43 // Create tensor as view on data with ownership
44 auto data2 = std::make_shared<std::vector<float>>(4);
45 float c = 9;
46 for (auto &v : *data2) {
47 v = c;
48 c++;
49 }
50
51 RTensor<float> z(data2, {2, 2});
52 cout << z << endl;
53}
#define c(i)
Definition RSha256.hxx:101
static const double x3[11]
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char x2
RTensor is a container with contiguous memory and shape information.
Definition RTensor.hxx:162
RooCmdArg Slice(const RooArgSet &sliceSet)
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17