Logo ROOT  
Reference Guide
tmva001_RTensor.C File Reference

Detailed Description

View in nbviewer Open in SWAN This tutorial illustrates the basic features of the RTensor class, RTensor is a std::vector-like container with additional shape information. The class serves as an interface in C++ between multi-dimensional data and the algorithm such as in machine learning workflows. The interface is similar to Numpy arrays and provides a subset of the functionality.

using namespace TMVA::Experimental;
void tmva001_RTensor()
{
// Create RTensor from scratch
RTensor<float> x({2, 2});
cout << x << endl;
// Assign some data
x(0, 0) = 1;
x(0, 1) = 2;
x(1, 0) = 3;
x(1, 1) = 4;
// Apply transformations
auto x2 = x.Reshape({1, 4}).Squeeze();
cout << x2 << endl;
// Slice
auto x3 = x.Reshape({2, 2}).Slice({{0, 2}, {0, 1}});
cout << x3 << endl;
// Create tensor as view on data without ownership
float data[] = {5, 6, 7, 8};
RTensor<float> y(data, {2, 2});
cout << y << endl;
// Create tensor as view on data with ownership
auto data2 = std::make_shared<std::vector<float>>(4);
float c = 9;
for (auto &v : *data2) {
v = c;
c++;
}
RTensor<float> z(data2, {2, 2});
cout << z << endl;
}
{ { 0, 0 } { 0, 0 } }
{ 1, 2, 3, 4 }
{ 1, 3 }
{ { 5, 6 } { 7, 8 } }
{ { 9, 10 } { 11, 12 } }
Date
December 2018
Author
Stefan Wunsch

Definition in file tmva001_RTensor.C.

c
#define c(i)
Definition: RSha256.hxx:119
TMVA::Experimental::RTensor
RTensor is a container with contiguous memory and shape information.
Definition: RTensor.hxx:162
x
Double_t x[n]
Definition: legend1.C:17
v
@ v
Definition: rootcling_impl.cxx:3635
RooFit::Slice
RooCmdArg Slice(const RooArgSet &sliceSet)
Definition: RooGlobalFunc.cxx:39
x3
static const double x3[11]
Definition: RooGaussKronrodIntegrator1D.cxx:392
y
Double_t y[n]
Definition: legend1.C:17
TMVA::Experimental
Definition: Classification.h:127
x2
static const double x2[5]
Definition: RooGaussKronrodIntegrator1D.cxx:364