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
10
12
13std::vector<std::size_t> RFlat2DMatrixOperators::MakePermutation(std::size_t rows)
14{
15 if (!fShuffle) {
16 return {};
17 }
18
19 // make an identity permutation map
20 std::vector<std::size_t> indices(rows);
21 std::iota(indices.begin(), indices.end(), 0);
22
23 // shuffle the identity permutation to create a new permutation
25
26 return indices;
27}
28
29void RFlat2DMatrixOperators::ShuffleIndices(std::vector<std::size_t> &indices)
30{
31 if (!fShuffle) {
32 return;
33 }
34
35 std::random_device rd;
36 std::mt19937 g;
37
38 if (fSetSeed == 0) {
39 g.seed(rd());
40 } else {
41 g.seed(fSetSeed);
42 }
43
44 std::shuffle(indices.begin(), indices.end(), g);
45}
46
48 const std::vector<std::size_t> &permutation, std::size_t begin, std::size_t end)
49{
50 if (begin == end) {
51 return;
52 }
53
54 const std::size_t cols = Tensor.GetCols();
55 const float *data = Tensor.GetData();
56 auto &values = Dest.fRVec;
57
58 // grow once and copy the rows in place, cheaper than inserting them one by one
59 const std::size_t offset = values.size();
60 values.resize(offset + (end - begin) * cols);
61 float *out = values.data() + offset;
62
63 if (permutation.empty()) {
64 std::copy(data + begin * cols, data + end * cols, out);
65 } else {
66 for (std::size_t i = begin; i < end; i++) {
67 out = std::copy_n(data + permutation[i] * cols, cols, out);
68 }
69 }
70
71 Dest.Reshape(values.size() / cols, cols);
72}
73
74} // namespace ROOT::Experimental::Internal::ML
#define g(i)
Definition RSha256.hxx:105
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 GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
std::vector< std::size_t > MakePermutation(std::size_t rows)
static void AppendRows(RFlat2DMatrix &Dest, const RFlat2DMatrix &Tensor, const std::vector< std::size_t > &permutation, std::size_t begin, std::size_t end)
Wrapper around ROOT::RVec<float> representing a 2D matrix.
void Reshape(std::size_t rows, std::size_t cols)