14#include "./InternalHeaderCheck.h"
19template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
20struct 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 typename remove_reference<XprTypeNested>::type _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,
64template<
typename XprType,
int BlockRows=
Dynamic,
int BlockCols=
Dynamic,
bool InnerPanel =
false,
65 bool HasDirectAccess = internal::has_direct_access<XprType>::ret>
class BlockImpl_dense;
69template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
typename StorageKind>
class BlockImpl;
105template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
class Block
106 :
public BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind>
108 typedef BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind> Impl;
112 EIGEN_GENERIC_PUBLIC_INTERFACE(
Block)
113 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Block)
115 typedef typename internal::remove_all<XprType>::type NestedExpression;
119 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
122 eigen_assert( (i>=0) && (
123 ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
124 ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
129 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
131 : Impl(xpr, startRow, startCol)
133 EIGEN_STATIC_ASSERT(RowsAtCompileTime!=
Dynamic && ColsAtCompileTime!=
Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
134 eigen_assert(startRow >= 0 && BlockRows >= 0 && startRow + BlockRows <= xpr.rows()
135 && startCol >= 0 && BlockCols >= 0 && startCol + BlockCols <= xpr.cols());
140 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
144 : Impl(xpr, startRow, startCol, blockRows, blockCols)
146 eigen_assert((RowsAtCompileTime==
Dynamic || RowsAtCompileTime==blockRows)
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);
155template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
156class BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Dense>
157 :
public internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel>
159 typedef internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel> Impl;
160 typedef typename XprType::StorageIndex StorageIndex;
163 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl)
164 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr,
Index i) : Impl(xpr,i) {}
165 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockImpl(XprType& xpr,
Index startRow,
Index startCol) : Impl(xpr, startRow, startCol) {}
167 EIGEN_STRONG_INLINE BlockImpl(XprType& xpr,
Index startRow,
Index startCol,
Index blockRows,
Index blockCols)
168 : Impl(xpr, startRow, startCol, blockRows, blockCols) {}
174template<
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;
182 EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
183 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
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)
220 EIGEN_DEVICE_FUNC
inline Index rows()
const {
return m_blockRows.value(); }
221 EIGEN_DEVICE_FUNC
inline Index cols()
const {
return m_blockCols.value(); }
224 inline Scalar& coeffRef(
Index rowId,
Index colId)
226 EIGEN_STATIC_ASSERT_LVALUE(XprType)
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)
245 EIGEN_STATIC_ASSERT_LVALUE(XprType)
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>
265 EIGEN_DEVICE_FUNC
inline PacketScalar packet(
Index rowId,
Index colId)
const
267 return m_xpr.template packet<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value());
270 template<
int LoadMode>
271 EIGEN_DEVICE_FUNC
inline void writePacket(
Index rowId,
Index colId,
const PacketScalar& val)
273 m_xpr.template writePacket<Unaligned>(rowId + m_startRow.value(), colId + m_startCol.value(), val);
276 template<
int LoadMode>
277 EIGEN_DEVICE_FUNC
inline PacketScalar packet(
Index index)
const
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>
285 EIGEN_DEVICE_FUNC
inline void writePacket(
Index index,
const PacketScalar& val)
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
294 EIGEN_DEVICE_FUNC
inline const Scalar* data()
const;
295 EIGEN_DEVICE_FUNC
inline Index innerStride()
const;
296 EIGEN_DEVICE_FUNC
inline Index outerStride()
const;
299 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
300 const typename internal::remove_all<XprTypeNested>::type& nestedExpression()
const
305 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
306 XprType& nestedExpression() {
return m_xpr; }
308 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
309 StorageIndex startRow() const EIGEN_NOEXCEPT
311 return m_startRow.value();
314 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
315 StorageIndex startCol() const EIGEN_NOEXCEPT
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;
330template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
331class 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
341 typedef MapBase<BlockType> Base;
342 EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
343 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
347 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
348 BlockImpl_dense(XprType& xpr,
Index i)
349 : Base(xpr.data() + i * ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && (!XprTypeIsRowMajor))
350 || ((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && ( XprTypeIsRowMajor)) ? xpr.innerStride() : xpr.outerStride()),
351 BlockRows==1 ? 1 : xpr.rows(),
352 BlockCols==1 ? 1 : xpr.cols()),
354 m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
355 m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0)
362 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
363 BlockImpl_dense(XprType& xpr,
Index startRow,
Index startCol)
364 : Base(xpr.data()+xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol)),
365 m_xpr(xpr), m_startRow(startRow), m_startCol(startCol)
372 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
373 BlockImpl_dense(XprType& xpr,
376 : Base(xpr.data()+xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol), blockRows, blockCols),
377 m_xpr(xpr), m_startRow(startRow), m_startCol(startCol)
382 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
383 const typename internal::remove_all<XprTypeNested>::type& nestedExpression() const EIGEN_NOEXCEPT
388 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
389 XprType& nestedExpression() {
return m_xpr; }
392 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
393 Index innerStride() const EIGEN_NOEXCEPT
395 return internal::traits<BlockType>::HasSameStorageOrderAsXprType
396 ? m_xpr.innerStride()
397 : m_xpr.outerStride();
401 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
402 Index outerStride() const EIGEN_NOEXCEPT
404 return internal::traits<BlockType>::HasSameStorageOrderAsXprType
405 ? m_xpr.outerStride()
406 : m_xpr.innerStride();
409 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
410 StorageIndex startRow() const EIGEN_NOEXCEPT {
return m_startRow.value(); }
412 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
413 StorageIndex startCol() const EIGEN_NOEXCEPT {
return m_startCol.value(); }
421 #ifndef EIGEN_PARSED_BY_DOXYGEN
423 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
424 BlockImpl_dense(XprType& xpr,
const Scalar* data,
Index blockRows,
Index blockCols)
425 : Base(data, blockRows, blockCols), m_xpr(xpr)
432 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
435 m_outerStride = internal::traits<BlockType>::HasSameStorageOrderAsXprType
436 ? m_xpr.outerStride()
437 : m_xpr.innerStride();
441 const internal::variable_if_dynamic<StorageIndex, (XprType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 :
Dynamic> m_startRow;
442 const internal::variable_if_dynamic<StorageIndex, (XprType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 :
Dynamic> m_startCol;
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:107
Block(XprType &xpr, Index startRow, Index startCol)
Definition: Block.h:130
Block(XprType &xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
Definition: Block.h:141
Block(XprType &xpr, Index i)
Definition: Block.h:120
const unsigned int DirectAccessBit
Definition: Constants.h:157
const unsigned int LvalueBit
Definition: Constants.h:146
const unsigned int RowMajorBit
Definition: Constants.h:68
const unsigned int CompressedAccessBit
Definition: Constants.h:193
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24