11 #ifndef EIGEN_RESHAPED_H 12 #define EIGEN_RESHAPED_H 48 template<
typename XprType,
int Rows,
int Cols,
int Order>
49 struct traits<Reshaped<XprType, Rows, Cols, Order> > : traits<XprType>
51 typedef typename traits<XprType>::Scalar Scalar;
52 typedef typename traits<XprType>::StorageKind StorageKind;
53 typedef typename traits<XprType>::XprKind XprKind;
55 MatrixRows = traits<XprType>::RowsAtCompileTime,
56 MatrixCols = traits<XprType>::ColsAtCompileTime,
57 RowsAtCompileTime = Rows,
58 ColsAtCompileTime = Cols,
59 MaxRowsAtCompileTime = Rows,
60 MaxColsAtCompileTime = Cols,
62 ReshapedStorageOrder = (RowsAtCompileTime == 1 && ColsAtCompileTime != 1) ?
RowMajor 63 : (ColsAtCompileTime == 1 && RowsAtCompileTime != 1) ?
ColMajor 65 HasSameStorageOrderAsXprType = (ReshapedStorageOrder == XpxStorageOrder),
66 InnerSize = (ReshapedStorageOrder==
int(
RowMajor)) ?
int(ColsAtCompileTime) : int(RowsAtCompileTime),
67 InnerStrideAtCompileTime = HasSameStorageOrderAsXprType
68 ? int(inner_stride_at_compile_time<XprType>::ret)
70 OuterStrideAtCompileTime =
Dynamic,
72 HasDirectAccess =
internal::has_direct_access<XprType>::ret
73 && (Order==int(XpxStorageOrder))
76 MaskPacketAccessBit = (InnerSize ==
Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0)
77 && (InnerStrideAtCompileTime == 1)
80 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1) ?
LinearAccessBit : 0,
81 FlagsLvalueBit = is_lvalue<XprType>::value ?
LvalueBit : 0,
84 Flags0 = traits<XprType>::Flags & ( (HereditaryBits & ~
RowMajorBit) | MaskPacketAccessBit),
86 Flags = (Flags0 | FlagsLinearAccessBit | FlagsLvalueBit | FlagsRowMajorBit | FlagsDirectAccessBit)
90 template<
typename XprType,
int Rows,
int Cols,
int Order,
bool HasDirectAccess>
class ReshapedImpl_dense;
94 template<
typename XprType,
int Rows,
int Cols,
int Order,
typename StorageKind>
class ReshapedImpl;
96 template<
typename XprType,
int Rows,
int Cols,
int Order>
class Reshaped 97 :
public ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind>
99 typedef ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind> Impl;
103 EIGEN_GENERIC_PUBLIC_INTERFACE(
Reshaped)
104 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(
Reshaped)
112 EIGEN_STATIC_ASSERT(RowsAtCompileTime!=
Dynamic && ColsAtCompileTime!=
Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
113 eigen_assert(Rows * Cols == xpr.rows() * xpr.cols());
121 : Impl(xpr, reshapeRows, reshapeCols)
123 eigen_assert((RowsAtCompileTime==
Dynamic || RowsAtCompileTime==reshapeRows)
124 && (ColsAtCompileTime==
Dynamic || ColsAtCompileTime==reshapeCols));
125 eigen_assert(reshapeRows * reshapeCols == xpr.rows() * xpr.cols());
131 template<
typename XprType,
int Rows,
int Cols,
int Order>
132 class ReshapedImpl<XprType, Rows, Cols, Order, Dense>
133 :
public internal::ReshapedImpl_dense<XprType, Rows, Cols, Order,internal::traits<Reshaped<XprType,Rows,Cols,Order> >::HasDirectAccess>
135 typedef internal::ReshapedImpl_dense<XprType, Rows, Cols, Order,internal::traits<Reshaped<XprType,Rows,Cols,Order> >::HasDirectAccess> Impl;
138 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl)
139 EIGEN_DEVICE_FUNC
inline ReshapedImpl(XprType& xpr) : Impl(xpr) {}
140 EIGEN_DEVICE_FUNC
inline ReshapedImpl(XprType& xpr,
Index reshapeRows,
Index reshapeCols)
141 : Impl(xpr, reshapeRows, reshapeCols) {}
147 template<
typename XprType,
int Rows,
int Cols,
int Order>
148 class ReshapedImpl_dense<XprType,Rows,Cols,Order,false>
149 :
public internal::dense_xpr_base<Reshaped<XprType, Rows, Cols, Order> >::type
154 typedef typename internal::dense_xpr_base<ReshapedType>::type Base;
155 EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType)
156 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense)
158 typedef typename internal::ref_selector<XprType>::non_const_type MatrixTypeNested;
159 typedef typename internal::remove_all<XprType>::type NestedExpression;
166 inline ReshapedImpl_dense(XprType& xpr)
167 : m_xpr(xpr), m_rows(Rows), m_cols(Cols)
173 inline ReshapedImpl_dense(XprType& xpr,
Index nRows,
Index nCols)
174 : m_xpr(xpr), m_rows(nRows), m_cols(nCols)
177 EIGEN_DEVICE_FUNC
Index rows()
const {
return m_rows; }
178 EIGEN_DEVICE_FUNC
Index cols()
const {
return m_cols; }
180 #ifdef EIGEN_PARSED_BY_DOXYGEN 182 EIGEN_DEVICE_FUNC
inline const Scalar* data()
const;
183 EIGEN_DEVICE_FUNC
inline Index innerStride()
const;
184 EIGEN_DEVICE_FUNC
inline Index outerStride()
const;
189 const typename internal::remove_all<XprType>::type&
190 nestedExpression()
const {
return m_xpr; }
194 typename internal::remove_reference<XprType>::type&
195 nestedExpression() {
return m_xpr; }
199 MatrixTypeNested m_xpr;
200 const internal::variable_if_dynamic<Index, Rows> m_rows;
201 const internal::variable_if_dynamic<Index, Cols> m_cols;
206 template<
typename XprType,
int Rows,
int Cols,
int Order>
207 class ReshapedImpl_dense<XprType, Rows, Cols, Order, true>
208 :
public MapBase<Reshaped<XprType, Rows, Cols, Order> >
211 typedef typename internal::ref_selector<XprType>::non_const_type XprTypeNested;
214 typedef MapBase<ReshapedType> Base;
215 EIGEN_DENSE_PUBLIC_INTERFACE(ReshapedType)
216 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(ReshapedImpl_dense)
221 inline ReshapedImpl_dense(XprType& xpr)
222 : Base(xpr.data()), m_xpr(xpr)
228 inline ReshapedImpl_dense(XprType& xpr,
Index nRows,
Index nCols)
229 : Base(xpr.data(), nRows, nCols),
234 const typename internal::remove_all<XprTypeNested>::type& nestedExpression()
const 240 XprType& nestedExpression() {
return m_xpr; }
243 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
244 inline Index innerStride()
const 246 return m_xpr.innerStride();
250 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
251 inline Index outerStride()
const 253 return ((Flags&
RowMajorBit)==RowMajorBit) ? this->cols() : this->rows();
262 template<
typename ArgType,
int Rows,
int Cols,
int Order,
bool HasDirectAccess>
struct reshaped_evaluator;
264 template<
typename ArgType,
int Rows,
int Cols,
int Order>
265 struct evaluator<Reshaped<ArgType, Rows, Cols, Order> >
266 : reshaped_evaluator<ArgType, Rows, Cols, Order, traits<Reshaped<ArgType,Rows,Cols,Order> >::HasDirectAccess>
269 typedef typename XprType::Scalar Scalar;
271 typedef typename packet_traits<Scalar>::type PacketScalar;
274 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
275 HasDirectAccess = traits<XprType>::HasDirectAccess,
287 FlagsLinearAccessBit = (traits<XprType>::RowsAtCompileTime == 1 || traits<XprType>::ColsAtCompileTime == 1 || HasDirectAccess) ?
LinearAccessBit : 0,
288 FlagsRowMajorBit = (traits<XprType>::ReshapedStorageOrder==
int(
RowMajor)) ?
RowMajorBit : 0,
290 Flags0 = evaluator<ArgType>::Flags & (HereditaryBits & ~RowMajorBit),
291 Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit | FlagsDirectAccessBit,
293 PacketAlignment = unpacket_traits<PacketScalar>::alignment,
294 Alignment = evaluator<ArgType>::Alignment
296 typedef reshaped_evaluator<ArgType, Rows, Cols, Order, HasDirectAccess> reshaped_evaluator_type;
297 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& xpr) : reshaped_evaluator_type(xpr)
299 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
303 template<
typename ArgType,
int Rows,
int Cols,
int Order>
304 struct reshaped_evaluator<ArgType, Rows, Cols, Order, false>
305 : evaluator_base<Reshaped<ArgType, Rows, Cols, Order> >
310 CoeffReadCost = evaluator<ArgType>::CoeffReadCost ,
312 Flags = (evaluator<ArgType>::Flags & (HereditaryBits )),
317 EIGEN_DEVICE_FUNC
explicit reshaped_evaluator(
const XprType& xpr) : m_argImpl(xpr.nestedExpression()), m_xpr(xpr)
319 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
322 typedef typename XprType::Scalar Scalar;
323 typedef typename XprType::CoeffReturnType CoeffReturnType;
325 typedef std::pair<Index, Index> RowCol;
327 inline RowCol index_remap(
Index rowId,
Index colId)
const 331 const Index nth_elem_idx = colId * m_xpr.rows() + rowId;
332 return RowCol(nth_elem_idx % m_xpr.nestedExpression().rows(),
333 nth_elem_idx / m_xpr.nestedExpression().rows());
337 const Index nth_elem_idx = colId + rowId * m_xpr.cols();
338 return RowCol(nth_elem_idx / m_xpr.nestedExpression().cols(),
339 nth_elem_idx % m_xpr.nestedExpression().cols());
344 inline Scalar& coeffRef(
Index rowId,
Index colId)
346 EIGEN_STATIC_ASSERT_LVALUE(XprType)
347 const RowCol row_col = index_remap(rowId, colId);
348 return m_argImpl.coeffRef(row_col.first, row_col.second);
352 inline const Scalar& coeffRef(
Index rowId,
Index colId)
const 354 const RowCol row_col = index_remap(rowId, colId);
355 return m_argImpl.coeffRef(row_col.first, row_col.second);
359 EIGEN_STRONG_INLINE
const CoeffReturnType coeff(
Index rowId,
Index colId)
const 361 const RowCol row_col = index_remap(rowId, colId);
362 return m_argImpl.coeff(row_col.first, row_col.second);
366 inline Scalar& coeffRef(
Index index)
368 EIGEN_STATIC_ASSERT_LVALUE(XprType)
369 const RowCol row_col = index_remap(Rows == 1 ? 0 : index,
370 Rows == 1 ? index : 0);
371 return m_argImpl.coeffRef(row_col.first, row_col.second);
376 inline const Scalar& coeffRef(
Index index)
const 378 const RowCol row_col = index_remap(Rows == 1 ? 0 : index,
379 Rows == 1 ? index : 0);
380 return m_argImpl.coeffRef(row_col.first, row_col.second);
384 inline const CoeffReturnType coeff(
Index index)
const 386 const RowCol row_col = index_remap(Rows == 1 ? 0 : index,
387 Rows == 1 ? index : 0);
388 return m_argImpl.coeff(row_col.first, row_col.second);
392 template<
int LoadMode>
393 inline PacketScalar packet(
Index rowId,
Index colId)
const 395 const RowCol row_col = index_remap(rowId, colId);
396 return m_argImpl.template packet<Unaligned>(row_col.first, row_col.second);
400 template<
int LoadMode>
402 inline void writePacket(
Index rowId,
Index colId,
const PacketScalar& val)
404 const RowCol row_col = index_remap(rowId, colId);
405 m_argImpl.const_cast_derived().template writePacket<Unaligned>
406 (row_col.first, row_col.second, val);
409 template<
int LoadMode>
411 inline PacketScalar packet(
Index index)
const 413 const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index,
414 RowsAtCompileTime == 1 ? index : 0);
415 return m_argImpl.template packet<Unaligned>(row_col.first, row_col.second);
418 template<
int LoadMode>
420 inline void writePacket(
Index index,
const PacketScalar& val)
422 const RowCol row_col = index_remap(RowsAtCompileTime == 1 ? 0 : index,
423 RowsAtCompileTime == 1 ? index : 0);
424 return m_argImpl.template packet<Unaligned>(row_col.first, row_col.second, val);
429 evaluator<ArgType> m_argImpl;
430 const XprType& m_xpr;
434 template<
typename ArgType,
int Rows,
int Cols,
int Order>
435 struct reshaped_evaluator<ArgType, Rows, Cols, Order, true>
436 : mapbase_evaluator<Reshaped<ArgType, Rows, Cols, Order>,
437 typename Reshaped<ArgType, Rows, Cols, Order>::PlainObject>
440 typedef typename XprType::Scalar Scalar;
442 EIGEN_DEVICE_FUNC
explicit reshaped_evaluator(
const XprType& xpr)
443 : mapbase_evaluator<XprType, typename XprType::PlainObject>(xpr)
446 eigen_assert(((internal::UIntPtr(xpr.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) &&
"data is not aligned");
454 #endif // EIGEN_RESHAPED_H Reshaped(XprType &xpr)
Definition: Reshaped.h:109
Reshaped(XprType &xpr, Index reshapeRows, Index reshapeCols)
Definition: Reshaped.h:119
Definition: Constants.h:319
const unsigned int DirectAccessBit
Definition: Constants.h:155
const unsigned int LvalueBit
Definition: Constants.h:144
Namespace containing all symbols from the Eigen library.
Definition: Core:141
const unsigned int RowMajorBit
Definition: Constants.h:66
const unsigned int PacketAccessBit
Definition: Constants.h:94
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: Eigen_Colamd.h:50
Definition: Constants.h:321
Expression of a fixed-size or dynamic-size reshape.
Definition: Reshaped.h:96
const int Dynamic
Definition: Constants.h:22
const unsigned int LinearAccessBit
Definition: Constants.h:130