52 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
53 struct traits<Block<XprType, BlockRows, BlockCols, InnerPanel> > : traits<XprType>
55 typedef typename traits<XprType>::Scalar Scalar;
56 typedef typename traits<XprType>::StorageKind StorageKind;
57 typedef typename traits<XprType>::XprKind XprKind;
58 typedef typename ref_selector<XprType>::type XprTypeNested;
59 typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
61 MatrixRows = traits<XprType>::RowsAtCompileTime,
62 MatrixCols = traits<XprType>::ColsAtCompileTime,
63 RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
64 ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
65 MaxRowsAtCompileTime = BlockRows==0 ? 0
66 : RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime)
67 : int(traits<XprType>::MaxRowsAtCompileTime),
68 MaxColsAtCompileTime = BlockCols==0 ? 0
69 : ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime)
70 : int(traits<XprType>::MaxColsAtCompileTime),
72 XprTypeIsRowMajor = (int(traits<XprType>::Flags)&
RowMajorBit) != 0,
73 IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
74 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
76 HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
77 InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
78 InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
79 ? int(inner_stride_at_compile_time<XprType>::ret)
80 : int(outer_stride_at_compile_time<XprType>::ret),
81 OuterStrideAtCompileTime = HasSameStorageOrderAsXprType
82 ? int(outer_stride_at_compile_time<XprType>::ret)
83 : int(inner_stride_at_compile_time<XprType>::ret),
86 FlagsLvalueBit = is_lvalue<XprType>::value ?
LvalueBit : 0,
97 template<
typename XprType,
int BlockRows=Dynamic,
int BlockCols=Dynamic,
bool InnerPanel =
false,
98 bool HasDirectAccess = internal::has_direct_access<XprType>::ret>
class BlockImpl_dense;
102 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
typename StorageKind>
class BlockImpl;
104 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
class Block
105 :
public BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind>
107 typedef BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, typename internal::traits<XprType>::StorageKind> Impl;
111 EIGEN_GENERIC_PUBLIC_INTERFACE(
Block)
112 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Block)
114 typedef typename internal::remove_all<XprType>::type NestedExpression;
119 inline Block(XprType& xpr, Index i) : Impl(xpr,i)
121 eigen_assert( (i>=0) && (
122 ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
123 ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
129 inline Block(XprType& xpr, Index startRow, Index startCol)
130 : Impl(xpr, startRow, startCol)
132 EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
133 eigen_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows()
134 && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols());
141 Index startRow, Index startCol,
142 Index blockRows, Index blockCols)
143 : 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
148 && startCol >= 0 && blockCols >= 0 && startCol <= xpr.cols() - blockCols);
154 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
155 class BlockImpl<XprType, BlockRows, BlockCols, InnerPanel, Dense>
156 :
public internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel>
158 typedef internal::BlockImpl_dense<XprType, BlockRows, BlockCols, InnerPanel> Impl;
159 typedef typename XprType::StorageIndex StorageIndex;
162 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl)
163 EIGEN_DEVICE_FUNC inline BlockImpl(XprType& xpr, Index i) : Impl(xpr,i) {}
164 EIGEN_DEVICE_FUNC
inline BlockImpl(XprType& xpr, Index startRow, Index startCol) : Impl(xpr, startRow, startCol) {}
166 inline BlockImpl(XprType& xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
167 : Impl(xpr, startRow, startCol, blockRows, blockCols) {}
173 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
bool HasDirectAccess>
class BlockImpl_dense
174 :
public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel> >::type
176 typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
179 typedef typename internal::dense_xpr_base<BlockType>::type Base;
180 EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
181 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
188 inline BlockImpl_dense(XprType& xpr, Index i)
194 m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
195 m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
196 m_blockRows(BlockRows==1 ? 1 : xpr.rows()),
197 m_blockCols(BlockCols==1 ? 1 : xpr.cols())
203 inline BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
204 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
205 m_blockRows(BlockRows), m_blockCols(BlockCols)
211 inline BlockImpl_dense(XprType& xpr,
212 Index startRow, Index startCol,
213 Index blockRows, Index blockCols)
214 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
215 m_blockRows(blockRows), m_blockCols(blockCols)
218 EIGEN_DEVICE_FUNC
inline Index rows()
const {
return m_blockRows.value(); }
219 EIGEN_DEVICE_FUNC
inline Index cols()
const {
return m_blockCols.value(); }
222 inline Scalar& coeffRef(Index rowId, Index colId)
224 EIGEN_STATIC_ASSERT_LVALUE(XprType)
225 return m_xpr.const_cast_derived()
226 .coeffRef(rowId + m_startRow.value(), colId + m_startCol.value());
230 inline const Scalar& coeffRef(Index rowId, Index colId)
const
232 return m_xpr.derived()
233 .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.const_cast_derived()
247 .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
248 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
252 inline const Scalar& coeffRef(Index index)
const
254 return m_xpr.const_cast_derived()
255 .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
256 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
260 inline const CoeffReturnType coeff(Index index)
const
263 .coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
264 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
267 template<
int LoadMode>
268 inline PacketScalar packet(Index rowId, Index colId)
const
270 return m_xpr.template packet<Unaligned>
271 (rowId + m_startRow.value(), colId + m_startCol.value());
274 template<
int LoadMode>
275 inline void writePacket(Index rowId, Index colId,
const PacketScalar& val)
277 m_xpr.const_cast_derived().template writePacket<Unaligned>
278 (rowId + m_startRow.value(), colId + m_startCol.value(), val);
281 template<
int LoadMode>
282 inline PacketScalar packet(Index index)
const
284 return m_xpr.template packet<Unaligned>
285 (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
286 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
289 template<
int LoadMode>
290 inline void writePacket(Index index,
const PacketScalar& val)
292 m_xpr.const_cast_derived().template writePacket<Unaligned>
293 (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
294 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), val);
297 #ifdef EIGEN_PARSED_BY_DOXYGEN
299 EIGEN_DEVICE_FUNC
inline const Scalar* data()
const;
300 EIGEN_DEVICE_FUNC
inline Index innerStride()
const;
301 EIGEN_DEVICE_FUNC
inline Index outerStride()
const;
305 const typename internal::remove_all<typename XprType::Nested>::type& nestedExpression()
const
311 StorageIndex startRow()
const
313 return m_startRow.value();
317 StorageIndex startCol()
const
319 return m_startCol.value();
324 const typename XprType::Nested m_xpr;
325 const internal::variable_if_dynamic<StorageIndex, XprType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
326 const internal::variable_if_dynamic<StorageIndex, XprType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
327 const internal::variable_if_dynamic<StorageIndex, RowsAtCompileTime> m_blockRows;
328 const internal::variable_if_dynamic<StorageIndex, ColsAtCompileTime> m_blockCols;
332 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
333 class BlockImpl_dense<XprType,BlockRows,BlockCols, InnerPanel,true>
334 :
public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel> >
336 typedef Block<XprType, BlockRows, BlockCols, InnerPanel> BlockType;
338 XprTypeIsRowMajor = (int(traits<XprType>::Flags)&
RowMajorBit) != 0
342 typedef MapBase<BlockType> Base;
343 EIGEN_DENSE_PUBLIC_INTERFACE(BlockType)
344 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(BlockImpl_dense)
349 inline BlockImpl_dense(XprType& xpr, Index i)
350 : Base(xpr.data() + i * ( ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && (!XprTypeIsRowMajor))
351 || ((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && ( XprTypeIsRowMajor)) ? xpr.innerStride() : xpr.outerStride()),
352 BlockRows==1 ? 1 : xpr.rows(),
353 BlockCols==1 ? 1 : xpr.cols()),
362 inline BlockImpl_dense(XprType& xpr, Index startRow, Index startCol)
363 : Base(xpr.data()+xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol)),
372 inline BlockImpl_dense(XprType& xpr,
373 Index startRow, Index startCol,
374 Index blockRows, Index blockCols)
375 : Base(xpr.data()+xpr.innerStride()*(XprTypeIsRowMajor?startCol:startRow) + xpr.outerStride()*(XprTypeIsRowMajor?startRow:startCol), blockRows, blockCols),
382 const typename internal::remove_all<typename XprType::Nested>::type& nestedExpression()
const
389 inline Index innerStride()
const
391 return internal::traits<BlockType>::HasSameStorageOrderAsXprType
392 ? m_xpr.innerStride()
393 : m_xpr.outerStride();
398 inline Index outerStride()
const
400 return m_outerStride;
409 #ifndef EIGEN_PARSED_BY_DOXYGEN
412 inline BlockImpl_dense(XprType& xpr,
const Scalar* data, Index blockRows, Index blockCols)
413 : Base(data, blockRows, blockCols), m_xpr(xpr)
423 m_outerStride = internal::traits<BlockType>::HasSameStorageOrderAsXprType
424 ? m_xpr.outerStride()
425 : m_xpr.innerStride();
428 typename XprType::Nested m_xpr;
436 #endif // EIGEN_BLOCK_H
const unsigned int CompressedAccessBit
Definition: Constants.h:185
const unsigned int DirectAccessBit
Definition: Constants.h:149
const unsigned int LvalueBit
Definition: Constants.h:138
const unsigned int RowMajorBit
Definition: Constants.h:61
Block(XprType &xpr, Index startRow, Index startCol, Index blockRows, Index blockCols)
Definition: Block.h:140
Block(XprType &xpr, Index i)
Definition: Block.h:119
Definition: Eigen_Colamd.h:54
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:104
Block(XprType &xpr, Index startRow, Index startCol)
Definition: Block.h:129