Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFlat2DMatrixOperators.cxx
Go to the documentation of this file.
2
3#include <algorithm>
4#include <numeric>
5#include <random>
6
8#include "Rtypes.h"
9
11
13
15{
16 if (fShuffle) {
17 std::random_device rd;
18 std::mt19937 g;
19
20 if (fSetSeed == 0) {
21 g.seed(rd());
22 } else {
23 g.seed(fSetSeed);
24 }
25
26 std::size_t rows = Tensor.GetRows();
27 std::size_t cols = Tensor.GetCols();
28 ShuffledTensor.Resize(rows, cols);
29
30 // make an identity permutation map
31 std::vector<Long_t> indices(rows);
32 std::iota(indices.begin(), indices.end(), 0);
33
34 // shuffle the identity permutation to create a new permutation
35 std::shuffle(indices.begin(), indices.end(), g);
36
37 // shuffle data in the tensor with the permutation map defined above
38 for (std::size_t i = 0; i < rows; i++) {
39 std::copy(Tensor.GetData() + indices[i] * cols, Tensor.GetData() + (indices[i] + 1) * cols,
40 ShuffledTensor.GetData() + i * cols);
41 }
42 } else {
44 }
45}
46
48 const std::vector<std::vector<std::size_t>> &slice)
49{
50 const auto &rowSlice = slice[0];
51 const auto &colSlice = slice[1];
52
53 std::size_t rowStart = rowSlice[0];
54 std::size_t rowEnd = rowSlice[1];
55 std::size_t colStart = colSlice[0];
56 std::size_t colEnd = colSlice[1];
57
58 std::size_t rows = rowEnd - rowStart;
59 std::size_t cols = colEnd - colStart;
60
61 SlicedTensor.Resize(rows, cols);
62 std::copy(Tensor.GetData() + rowStart * cols, Tensor.GetData() + rowStart * cols + rows * cols,
63 SlicedTensor.GetData());
64}
65
67{
68 std::size_t cols = Tensors[0].GetCols();
69 std::size_t rows = 0;
70
71 for (const auto &t : Tensors) {
72 rows += t.GetRows();
73 }
74
75 ConcatTensor.Resize(rows, cols);
76
77 std::size_t index = 0;
78 for (std::size_t i = 0; i < Tensors.size(); i++) {
79 std::size_t tensorRows = Tensors[i].GetRows();
80 std::copy(Tensors[i].GetData(), Tensors[i].GetData() + tensorRows * cols, ConcatTensor.GetData() + index * cols);
82 }
83}
84} // namespace ROOT::Experimental::Internal::ML
#define g(i)
Definition RSha256.hxx:105
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
void SliceTensor(RFlat2DMatrix &SlicedTensor, RFlat2DMatrix &Tensor, const std::vector< std::vector< std::size_t > > &slice)
void ConcatenateTensors(RFlat2DMatrix &ConcatTensor, const std::vector< RFlat2DMatrix > &Tensors)
void ShuffleTensor(RFlat2DMatrix &ShuffledTensor, RFlat2DMatrix &Tensor)
Wrapper around ROOT::RVec<float> representing a 2D matrix.