50 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
bool HasDirectAccess>
51 struct traits<Block<XprType, BlockRows, BlockCols, InnerPanel, HasDirectAccess> > : traits<XprType>
53 typedef typename traits<XprType>::Scalar Scalar;
54 typedef typename traits<XprType>::StorageKind StorageKind;
55 typedef typename traits<XprType>::XprKind XprKind;
56 typedef typename nested<XprType>::type XprTypeNested;
57 typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
59 MatrixRows = traits<XprType>::RowsAtCompileTime,
60 MatrixCols = traits<XprType>::ColsAtCompileTime,
61 RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
62 ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
63 MaxRowsAtCompileTime = BlockRows==0 ? 0
64 : RowsAtCompileTime !=
Dynamic ? int(RowsAtCompileTime)
65 : int(traits<XprType>::MaxRowsAtCompileTime),
66 MaxColsAtCompileTime = BlockCols==0 ? 0
67 : ColsAtCompileTime !=
Dynamic ? int(ColsAtCompileTime)
68 : int(traits<XprType>::MaxColsAtCompileTime),
69 XprTypeIsRowMajor = (int(traits<XprType>::Flags)&
RowMajorBit) != 0,
70 IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
71 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
73 HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
74 InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
75 InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
76 ? int(inner_stride_at_compile_time<XprType>::ret)
77 : int(outer_stride_at_compile_time<XprType>::ret),
78 OuterStrideAtCompileTime = HasSameStorageOrderAsXprType
79 ? int(outer_stride_at_compile_time<XprType>::ret)
80 : int(inner_stride_at_compile_time<XprType>::ret),
81 MaskPacketAccessBit = (InnerSize ==
Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0)
82 && (InnerStrideAtCompileTime == 1)
84 MaskAlignedBit = (InnerPanel && (OuterStrideAtCompileTime!=
Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16) == 0)) ?
AlignedBit : 0,
85 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ?
LinearAccessBit : 0,
86 FlagsLvalueBit = is_lvalue<XprType>::value ?
LvalueBit : 0,
88 Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~
RowMajorBit) |
92 Flags = Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit
97 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
bool HasDirectAccess>
class Block
98 :
public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel, HasDirectAccess> >::type
102 typedef typename internal::dense_xpr_base<Block>::type Base;
103 EIGEN_DENSE_PUBLIC_INTERFACE(
Block)
115 m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
116 m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
117 m_blockRows(BlockRows==1 ? 1 : xpr.rows()),
118 m_blockCols(BlockCols==1 ? 1 : xpr.cols())
120 eigen_assert( (i>=0) && (
121 ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
122 ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
127 inline Block(XprType& xpr, Index startRow, Index startCol)
128 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
129 m_blockRows(BlockRows), m_blockCols(BlockCols)
131 EIGEN_STATIC_ASSERT(RowsAtCompileTime!=
Dynamic && ColsAtCompileTime!=
Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
132 eigen_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows()
133 && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols());
139 Index startRow, Index startCol,
140 Index blockRows, Index blockCols)
141 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
142 m_blockRows(blockRows), m_blockCols(blockCols)
144 eigen_assert((RowsAtCompileTime==
Dynamic || RowsAtCompileTime==blockRows)
145 && (ColsAtCompileTime==
Dynamic || ColsAtCompileTime==blockCols));
146 eigen_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= xpr.rows()
147 && startCol >= 0 && blockCols >= 0 && startCol + blockCols <= xpr.cols());
150 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Block)
152 inline Index rows()
const {
return m_blockRows.value(); }
153 inline Index cols()
const {
return m_blockCols.value(); }
155 inline Scalar& coeffRef(Index row, Index col)
157 EIGEN_STATIC_ASSERT_LVALUE(XprType)
158 return m_xpr.const_cast_derived()
159 .coeffRef(row + m_startRow.value(), col + m_startCol.value());
162 inline const Scalar& coeffRef(Index row, Index col)
const
164 return m_xpr.derived()
165 .coeffRef(row + m_startRow.value(), col + m_startCol.value());
168 EIGEN_STRONG_INLINE
const CoeffReturnType coeff(Index row, Index col)
const
170 return m_xpr.coeff(row + m_startRow.value(), col + m_startCol.value());
173 inline Scalar& coeffRef(Index index)
175 EIGEN_STATIC_ASSERT_LVALUE(XprType)
176 return m_xpr.const_cast_derived()
177 .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
178 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
181 inline const Scalar& coeffRef(Index index)
const
183 return m_xpr.const_cast_derived()
184 .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
185 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
188 inline const CoeffReturnType coeff(Index index)
const
191 .coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
192 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
195 template<
int LoadMode>
196 inline PacketScalar packet(Index row, Index col)
const
198 return m_xpr.template packet<Unaligned>
199 (row + m_startRow.value(), col + m_startCol.value());
202 template<
int LoadMode>
203 inline void writePacket(Index row, Index col,
const PacketScalar& x)
205 m_xpr.const_cast_derived().template writePacket<Unaligned>
206 (row + m_startRow.value(), col + m_startCol.value(), x);
209 template<
int LoadMode>
210 inline PacketScalar packet(Index index)
const
212 return m_xpr.template packet<Unaligned>
213 (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
214 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
217 template<
int LoadMode>
218 inline void writePacket(Index index,
const PacketScalar& x)
220 m_xpr.const_cast_derived().template writePacket<Unaligned>
221 (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
222 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), x);
225 #ifdef EIGEN_PARSED_BY_DOXYGEN
227 inline const Scalar* data()
const;
228 inline Index innerStride()
const;
229 inline Index outerStride()
const;
232 const typename internal::remove_all<typename XprType::Nested>::type& nestedExpression()
const
237 Index startRow()
const
239 return m_startRow.value();
242 Index startCol()
const
244 return m_startCol.value();
249 const typename XprType::Nested m_xpr;
250 const internal::variable_if_dynamic<Index, XprType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
251 const internal::variable_if_dynamic<Index, XprType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
252 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_blockRows;
253 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_blockCols;
257 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
258 class Block<XprType,BlockRows,BlockCols, InnerPanel,true>
259 :
public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel, true> >
263 typedef MapBase<Block> Base;
264 EIGEN_DENSE_PUBLIC_INTERFACE(Block)
266 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Block)
270 inline Block(XprType& xpr, Index i)
271 : Base(internal::const_cast_ptr(&xpr.coeffRef(
272 (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0,
273 (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0)),
274 BlockRows==1 ? 1 : xpr.rows(),
275 BlockCols==1 ? 1 : xpr.cols()),
278 eigen_assert( (i>=0) && (
279 ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
280 ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
286 inline Block(XprType& xpr, Index startRow, Index startCol)
287 : Base(internal::const_cast_ptr(&xpr.coeffRef(startRow,startCol))), m_xpr(xpr)
289 eigen_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows()
290 && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols());
296 inline Block(XprType& xpr,
297 Index startRow, Index startCol,
298 Index blockRows, Index blockCols)
299 : Base(internal::const_cast_ptr(&xpr.coeffRef(startRow,startCol)), blockRows, blockCols),
302 eigen_assert((RowsAtCompileTime==
Dynamic || RowsAtCompileTime==blockRows)
303 && (ColsAtCompileTime==
Dynamic || ColsAtCompileTime==blockCols));
304 eigen_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= xpr.rows()
305 && startCol >= 0 && blockCols >= 0 && startCol + blockCols <= xpr.cols());
309 const typename internal::remove_all<typename XprType::Nested>::type& nestedExpression()
const
315 inline Index innerStride()
const
317 return internal::traits<Block>::HasSameStorageOrderAsXprType
318 ? m_xpr.innerStride()
319 : m_xpr.outerStride();
323 inline Index outerStride()
const
325 return m_outerStride;
334 #ifndef EIGEN_PARSED_BY_DOXYGEN
336 inline Block(XprType& xpr,
const Scalar* data, Index blockRows, Index blockCols)
337 : Base(data, blockRows, blockCols), m_xpr(xpr)
346 m_outerStride = internal::traits<Block>::HasSameStorageOrderAsXprType
347 ? m_xpr.outerStride()
348 : m_xpr.innerStride();
351 typename XprType::Nested m_xpr;
357 #endif // EIGEN_BLOCK_H