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) {}
191template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
bool HasDirectAccess>
192class BlockImpl_dense :
public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel>>::type {
193 using BlockType = Block<XprType, BlockRows, BlockCols, InnerPanel>;
194 using XprTypeNested =
typename internal::ref_selector<XprType>::non_const_type;
197 using Base =
typename internal::dense_xpr_base<BlockType>::type;
198 EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
199 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
203 EIGEN_DEVICE_FUNC
constexpr BlockImpl_dense(XprType& xpr, Index i)
209 m_startRow((BlockRows == 1) && (BlockCols == XprType::ColsAtCompileTime) ? i : 0),
210 m_startCol((BlockRows == XprType::RowsAtCompileTime) && (BlockCols == 1) ? i : 0),
211 m_blockRows(BlockRows == 1 ? 1 : xpr.rows()),
212 m_blockCols(BlockCols == 1 ? 1 : xpr.cols()) {}
216 EIGEN_DEVICE_FUNC
constexpr BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
217 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol), m_blockRows(BlockRows), m_blockCols(BlockCols) {}
221 EIGEN_DEVICE_FUNC
constexpr BlockImpl_dense(XprType& xpr, Index startRow, Index startCol, Index blockRows,
223 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol), m_blockRows(blockRows), m_blockCols(blockCols) {}
225 EIGEN_DEVICE_FUNC
constexpr Index rows()
const {
return m_blockRows.value(); }
226 EIGEN_DEVICE_FUNC
constexpr Index cols()
const {
return m_blockCols.value(); }
228 EIGEN_DEVICE_FUNC
inline Scalar& coeffRef(Index rowId, Index colId) {
229 EIGEN_STATIC_ASSERT_LVALUE(XprType)
230 return m_xpr.coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
233 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(Index rowId, Index colId)
const {
234 return m_xpr.derived().coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
237 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const CoeffReturnType coeff(Index rowId, Index colId)
const {
238 return m_xpr.coeff(rowId + m_startRow.value(), colId + m_startCol.value());
241 EIGEN_DEVICE_FUNC
inline Scalar& coeffRef(Index index) {
242 EIGEN_STATIC_ASSERT_LVALUE(XprType)
243 return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
244 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
247 EIGEN_DEVICE_FUNC
inline const Scalar& coeffRef(Index index)
const {
248 return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
249 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
252 EIGEN_DEVICE_FUNC
inline const CoeffReturnType coeff(Index index)
const {
253 return m_xpr.coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
254 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
257 template <
int LoadMode>
258 EIGEN_DEVICE_FUNC
inline PacketScalar packet(Index rowId, Index colId)
const {
259 return m_xpr.template packet<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value());
262 template <
int LoadMode>
263 EIGEN_DEVICE_FUNC
inline void writePacket(Index rowId, Index colId,
const PacketScalar& val) {
264 m_xpr.template writePacket<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value(), val);
267 template <
int LoadMode>
268 EIGEN_DEVICE_FUNC
inline PacketScalar packet(Index index)
const {
269 return m_xpr.template packet<Unaligned>(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
270 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
273 template <
int LoadMode>
274 EIGEN_DEVICE_FUNC
inline void writePacket(Index index,
const PacketScalar& val) {
275 m_xpr.template writePacket<Unaligned>(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
276 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), val);
279#ifdef EIGEN_PARSED_BY_DOXYGEN
281 EIGEN_DEVICE_FUNC
constexpr const Scalar* data()
const;
282 EIGEN_DEVICE_FUNC
inline Index innerStride()
const;
283 EIGEN_DEVICE_FUNC
inline Index outerStride()
const;
286 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const internal::remove_all_t<XprTypeNested>& nestedExpression()
const {
290 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE XprType& nestedExpression() {
return m_xpr; }
292 EIGEN_DEVICE_FUNC
constexpr StorageIndex startRow() const noexcept {
return m_startRow.value(); }
294 EIGEN_DEVICE_FUNC
constexpr StorageIndex startCol() const noexcept {
return m_startCol.value(); }
298 const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows == 1) ? 0 : Dynamic>
300 const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols == 1) ? 0 : Dynamic>
302 const internal::variable_if_dynamic<StorageIndex, RowsAtCompileTime> m_blockRows;
303 const internal::variable_if_dynamic<StorageIndex, ColsAtCompileTime> m_blockCols;
307template <
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
308class BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel, true>
309 :
public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel>> {
310 using BlockType = Block<XprType, BlockRows, BlockCols, InnerPanel>;
311 using XprTypeNested =
typename internal::ref_selector<XprType>::non_const_type;
312 enum { XprTypeIsRowMajor = (int(traits<XprType>::Flags) &
RowMajorBit) != 0 };
317 template <
typename Scalar>
318 EIGEN_DEVICE_FUNC
constexpr EIGEN_ALWAYS_INLINE
static Scalar* add_to_nullable_pointer(Scalar* base, Index offset) {
319 return base !=
nullptr ? base + offset :
nullptr;
323 using Base = MapBase<BlockType>;
324 EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
325 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
329 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl_dense(XprType& xpr, Index i)
330 : Base((BlockRows == 0 || BlockCols == 0)
332 : add_to_nullable_pointer(
334 i * (((BlockRows == 1) && (BlockCols == XprType::ColsAtCompileTime) && (!XprTypeIsRowMajor)) ||
335 ((BlockRows == XprType::RowsAtCompileTime) && (BlockCols == 1) &&
338 : xpr.outerStride())),
339 BlockRows == 1 ? 1 : xpr.rows(), BlockCols == 1 ? 1 : xpr.cols()),
341 m_startRow((BlockRows == 1) && (BlockCols == XprType::ColsAtCompileTime) ? i : 0),
342 m_startCol((BlockRows == XprType::RowsAtCompileTime) && (BlockCols == 1) ? i : 0) {
348 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
349 : Base((BlockRows == 0 || BlockCols == 0)
351 : add_to_nullable_pointer(xpr.data(),
352 xpr.innerStride() * (XprTypeIsRowMajor ? startCol : startRow) +
353 xpr.outerStride() * (XprTypeIsRowMajor ? startRow : startCol))),
355 m_startRow(startRow),
356 m_startCol(startCol) {
362 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl_dense(XprType& xpr, Index startRow, Index startCol, Index blockRows,
364 : Base((blockRows == 0 || blockCols == 0)
366 : add_to_nullable_pointer(xpr.data(),
367 xpr.innerStride() * (XprTypeIsRowMajor ? startCol : startRow) +
368 xpr.outerStride() * (XprTypeIsRowMajor ? startRow : startCol)),
369 blockRows, blockCols),
371 m_startRow(startRow),
372 m_startCol(startCol) {
376 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const internal::remove_all_t<XprTypeNested>& nestedExpression() const noexcept {
380 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE XprType& nestedExpression() {
return m_xpr; }
383 EIGEN_DEVICE_FUNC
constexpr Index innerStride() const noexcept {
384 return internal::traits<BlockType>::HasSameStorageOrderAsXprType ? m_xpr.innerStride() : m_xpr.outerStride();
388 EIGEN_DEVICE_FUNC
constexpr Index outerStride() const noexcept {
return m_outerStride; }
390 EIGEN_DEVICE_FUNC
constexpr StorageIndex startRow() const noexcept {
return m_startRow.value(); }
392 EIGEN_DEVICE_FUNC
constexpr StorageIndex startCol() const noexcept {
return m_startCol.value(); }
395 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void init() {
397 internal::traits<BlockType>::HasSameStorageOrderAsXprType ? m_xpr.outerStride() : m_xpr.innerStride();
401 const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows == 1) ? 0 : Dynamic>
403 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