16#include "./InternalHeaderCheck.h"
21template <
typename XprType_,
int BlockRows,
int BlockCols,
bool InnerPanel_>
22struct traits<Block<XprType_, BlockRows, BlockCols, InnerPanel_>> : traits<XprType_> {
23 using Scalar =
typename traits<XprType_>::Scalar;
24 using StorageKind =
typename traits<XprType_>::StorageKind;
25 using XprKind =
typename traits<XprType_>::XprKind;
26 using XprTypeNested =
typename ref_selector<XprType_>::type;
27 using XprTypeNested_ = std::remove_reference_t<XprTypeNested>;
29 MatrixRows = traits<XprType_>::RowsAtCompileTime,
30 MatrixCols = traits<XprType_>::ColsAtCompileTime,
31 RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
32 ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
33 MaxRowsAtCompileTime = BlockRows == 0 ? 0
34 : RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime)
35 : int(traits<XprType_>::MaxRowsAtCompileTime),
36 MaxColsAtCompileTime = BlockCols == 0 ? 0
37 : ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime)
38 : int(traits<XprType_>::MaxColsAtCompileTime),
40 XprTypeIsRowMajor = (int(traits<XprType_>::Flags) &
RowMajorBit) != 0,
41 IsRowMajor = (MaxRowsAtCompileTime == 1 && MaxColsAtCompileTime != 1) ? 1
42 : (MaxColsAtCompileTime == 1 && MaxRowsAtCompileTime != 1) ? 0
44 HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
45 InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
46 InnerStrideAtCompileTime = HasSameStorageOrderAsXprType ? int(inner_stride_at_compile_time<XprType_>::value)
47 : int(outer_stride_at_compile_time<XprType_>::value),
48 OuterStrideAtCompileTime = HasSameStorageOrderAsXprType ? int(outer_stride_at_compile_time<XprType_>::value)
49 : int(inner_stride_at_compile_time<XprType_>::value),
52 FlagsLvalueBit = is_lvalue<XprType_>::value ?
LvalueBit : 0,
62 InnerPanel = InnerPanel_ ? 1 : 0
66template <
typename XprType,
int BlockRows = Dynamic,
int BlockCols = Dynamic,
bool InnerPanel =
false,
67 bool HasDirectAccess = internal::has_direct_access<XprType>::value>
72template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
typename StorageKind>
109template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
111 :
public BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind> {
112 using Impl = BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind>;
113 using BlockHelper = internal::block_xpr_helper<Block>;
118 EIGEN_GENERIC_PUBLIC_INTERFACE(
Block)
119 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Block)
121 using NestedExpression = internal::remove_all_t<XprType>;
125 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
Block(XprType& xpr, Index i) : Impl(xpr, i) {
126 eigen_assert((i >= 0) && (((BlockRows == 1) && (BlockCols == XprType::ColsAtCompileTime) && i < xpr.rows()) ||
127 ((BlockRows == XprType::RowsAtCompileTime) && (BlockCols == 1) && i < xpr.cols())));
132 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
Block(XprType& xpr, Index startRow, Index startCol)
133 : Impl(xpr, startRow, startCol) {
134 EIGEN_STATIC_ASSERT(RowsAtCompileTime != Dynamic && ColsAtCompileTime != Dynamic,
135 THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
136 eigen_assert(startRow >= 0 && BlockRows >= 0 && startRow + BlockRows <= xpr.rows() && startCol >= 0 &&
137 BlockCols >= 0 && startCol + BlockCols <= xpr.cols());
142 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE
Block(XprType& xpr, Index startRow, Index startCol, Index blockRows,
144 : Impl(xpr, startRow, startCol, blockRows, blockCols) {
145 eigen_assert((RowsAtCompileTime == Dynamic || RowsAtCompileTime == blockRows) &&
146 (ColsAtCompileTime == Dynamic || ColsAtCompileTime == blockCols));
147 eigen_assert(startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows && startCol >= 0 &&
148 blockCols >= 0 && startCol <= xpr.cols() - blockCols);
153 static constexpr bool UnwoundInnerPanel = BlockHelper::is_inner_panel(
true);
157 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ConstUnwindReturnType unwind()
const {
158 return ConstUnwindReturnType(BlockHelper::base(*
this), BlockHelper::row(*
this, 0), BlockHelper::col(*
this, 0),
159 this->rows(), this->cols());
162 template <typename T = Block, typename EnableIf = std::enable_if_t<!std::is_const<T>::value>>
163 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE UnwindReturnType unwind() {
164 return UnwindReturnType(BlockHelper::base(*
this), BlockHelper::row(*
this, 0), BlockHelper::col(*
this, 0),
165 this->rows(), this->cols());
171template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
172class BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Dense>
173 :
public internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel> {
174 using Impl = internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel>;
175 using StorageIndex =
typename XprType::StorageIndex;
179 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl)
180 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index i) : Impl(xpr, i) {}
181 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index startRow, Index startCol)
182 : Impl(xpr, startRow, startCol) {}
183 EIGEN_DEVICE_FUNC
constexpr EIGEN_STRONG_INLINE BlockImpl(XprType& xpr, Index startRow, Index startCol,
184 Index blockRows, Index blockCols)
185 : Impl(xpr, startRow, startCol, blockRows, blockCols) {}
193template <
typename XprType,
int BlockRows,
int BlockCols>
194struct block_vector_start {
195 static constexpr Index row(Index i) {
return (BlockRows == 1) && (BlockCols == XprType::ColsAtCompileTime) ? i : 0; }
196 static constexpr Index col(Index i) {
return (BlockRows == XprType::RowsAtCompileTime) && (BlockCols == 1) ? i : 0; }
201template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
bool HasDirectAccess>
202class BlockImpl_dense :
public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel>>::type {
203 using BlockType = Block<XprType, BlockRows, BlockCols, InnerPanel>;
204 using XprTypeNested =
typename internal::ref_selector<XprType>::non_const_type;
205 using VectorStart = block_vector_start<XprType, BlockRows, BlockCols>;
208 using Base =
typename internal::dense_xpr_base<BlockType>::type;
209 EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
210 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
214 EIGEN_DEVICE_FUNC
constexpr BlockImpl_dense(XprType& xpr, Index i)
216 m_startRow(VectorStart::row(i)),
217 m_startCol(VectorStart::col(i)),
218 m_blockRows(BlockRows == 1 ? 1 : xpr.rows()),
219 m_blockCols(BlockCols == 1 ? 1 : xpr.cols()) {}
223 EIGEN_DEVICE_FUNC
constexpr BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
224 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol), m_blockRows(BlockRows), m_blockCols(BlockCols) {}
228 EIGEN_DEVICE_FUNC
constexpr BlockImpl_dense(XprType& xpr, Index startRow, Index startCol, Index blockRows,
230 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol), m_blockRows(blockRows), m_blockCols(blockCols) {}
232 EIGEN_DEVICE_FUNC
constexpr Index rows()
const {
return m_blockRows.value(); }
233 EIGEN_DEVICE_FUNC
constexpr Index cols()
const {
return m_blockCols.value(); }
235#ifdef EIGEN_PARSED_BY_DOXYGEN
237 EIGEN_DEVICE_FUNC
constexpr const Scalar* data()
const;
238 EIGEN_DEVICE_FUNC
inline Index innerStride()
const;
239 EIGEN_DEVICE_FUNC
inline Index outerStride()
const;
242 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const internal::remove_all_t<XprTypeNested>& nestedExpression()
const {
246 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE XprType& nestedExpression() {
return m_xpr; }
248 EIGEN_DEVICE_FUNC
constexpr StorageIndex startRow() const noexcept {
return m_startRow.value(); }
250 EIGEN_DEVICE_FUNC
constexpr StorageIndex startCol() const noexcept {
return m_startCol.value(); }
254 const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows == 1) ? 0 : Dynamic>
256 const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols == 1) ? 0 : Dynamic>
258 const internal::variable_if_dynamic<StorageIndex, RowsAtCompileTime> m_blockRows;
259 const internal::variable_if_dynamic<StorageIndex, ColsAtCompileTime> m_blockCols;
263template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
264class BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel, true>
265 :
public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel>> {
266 using BlockType = Block<XprType, BlockRows, BlockCols, InnerPanel>;
267 using XprTypeNested =
typename internal::ref_selector<XprType>::non_const_type;
268 using VectorStart = block_vector_start<XprType, BlockRows, BlockCols>;
272 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
static auto block_data(XprType& xpr, Index startRow, Index startCol,
273 Index blockRows, Index blockCols)
274 ->
decltype(xpr.data()) {
275 if (blockRows == 0 || blockCols == 0 || xpr.data() ==
nullptr) {
276 decltype(xpr.data()) data =
nullptr;
277#if EIGEN_GNUC_STRICT_AT_LEAST(13, 0, 0) && defined(__ARM_FEATURE_SVE2) && !defined(EIGEN_GPU_COMPILE_PHASE)
279 asm(
"" :
"+r"(data));
283 return xpr.data() + startRow * xpr.rowStride() + startCol * xpr.colStride();
287 using Base = MapBase<BlockType>;
288 EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
289 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
293 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl_dense(XprType& xpr, Index i)
294 : Base(block_data(xpr, VectorStart::row(i), VectorStart::col(i), BlockRows == 1 ? 1 : xpr.rows(),
295 BlockCols == 1 ? 1 : xpr.cols()),
296 BlockRows == 1 ? 1 : xpr.rows(), BlockCols == 1 ? 1 : xpr.cols()),
298 m_startRow(VectorStart::row(i)),
299 m_startCol(VectorStart::col(i)),
300 m_outerStride(outer_stride(xpr)) {}
304 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
305 : Base(block_data(xpr, startRow, startCol, BlockRows, BlockCols)),
307 m_startRow(startRow),
308 m_startCol(startCol),
309 m_outerStride(outer_stride(xpr)) {}
313 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl_dense(XprType& xpr, Index startRow, Index startCol, Index blockRows,
315 : Base(block_data(xpr, startRow, startCol, blockRows, blockCols), blockRows, blockCols),
317 m_startRow(startRow),
318 m_startCol(startCol),
319 m_outerStride(outer_stride(xpr)) {}
321 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const internal::remove_all_t<XprTypeNested>& nestedExpression() const noexcept {
325 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE XprType& nestedExpression() {
return m_xpr; }
328 EIGEN_DEVICE_FUNC
constexpr Index innerStride() const noexcept {
329 return internal::traits<BlockType>::HasSameStorageOrderAsXprType ? m_xpr.innerStride() : m_xpr.outerStride();
333 EIGEN_DEVICE_FUNC
constexpr Index outerStride() const noexcept {
return m_outerStride; }
335 EIGEN_DEVICE_FUNC
constexpr StorageIndex startRow() const noexcept {
return m_startRow.value(); }
337 EIGEN_DEVICE_FUNC
constexpr StorageIndex startCol() const noexcept {
return m_startCol.value(); }
340 EIGEN_DEVICE_FUNC
static constexpr Index outer_stride(
const XprType& xpr) {
341 return internal::traits<BlockType>::HasSameStorageOrderAsXprType ? xpr.outerStride() : xpr.innerStride();
345 const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows == 1) ? 0 : Dynamic>
347 const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols == 1) ? 0 : Dynamic>
Expression of a fixed-size or dynamic-size block.
Definition Block.h:111
constexpr Block(XprType &xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
Definition Block.h:142
constexpr Block(XprType &xpr, Index i)
Definition Block.h:125
constexpr Block(XprType &xpr, Index startRow, Index startCol)
Definition Block.h:132
constexpr unsigned int DirectAccessBit
Definition Constants.h:160
constexpr unsigned int LvalueBit
Definition Constants.h:149
constexpr unsigned int RowMajorBit
Definition Constants.h:71
constexpr unsigned int CompressedAccessBit
Definition Constants.h:196