Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFlat2DMatrix.hxx
Go to the documentation of this file.
1#ifndef ROOT_TMVA_RFLAT2DMATRIX
2#define ROOT_TMVA_RFLAT2DMATRIX
3
4#include <utility>
5#include <cassert>
6
7#include "ROOT/RVec.hxx"
8
10/// \brief Wrapper around ROOT::RVec<float> representing a 2D matrix
11///
12/// The storage is flattened row-major: index(row, col) == row * cols + col.
15 std::size_t fRows{0};
16 std::size_t fCols{0};
17
18 RFlat2DMatrix() = default;
19
20 RFlat2DMatrix(std::size_t rows, std::size_t cols) { Resize(rows, cols); }
21
22 float *GetData() { return fRVec.data(); }
23
24 const float *GetData() const { return fRVec.data(); }
25
26 // Used in the pythonization
27 std::pair<std::size_t, std::size_t> GetShape() const { return {fRows, fCols}; }
28
29 std::size_t GetRows() const { return fRows; }
30
31 std::size_t GetCols() const { return fCols; }
32
33 std::size_t GetSize() const { return fRVec.size(); }
34
35 void Resize(std::size_t rows, std::size_t cols)
36 {
37 fRows = rows;
38 fCols = cols;
40 }
41
42 void Reshape(std::size_t rows, std::size_t cols)
43 {
44 // We don't reallocate: require matching sizes
45 assert(rows * cols == fRVec.size());
46 fRows = rows;
47 fCols = cols;
48 }
49
50 float &operator[](std::size_t i) { return fRVec[i]; }
51
52 const float &operator[](std::size_t i) const { return fRVec[i]; }
53};
54
55} // namespace TMVA::Experimental::Internal
56#endif // ROOT_TMVA_RFLAT2DMATRIX
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void resize(size_type N)
Definition RVec.hxx:593
pointer data() noexcept
Return a pointer to the vector's buffer, even if empty().
Definition RVec.hxx:282
Wrapper around ROOT::RVec<float> representing a 2D matrix.
void Reshape(std::size_t rows, std::size_t cols)
const float & operator[](std::size_t i) const
std::pair< std::size_t, std::size_t > GetShape() const
void Resize(std::size_t rows, std::size_t cols)
RFlat2DMatrix(std::size_t rows, std::size_t cols)