Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-16 09:21:06

0001 #ifndef ROOT_INTERNAL_ML_RFLAT2DMATRIX
0002 #define ROOT_INTERNAL_ML_RFLAT2DMATRIX
0003 
0004 #include <cassert>
0005 #include <utility>
0006 
0007 #include "ROOT/RVec.hxx"
0008 
0009 namespace ROOT::Experimental::Internal::ML {
0010 /// \brief Wrapper around ROOT::RVec<float> representing a 2D matrix
0011 ///
0012 /// The storage is flattened row-major: index(row, col) == row * cols + col.
0013 struct RFlat2DMatrix {
0014    ROOT::RVecF fRVec;
0015    std::size_t fRows{0};
0016    std::size_t fCols{0};
0017 
0018    RFlat2DMatrix() = default;
0019 
0020    RFlat2DMatrix(std::size_t rows, std::size_t cols) { Resize(rows, cols); }
0021 
0022    float *GetData() { return fRVec.data(); }
0023 
0024    const float *GetData() const { return fRVec.data(); }
0025 
0026    // Used in the pythonization
0027    std::pair<std::size_t, std::size_t> GetShape() const { return {fRows, fCols}; }
0028 
0029    std::size_t GetRows() const { return fRows; }
0030 
0031    std::size_t GetCols() const { return fCols; }
0032 
0033    std::size_t GetSize() const { return fRVec.size(); }
0034 
0035    void Resize(std::size_t rows, std::size_t cols)
0036    {
0037       fRows = rows;
0038       fCols = cols;
0039       fRVec.resize(rows * cols);
0040    }
0041 
0042    void Reshape(std::size_t rows, std::size_t cols)
0043    {
0044       // We don't reallocate: require matching sizes
0045       assert(rows * cols == fRVec.size());
0046       fRows = rows;
0047       fCols = cols;
0048    }
0049 
0050    float &operator[](std::size_t i) { return fRVec[i]; }
0051 
0052    const float &operator[](std::size_t i) const { return fRVec[i]; }
0053 };
0054 
0055 } // namespace ROOT::Experimental::Internal::ML
0056 #endif // ROOT_INTERNAL_ML_RFLAT2DMATRIX