ROOT
git-r3/HEAD
Reference Guide
Loading...
Searching...
No Matches
tmva001_RTensor.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_ml
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
16
using namespace
TMVA::Experimental
;
17
18
void
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
}
c
#define c(i)
Definition
RSha256.hxx:101
RTensor
RTensor is a container with contiguous memory and shape information.
Definition
RTensor.hxx:163
y
Double_t y[n]
Definition
legend1.C:17
x
Double_t x[n]
Definition
legend1.C:17
ROOT::Internal::Slice
T Slice(const T &histo, std::vector< Int_t > &args)
Creates a sliced copy of the given histogram.
Definition
TH1.h:75
TMVA::Experimental::SOFIE::Squeeze
@ Squeeze
Definition
ROperator_Reshape.hxx:17
TMVA::Experimental
Definition
RFunction.hxx:11
hist015_TH1_read_and_draw_uhi.z
z
Definition
hist015_TH1_read_and_draw_uhi.py:56
rf503_wspaceread.data
data
Definition
rf503_wspaceread.py:37
v
@ v
Definition
rootcling_impl.cxx:3554
tutorials
machine_learning
tmva001_RTensor.C
ROOTgit-r3/HEAD - Reference Guide Generated on
(GVA Time) using Doxygen 1.16.1