19 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
20 struct traits<Block<XprType, BlockRows, BlockCols, InnerPanel> > : traits<XprType>
22 typedef typename traits<XprType>::Scalar Scalar;
23 typedef typename traits<XprType>::StorageKind StorageKind;
24 typedef typename traits<XprType>::XprKind XprKind;
25 typedef typename ref_selector<XprType>::type XprTypeNested;
26 typedef std::remove_reference_t<XprTypeNested> XprTypeNested_;
28 MatrixRows = traits<XprType>::RowsAtCompileTime,
29 MatrixCols = traits<XprType>::ColsAtCompileTime,
30 RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
31 ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
32 MaxRowsAtCompileTime = BlockRows==0 ? 0
33 : RowsAtCompileTime !=
Dynamic ? int(RowsAtCompileTime)
34 : int(traits<XprType>::MaxRowsAtCompileTime),
35 MaxColsAtCompileTime = BlockCols==0 ? 0
36 : ColsAtCompileTime !=
Dynamic ? int(ColsAtCompileTime)
37 : int(traits<XprType>::MaxColsAtCompileTime),
39 XprTypeIsRowMajor = (int(traits<XprType>::Flags)&
RowMajorBit) != 0,
40 IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
41 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
43 HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
44 InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
45 InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
46 ? int(inner_stride_at_compile_time<XprType>::ret)
47 : int(outer_stride_at_compile_time<XprType>::ret),
48 OuterStrideAtCompileTime = HasSameStorageOrderAsXprType
49 ? int(outer_stride_at_compile_time<XprType>::ret)
50 : int(inner_stride_at_compile_time<XprType>::ret),
53 FlagsLvalueBit = is_lvalue<XprType>::value ?
LvalueBit : 0,
64 template<
typename XprType,
int BlockRows=
Dynamic,
int BlockCols=
Dynamic,
bool InnerPanel =
false,
65 bool HasDirectAccess = internal::has_direct_access<XprType>::ret>
class BlockImpl_dense;
69 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
typename StorageKind>
class BlockImpl;
105 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
class Block
106 :
public BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind>
123 ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) &&
i<xpr.rows())
124 ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) &&
i<xpr.cols())));
131 :
Impl(xpr, startRow, startCol)
134 eigen_assert(startRow >= 0 && BlockRows >= 0 && startRow + BlockRows <= xpr.rows()
135 && startCol >= 0 && BlockCols >= 0 && startCol + BlockCols <= xpr.cols());
144 :
Impl(xpr, startRow, startCol, blockRows, blockCols)
147 && (ColsAtCompileTime==
Dynamic || ColsAtCompileTime==blockCols));
148 eigen_assert(startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows
149 && startCol >= 0 && blockCols >= 0 && startCol <= xpr.cols() - blockCols);
155 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
157 :
public internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel>
159 typedef internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel>
Impl;
168 :
Impl(xpr, startRow, startCol, blockRows, blockCols) {}
174 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
bool HasDirectAccess>
class BlockImpl_dense
175 :
public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel> >::type
177 typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
178 typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested;
181 typedef typename internal::dense_xpr_base<BlockType>::type Base;
190 inline BlockImpl_dense(XprType& xpr,
Index i)
196 m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ?
i : 0),
197 m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ?
i : 0),
198 m_blockRows(BlockRows==1 ? 1 : xpr.
rows()),
199 m_blockCols(BlockCols==1 ? 1 : xpr.
cols())
205 inline BlockImpl_dense(XprType& xpr,
Index startRow,
Index startCol)
206 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
207 m_blockRows(BlockRows), m_blockCols(BlockCols)
213 inline BlockImpl_dense(XprType& xpr,
216 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
217 m_blockRows(blockRows), m_blockCols(blockCols)
224 inline Scalar& coeffRef(
Index rowId,
Index colId)
227 return m_xpr.coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
231 inline const Scalar& coeffRef(
Index rowId,
Index colId)
const
233 return m_xpr.derived().coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
237 EIGEN_STRONG_INLINE
const CoeffReturnType coeff(
Index rowId,
Index colId)
const
239 return m_xpr.coeff(rowId + m_startRow.value(), colId + m_startCol.value());
243 inline Scalar& coeffRef(
Index index)
246 return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
247 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
251 inline const Scalar& coeffRef(
Index index)
const
253 return m_xpr.coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
254 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
258 inline const CoeffReturnType coeff(
Index index)
const
260 return m_xpr.coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
261 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
264 template<
int LoadMode>
267 return m_xpr.template packet<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value());
270 template<
int LoadMode>
273 m_xpr.template writePacket<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value(), val);
276 template<
int LoadMode>
279 return m_xpr.template packet<Unaligned>
280 (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
281 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
284 template<
int LoadMode>
287 m_xpr.template writePacket<Unaligned>
288 (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
289 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), val);
292 #ifdef EIGEN_PARSED_BY_DOXYGEN
300 const internal::remove_all_t<XprTypeNested>& nestedExpression()
const
306 XprType& nestedExpression() {
return m_xpr; }
311 return m_startRow.value();
317 return m_startCol.value();
323 const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 :
Dynamic> m_startRow;
324 const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 :
Dynamic> m_startCol;
325 const internal::variable_if_dynamic<StorageIndex, RowsAtCompileTime> m_blockRows;
326 const internal::variable_if_dynamic<StorageIndex, ColsAtCompileTime> m_blockCols;
330 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
331 class BlockImpl_dense<XprType,BlockRows,BlockCols, InnerPanel,true>
332 :
public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel> >
334 typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
335 typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested;
337 XprTypeIsRowMajor = (int(traits<XprType>::Flags)&
RowMajorBit) != 0
343 template <
typename Scalar>
345 static Scalar* add_to_nullable_pointer(Scalar* base,
Index offset)
347 return base !=
nullptr ? base+offset :
nullptr;
352 typedef MapBase<BlockType> Base;
359 BlockImpl_dense(XprType& xpr,
Index i)
360 : Base((BlockRows == 0 || BlockCols == 0) ? nullptr : add_to_nullable_pointer(xpr.
data(),
361 i * ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && (!XprTypeIsRowMajor))
362 || ((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && ( XprTypeIsRowMajor)) ? xpr.innerStride() : xpr.outerStride())),
363 BlockRows==1 ? 1 : xpr.
rows(),
364 BlockCols==1 ? 1 : xpr.
cols()),
366 m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ?
i : 0),
367 m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ?
i : 0)
375 BlockImpl_dense(XprType& xpr,
Index startRow,
Index startCol)
376 : Base((BlockRows == 0 || BlockCols == 0) ? nullptr : add_to_nullable_pointer(xpr.
data(),
377 xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol))),
378 m_xpr(xpr), m_startRow(startRow), m_startCol(startCol)
386 BlockImpl_dense(XprType& xpr,
389 : Base((blockRows == 0 || blockCols == 0) ? nullptr : add_to_nullable_pointer(xpr.
data(),
390 xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol)),
391 blockRows, blockCols),
392 m_xpr(xpr), m_startRow(startRow), m_startCol(startCol)
398 const internal::remove_all_t<XprTypeNested>& nestedExpression() const
EIGEN_NOEXCEPT
404 XprType& nestedExpression() {
return m_xpr; }
410 return internal::traits<BlockType>::HasSameStorageOrderAsXprType
411 ? m_xpr.innerStride()
412 : m_xpr.outerStride();
419 return internal::traits<BlockType>::HasSameStorageOrderAsXprType
420 ? m_xpr.outerStride()
421 : m_xpr.innerStride();
425 StorageIndex startRow() const
EIGEN_NOEXCEPT {
return m_startRow.value(); }
428 StorageIndex startCol() const
EIGEN_NOEXCEPT {
return m_startCol.value(); }
436 #ifndef EIGEN_PARSED_BY_DOXYGEN
439 BlockImpl_dense(XprType& xpr,
const Scalar*
data,
Index blockRows,
Index blockCols)
440 : Base(
data, blockRows, blockCols), m_xpr(xpr)
450 m_outerStride = internal::traits<BlockType>::HasSameStorageOrderAsXprType
451 ? m_xpr.outerStride()
452 : m_xpr.innerStride();
456 const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 :
Dynamic> m_startRow;
457 const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 :
Dynamic> m_startCol;
#define EIGEN_ALWAYS_INLINE
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
#define EIGEN_DEVICE_FUNC
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
#define EIGEN_STATIC_ASSERT_LVALUE(Derived)
#define EIGEN_STATIC_ASSERT(X, MSG)
internal::BlockImpl_dense< XprType, BlockRows, BlockCols, InnerPanel > Impl
BlockImpl(XprType &xpr, Index startRow, Index startCol)
XprType::StorageIndex StorageIndex
BlockImpl(XprType &xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
Expression of a fixed-size or dynamic-size block.
internal::remove_all_t< XprType > NestedExpression
Block(XprType &xpr, Index startRow, Index startCol)
Block(XprType &xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
BlockImpl< XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits< XprType >::StorageKind > Impl
const unsigned int DirectAccessBit
const unsigned int LvalueBit
const unsigned int RowMajorBit
const unsigned int CompressedAccessBit
typename remove_all< T >::type remove_all_t
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.