| 29 | |
| 30 | template <typename _Scalar, int _Rows, int _Columns, int _Batches, int _Flags, typename _MatrixType> |
| 31 | class MatrixBlock : public CwiseOp<MatrixBlock<_Scalar, _Rows, _Columns, _Batches, _Flags, _MatrixType> > |
| 32 | { |
| 33 | public: |
| 34 | using Type = MatrixBlock<_Scalar, _Rows, _Columns, _Batches, _Flags, _MatrixType>; |
| 35 | using MatrixType = _MatrixType; |
| 36 | using Base = MatrixBase<MatrixBlock<_Scalar, _Rows, _Columns, _Batches, _Flags, _MatrixType> >; |
| 37 | CUMAT_PUBLIC_API |
| 38 | |
| 39 | protected: |
| 40 | |
| 41 | MatrixType matrix_; |
| 42 | const Index rows_; |
| 43 | const Index columns_; |
| 44 | const Index batches_; |
| 45 | const Index start_row_; |
| 46 | const Index start_column_; |
| 47 | const Index start_batch_; |
| 48 | |
| 49 | public: |
| 50 | MatrixBlock(MatrixType& matrix, Index rows, Index columns, Index batches, Index start_row, Index start_column, Index start_batch) |
| 51 | : matrix_(matrix) |
| 52 | , rows_(rows) |
| 53 | , columns_(columns) |
| 54 | , batches_(batches) |
| 55 | , start_row_(start_row) |
| 56 | , start_column_(start_column) |
| 57 | , start_batch_(start_batch) |
| 58 | {} |
| 59 | |
| 60 | /** |
| 61 | * \brief Returns the number of rows of this matrix. |
| 62 | * \return the number of rows |
| 63 | */ |
| 64 | __host__ __device__ CUMAT_STRONG_INLINE Index rows() const { return rows_; } |
| 65 | |
| 66 | /** |
| 67 | * \brief Returns the number of columns of this matrix. |
| 68 | * \return the number of columns |
| 69 | */ |
| 70 | __host__ __device__ CUMAT_STRONG_INLINE Index cols() const { return columns_; } |
| 71 | |
| 72 | /** |
| 73 | * \brief Returns the number of batches of this matrix. |
| 74 | * \return the number of batches |
| 75 | */ |
| 76 | __host__ __device__ CUMAT_STRONG_INLINE Index batches() const { return batches_; } |
| 77 | |
| 78 | /** |
| 79 | * \brief Converts from the linear index back to row, column and batch index |
| 80 | * \param index the linear index |
| 81 | * \param row the row index (output) |
| 82 | * \param col the column index (output) |
| 83 | * \param batch the batch index (output) |
| 84 | */ |
| 85 | __host__ __device__ CUMAT_STRONG_INLINE void index(Index index, Index& row, Index& col, Index& batch) const |
| 86 | { |
| 87 | if (CUMAT_IS_ROW_MAJOR(Flags)) { |
| 88 | batch = index / (rows() * cols()); |