Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RFlat2DMatrix.hxx
Go to the documentation of this file.
1#ifndef ROOT_INTERNAL_ML_RFLAT2DMATRIX
2#define ROOT_INTERNAL_ML_RFLAT2DMATRIX
3
4#include <cassert>
5#include <utility>
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
27 {
28 fRows = 0;
29 fCols = 0;
30 return std::move(fRVec);
31 }
32
33 // Used in the pythonization
34 std::pair<std::size_t, std::size_t> GetShape() const { return {fRows, fCols}; }
35
36 std::size_t GetRows() const { return fRows; }
37
38 std::size_t GetCols() const { return fCols; }
39
40 std::size_t GetSize() const { return fRVec.size(); }
41
42 void Resize(std::size_t rows, std::size_t cols)
43 {
44 fRows = rows;
45 fCols = cols;
47 }
48
49 void Reshape(std::size_t rows, std::size_t cols)
50 {
51 // We don't reallocate: require matching sizes
52 assert(rows * cols == fRVec.size());
53 fRows = rows;
54 fCols = cols;
55 }
56
57 float &operator[](std::size_t i) { return fRVec[i]; }
58
59 const float &operator[](std::size_t i) const { return fRVec[i]; }
60};
61
62} // namespace ROOT::Experimental::Internal::ML
63#endif // ROOT_INTERNAL_ML_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:577
pointer data() noexcept
Return a pointer to the vector's buffer, even if empty().
Definition RVec.hxx:277
Wrapper around ROOT::RVec<float> representing a 2D matrix.
void Resize(std::size_t rows, std::size_t cols)
const float & operator[](std::size_t i) const
void Reshape(std::size_t rows, std::size_t cols)
std::pair< std::size_t, std::size_t > GetShape() const
RFlat2DMatrix(std::size_t rows, std::size_t cols)