65 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
bool HasDirectAccess>
66 struct traits<Block<XprType, BlockRows, BlockCols, InnerPanel, HasDirectAccess> > :
traits<XprType>
71 typedef typename nested<XprType>::type XprTypeNested;
72 typedef typename remove_reference<XprTypeNested>::type _XprTypeNested;
76 RowsAtCompileTime = MatrixRows == 0 ? 0 : BlockRows,
77 ColsAtCompileTime = MatrixCols == 0 ? 0 : BlockCols,
78 MaxRowsAtCompileTime = BlockRows==0 ? 0
79 : RowsAtCompileTime !=
Dynamic ?
int(RowsAtCompileTime)
80 : int(
traits<XprType>::MaxRowsAtCompileTime),
81 MaxColsAtCompileTime = BlockCols==0 ? 0
82 : ColsAtCompileTime !=
Dynamic ? int(ColsAtCompileTime)
83 : int(
traits<XprType>::MaxColsAtCompileTime),
85 IsRowMajor = (MaxRowsAtCompileTime==1&&MaxColsAtCompileTime!=1) ? 1
86 : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0
88 HasSameStorageOrderAsXprType = (IsRowMajor == XprTypeIsRowMajor),
89 InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
90 InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
91 ? int(inner_stride_at_compile_time<XprType>::ret)
92 : int(outer_stride_at_compile_time<XprType>::ret),
93 OuterStrideAtCompileTime = HasSameStorageOrderAsXprType
94 ? int(outer_stride_at_compile_time<XprType>::ret)
95 : int(inner_stride_at_compile_time<XprType>::ret),
96 MaskPacketAccessBit = (InnerSize ==
Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0)
97 && (InnerStrideAtCompileTime == 1)
99 MaskAlignedBit = (InnerPanel && (OuterStrideAtCompileTime!=
Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % 16) == 0)) ?
AlignedBit : 0,
100 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ?
LinearAccessBit : 0,
101 FlagsLvalueBit = is_lvalue<XprType>::value ?
LvalueBit : 0,
105 MaskPacketAccessBit |
107 Flags = Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit
112 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel,
bool HasDirectAccess>
class Block
113 :
public internal::dense_xpr_base<Block<XprType, BlockRows, BlockCols, InnerPanel, HasDirectAccess> >::type
117 typedef typename internal::dense_xpr_base<Block>::type
Base;
130 m_startRow( (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0),
131 m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
132 m_blockRows(BlockRows==1 ? 1 : xpr.rows()),
133 m_blockCols(BlockCols==1 ? 1 : xpr.cols())
136 ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
137 ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
142 inline Block(XprType& xpr, Index startRow, Index startCol)
143 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
144 m_blockRows(BlockRows), m_blockCols(BlockCols)
147 eigen_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows()
148 && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols());
154 Index startRow, Index startCol,
155 Index blockRows, Index blockCols)
156 : m_xpr(xpr), m_startRow(startRow), m_startCol(startCol),
157 m_blockRows(blockRows), m_blockCols(blockCols)
160 && (ColsAtCompileTime==
Dynamic || ColsAtCompileTime==blockCols));
161 eigen_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= xpr.rows()
162 && startCol >= 0 && blockCols >= 0 && startCol + blockCols <= xpr.cols());
167 inline Index rows()
const {
return m_blockRows.value(); }
168 inline Index
cols()
const {
return m_blockCols.value(); }
170 inline Scalar& coeffRef(Index
row, Index
col)
173 return m_xpr.const_cast_derived()
174 .coeffRef(row + m_startRow.value(), col + m_startCol.value());
177 inline const Scalar& coeffRef(Index
row, Index
col)
const
179 return m_xpr.derived()
180 .coeffRef(row + m_startRow.value(), col + m_startCol.value());
185 return m_xpr.coeff(row + m_startRow.value(), col + m_startCol.value());
188 inline Scalar& coeffRef(Index index)
191 return m_xpr.const_cast_derived()
192 .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
193 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
196 inline const Scalar& coeffRef(Index index)
const
198 return m_xpr.const_cast_derived()
199 .coeffRef(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
200 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
203 inline const CoeffReturnType coeff(Index index)
const
206 .coeff(m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
207 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
210 template<
int LoadMode>
211 inline PacketScalar packet(Index
row, Index
col)
const
213 return m_xpr.template packet<Unaligned>
214 (row + m_startRow.value(), col + m_startCol.value());
217 template<
int LoadMode>
218 inline void writePacket(Index
row, Index
col,
const PacketScalar& x)
220 m_xpr.const_cast_derived().template writePacket<Unaligned>
221 (row + m_startRow.value(), col + m_startCol.value(), x);
224 template<
int LoadMode>
225 inline PacketScalar packet(Index index)
const
227 return m_xpr.template packet<Unaligned>
228 (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
229 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0));
232 template<
int LoadMode>
233 inline void writePacket(Index index,
const PacketScalar& x)
235 m_xpr.const_cast_derived().template writePacket<Unaligned>
236 (m_startRow.value() + (RowsAtCompileTime == 1 ? 0 : index),
237 m_startCol.value() + (RowsAtCompileTime == 1 ? index : 0), x);
240 #ifdef EIGEN_PARSED_BY_DOXYGEN
242 inline const Scalar* data()
const;
243 inline Index innerStride()
const;
244 inline Index outerStride()
const;
247 const typename internal::remove_all<typename XprType::Nested>::type& nestedExpression()
const
252 Index startRow()
const
254 return m_startRow.value();
257 Index startCol()
const
259 return m_startCol.value();
264 const typename XprType::Nested
m_xpr;
265 const internal::variable_if_dynamic<Index, XprType::RowsAtCompileTime == 1 ? 0 : Dynamic>
m_startRow;
266 const internal::variable_if_dynamic<Index, XprType::ColsAtCompileTime == 1 ? 0 : Dynamic>
m_startCol;
267 const internal::variable_if_dynamic<Index, RowsAtCompileTime>
m_blockRows;
268 const internal::variable_if_dynamic<Index, ColsAtCompileTime>
m_blockCols;
272 template<
typename XprType,
int BlockRows,
int BlockCols,
bool InnerPanel>
273 class Block<XprType,BlockRows,BlockCols, InnerPanel,true>
274 :
public MapBase<Block<XprType, BlockRows, BlockCols, InnerPanel, true> >
287 (BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) ? i : 0,
288 (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0)),
289 BlockRows==1 ? 1 : xpr.rows(),
290 BlockCols==1 ? 1 : xpr.cols()),
294 ((BlockRows==1) && (BlockCols==XprType::ColsAtCompileTime) && i<xpr.rows())
295 ||((BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) && i<xpr.cols())));
301 inline Block(XprType& xpr, Index startRow, Index startCol)
304 eigen_assert(startRow >= 0 && BlockRows >= 1 && startRow + BlockRows <= xpr.rows()
305 && startCol >= 0 && BlockCols >= 1 && startCol + BlockCols <= xpr.cols());
312 Index startRow, Index startCol,
313 Index blockRows, Index blockCols)
314 :
Base(internal::
const_cast_ptr(&xpr.coeffRef(startRow,startCol)), blockRows, blockCols),
318 && (ColsAtCompileTime==
Dynamic || ColsAtCompileTime==blockCols));
319 eigen_assert(startRow >= 0 && blockRows >= 0 && startRow + blockRows <= xpr.rows()
320 && startCol >= 0 && blockCols >= 0 && startCol + blockCols <= xpr.cols());
324 const typename internal::remove_all<typename XprType::Nested>::type& nestedExpression()
const
330 inline Index innerStride()
const
332 return internal::traits<Block>::HasSameStorageOrderAsXprType
333 ? m_xpr.innerStride()
334 : m_xpr.outerStride();
338 inline Index outerStride()
const
340 return m_outerStride;
349 #ifndef EIGEN_PARSED_BY_DOXYGEN
351 inline Block(XprType& xpr,
const Scalar* data, Index blockRows, Index blockCols)
352 : Base(data, blockRows, blockCols), m_xpr(xpr)
361 m_outerStride = internal::traits<Block>::HasSameStorageOrderAsXprType
362 ? m_xpr.outerStride()
363 : m_xpr.innerStride();
372 #endif // EIGEN_BLOCK_H