13 #ifndef EIGEN_COREEVALUATORS_H
14 #define EIGEN_COREEVALUATORS_H
22 template<
typename StorageKind>
23 struct storage_kind_to_evaluator_kind {
24 typedef IndexBased Kind;
29 template<
typename StorageKind>
struct storage_kind_to_shape;
31 template<>
struct storage_kind_to_shape<Dense> {
typedef DenseShape Shape; };
32 template<>
struct storage_kind_to_shape<PermutationStorage> {
typedef PermutationShape Shape; };
33 template<>
struct storage_kind_to_shape<TranspositionsStorage> {
typedef TranspositionsShape Shape; };
48 typename LhsKind =
typename evaluator_traits<typename T::Lhs>::Kind,
49 typename RhsKind =
typename evaluator_traits<typename T::Rhs>::Kind,
50 typename LhsScalar =
typename traits<typename T::Lhs>::Scalar,
51 typename RhsScalar =
typename traits<typename T::Rhs>::Scalar>
struct binary_evaluator;
54 typename Kind =
typename evaluator_traits<typename T::NestedExpression>::Kind,
55 typename Scalar =
typename T::Scalar>
struct unary_evaluator;
60 struct evaluator_traits_base
63 typedef typename storage_kind_to_evaluator_kind<typename traits<T>::StorageKind>::Kind Kind;
64 typedef typename storage_kind_to_shape<typename traits<T>::StorageKind>::Shape Shape;
68 static const int AssumeAliasing = 0;
73 struct evaluator_traits :
public evaluator_traits_base<T>
80 struct evaluator :
public unary_evaluator<T>
82 typedef unary_evaluator<T> Base;
83 EIGEN_DEVICE_FUNC
explicit evaluator(
const T& xpr) : Base(xpr) {}
89 struct evaluator<const T>
93 explicit evaluator(
const T& xpr) : evaluator<T>(xpr) {}
98 template<
typename ExpressionType>
99 struct evaluator_base :
public noncopyable
102 typedef typename traits<ExpressionType>::StorageIndex StorageIndex;
105 typedef traits<ExpressionType> ExpressionTraits;
119 template<
typename Derived>
120 struct evaluator<PlainObjectBase<Derived> >
121 : evaluator_base<Derived>
123 typedef PlainObjectBase<Derived> PlainObjectType;
124 typedef typename PlainObjectType::Scalar Scalar;
125 typedef typename PlainObjectType::CoeffReturnType CoeffReturnType;
128 IsRowMajor = PlainObjectType::IsRowMajor,
129 IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime,
130 RowsAtCompileTime = PlainObjectType::RowsAtCompileTime,
131 ColsAtCompileTime = PlainObjectType::ColsAtCompileTime,
133 CoeffReadCost = NumTraits<Scalar>::ReadCost,
134 Flags = traits<Derived>::EvaluatorFlags,
135 Alignment = traits<Derived>::Alignment
138 EIGEN_DEVICE_FUNC evaluator()
140 m_outerStride(IsVectorAtCompileTime ? 0
141 : int(IsRowMajor) ? ColsAtCompileTime
145 EIGEN_DEVICE_FUNC
explicit evaluator(
const PlainObjectType& m)
146 : m_data(m.data()), m_outerStride(IsVectorAtCompileTime ? 0 : m.outerStride())
149 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
152 return m_data[row * m_outerStride.value() + col];
154 return m_data[row + col * m_outerStride.value()];
157 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
159 return m_data[index];
162 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
165 return const_cast<Scalar*
>(m_data)[row * m_outerStride.value() + col];
167 return const_cast<Scalar*
>(m_data)[row + col * m_outerStride.value()];
170 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
172 return const_cast<Scalar*
>(m_data)[index];
175 template<
int LoadMode,
typename PacketType>
176 PacketType packet(Index row, Index col)
const
179 return ploadt<PacketType, LoadMode>(m_data + row * m_outerStride.value() + col);
181 return ploadt<PacketType, LoadMode>(m_data + row + col * m_outerStride.value());
184 template<
int LoadMode,
typename PacketType>
185 PacketType packet(Index index)
const
187 return ploadt<PacketType, LoadMode>(m_data + index);
190 template<
int StoreMode,
typename PacketType>
191 void writePacket(Index row, Index col,
const PacketType& x)
194 return pstoret<Scalar, PacketType, StoreMode>
195 (
const_cast<Scalar*
>(m_data) + row * m_outerStride.value() + col, x);
197 return pstoret<Scalar, PacketType, StoreMode>
198 (
const_cast<Scalar*
>(m_data) + row + col * m_outerStride.value(), x);
201 template<
int StoreMode,
typename PacketType>
202 void writePacket(Index index,
const PacketType& x)
204 return pstoret<Scalar, PacketType, StoreMode>(
const_cast<Scalar*
>(m_data) + index, x);
208 const Scalar *m_data;
211 variable_if_dynamic<Index, IsVectorAtCompileTime ? 0
212 : int(IsRowMajor) ? ColsAtCompileTime
213 : RowsAtCompileTime> m_outerStride;
216 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
217 struct evaluator<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
218 : evaluator<PlainObjectBase<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
220 typedef Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType;
222 EIGEN_DEVICE_FUNC evaluator() {}
224 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& m)
225 : evaluator<PlainObjectBase<XprType> >(m)
229 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
230 struct evaluator<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
231 : evaluator<PlainObjectBase<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
233 typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType;
235 EIGEN_DEVICE_FUNC evaluator() {}
237 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& m)
238 : evaluator<PlainObjectBase<XprType> >(m)
244 template<
typename ArgType>
245 struct unary_evaluator<Transpose<ArgType>, IndexBased>
246 : evaluator_base<Transpose<ArgType> >
248 typedef Transpose<ArgType> XprType;
251 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
253 Alignment = evaluator<ArgType>::Alignment
256 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& t) : m_argImpl(t.nestedExpression()) {}
258 typedef typename XprType::Scalar Scalar;
259 typedef typename XprType::CoeffReturnType CoeffReturnType;
261 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
263 return m_argImpl.coeff(col, row);
266 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
268 return m_argImpl.coeff(index);
271 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
273 return m_argImpl.coeffRef(col, row);
276 EIGEN_DEVICE_FUNC
typename XprType::Scalar& coeffRef(Index index)
278 return m_argImpl.coeffRef(index);
281 template<
int LoadMode,
typename PacketType>
282 PacketType packet(Index row, Index col)
const
284 return m_argImpl.template packet<LoadMode,PacketType>(col, row);
287 template<
int LoadMode,
typename PacketType>
288 PacketType packet(Index index)
const
290 return m_argImpl.template packet<LoadMode,PacketType>(index);
293 template<
int StoreMode,
typename PacketType>
294 void writePacket(Index row, Index col,
const PacketType& x)
296 m_argImpl.template writePacket<StoreMode,PacketType>(col, row, x);
299 template<
int StoreMode,
typename PacketType>
300 void writePacket(Index index,
const PacketType& x)
302 m_argImpl.template writePacket<StoreMode,PacketType>(index, x);
306 evaluator<ArgType> m_argImpl;
313 template<
typename NullaryOp,
typename PlainObjectType>
314 struct evaluator<CwiseNullaryOp<NullaryOp,PlainObjectType> >
315 : evaluator_base<CwiseNullaryOp<NullaryOp,PlainObjectType> >
317 typedef CwiseNullaryOp<NullaryOp,PlainObjectType> XprType;
318 typedef typename internal::remove_all<PlainObjectType>::type PlainObjectTypeCleaned;
321 CoeffReadCost = internal::functor_traits<NullaryOp>::Cost,
323 Flags = (evaluator<PlainObjectTypeCleaned>::Flags
331 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& n)
332 : m_functor(n.functor())
335 typedef typename XprType::CoeffReturnType CoeffReturnType;
337 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
339 return m_functor(row, col);
342 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
344 return m_functor(index);
347 template<
int LoadMode,
typename PacketType>
348 PacketType packet(Index row, Index col)
const
350 return m_functor.template packetOp<Index,PacketType>(row, col);
353 template<
int LoadMode,
typename PacketType>
354 PacketType packet(Index index)
const
356 return m_functor.template packetOp<Index,PacketType>(index);
360 const NullaryOp m_functor;
365 template<
typename UnaryOp,
typename ArgType>
366 struct unary_evaluator<CwiseUnaryOp<UnaryOp, ArgType>, IndexBased >
367 : evaluator_base<CwiseUnaryOp<UnaryOp, ArgType> >
369 typedef CwiseUnaryOp<UnaryOp, ArgType> XprType;
372 CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<UnaryOp>::Cost,
374 Flags = evaluator<ArgType>::Flags
376 Alignment = evaluator<ArgType>::Alignment
379 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& op)
380 : m_functor(op.functor()),
381 m_argImpl(op.nestedExpression())
384 typedef typename XprType::CoeffReturnType CoeffReturnType;
386 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
388 return m_functor(m_argImpl.coeff(row, col));
391 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
393 return m_functor(m_argImpl.coeff(index));
396 template<
int LoadMode,
typename PacketType>
397 PacketType packet(Index row, Index col)
const
399 return m_functor.packetOp(m_argImpl.template packet<LoadMode, PacketType>(row, col));
402 template<
int LoadMode,
typename PacketType>
403 PacketType packet(Index index)
const
405 return m_functor.packetOp(m_argImpl.template packet<LoadMode, PacketType>(index));
409 const UnaryOp m_functor;
410 evaluator<ArgType> m_argImpl;
416 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
417 struct evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
418 :
public binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
420 typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
421 typedef binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > Base;
423 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& xpr) : Base(xpr) {}
426 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
427 struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, IndexBased>
428 : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
430 typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
433 CoeffReadCost = evaluator<Lhs>::CoeffReadCost + evaluator<Rhs>::CoeffReadCost + functor_traits<BinaryOp>::Cost,
435 LhsFlags = evaluator<Lhs>::Flags,
436 RhsFlags = evaluator<Rhs>::Flags,
437 SameType = is_same<typename Lhs::Scalar,typename Rhs::Scalar>::value,
439 Flags0 = (
int(LhsFlags) | int(RhsFlags)) & (
441 | (
int(LhsFlags) &
int(RhsFlags) &
443 | (functor_traits<BinaryOp>::PacketAccess && StorageOrdersAgree && SameType ?
PacketAccessBit : 0)
448 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<Lhs>::Alignment,evaluator<Rhs>::Alignment)
451 EIGEN_DEVICE_FUNC
explicit binary_evaluator(
const XprType& xpr)
452 : m_functor(xpr.functor()),
453 m_lhsImpl(xpr.lhs()),
457 typedef typename XprType::CoeffReturnType CoeffReturnType;
459 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
461 return m_functor(m_lhsImpl.coeff(row, col), m_rhsImpl.coeff(row, col));
464 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
466 return m_functor(m_lhsImpl.coeff(index), m_rhsImpl.coeff(index));
469 template<
int LoadMode,
typename PacketType>
470 PacketType packet(Index row, Index col)
const
472 return m_functor.packetOp(m_lhsImpl.template packet<LoadMode,PacketType>(row, col),
473 m_rhsImpl.template packet<LoadMode,PacketType>(row, col));
476 template<
int LoadMode,
typename PacketType>
477 PacketType packet(Index index)
const
479 return m_functor.packetOp(m_lhsImpl.template packet<LoadMode,PacketType>(index),
480 m_rhsImpl.template packet<LoadMode,PacketType>(index));
484 const BinaryOp m_functor;
485 evaluator<Lhs> m_lhsImpl;
486 evaluator<Rhs> m_rhsImpl;
491 template<
typename UnaryOp,
typename ArgType>
492 struct unary_evaluator<CwiseUnaryView<UnaryOp, ArgType>, IndexBased>
493 : evaluator_base<CwiseUnaryView<UnaryOp, ArgType> >
495 typedef CwiseUnaryView<UnaryOp, ArgType> XprType;
498 CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<UnaryOp>::Cost,
500 Flags = (evaluator<ArgType>::Flags & (HereditaryBits | LinearAccessBit |
DirectAccessBit)),
505 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& op)
506 : m_unaryOp(op.functor()),
507 m_argImpl(op.nestedExpression())
510 typedef typename XprType::Scalar Scalar;
511 typedef typename XprType::CoeffReturnType CoeffReturnType;
513 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
515 return m_unaryOp(m_argImpl.coeff(row, col));
518 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
520 return m_unaryOp(m_argImpl.coeff(index));
523 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
525 return m_unaryOp(m_argImpl.coeffRef(row, col));
528 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
530 return m_unaryOp(m_argImpl.coeffRef(index));
534 const UnaryOp m_unaryOp;
535 evaluator<ArgType> m_argImpl;
542 template<
typename Derived,
typename PlainObjectType>
543 struct mapbase_evaluator;
545 template<
typename Derived,
typename PlainObjectType>
546 struct mapbase_evaluator : evaluator_base<Derived>
548 typedef Derived XprType;
549 typedef typename XprType::PointerType PointerType;
550 typedef typename XprType::Scalar Scalar;
551 typedef typename XprType::CoeffReturnType CoeffReturnType;
554 IsRowMajor = XprType::RowsAtCompileTime,
555 ColsAtCompileTime = XprType::ColsAtCompileTime,
556 CoeffReadCost = NumTraits<Scalar>::ReadCost
559 EIGEN_DEVICE_FUNC
explicit mapbase_evaluator(
const XprType& map)
560 : m_data(const_cast<PointerType>(map.data())),
563 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(evaluator<Derived>::Flags&PacketAccessBit, internal::inner_stride_at_compile_time<Derived>::ret==1),
564 PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
567 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
569 return m_data[col * m_xpr.colStride() + row * m_xpr.rowStride()];
572 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
574 return m_data[index * m_xpr.innerStride()];
577 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
579 return m_data[col * m_xpr.colStride() + row * m_xpr.rowStride()];
582 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
584 return m_data[index * m_xpr.innerStride()];
587 template<
int LoadMode,
typename PacketType>
588 PacketType packet(Index row, Index col)
const
590 PointerType ptr = m_data + row * m_xpr.rowStride() + col * m_xpr.colStride();
591 return internal::ploadt<PacketType, LoadMode>(ptr);
594 template<
int LoadMode,
typename PacketType>
595 PacketType packet(Index index)
const
597 return internal::ploadt<PacketType, LoadMode>(m_data + index * m_xpr.innerStride());
600 template<
int StoreMode,
typename PacketType>
601 void writePacket(Index row, Index col,
const PacketType& x)
603 PointerType ptr = m_data + row * m_xpr.rowStride() + col * m_xpr.colStride();
604 return internal::pstoret<Scalar, PacketType, StoreMode>(ptr, x);
607 template<
int StoreMode,
typename PacketType>
608 void writePacket(Index index,
const PacketType& x)
610 internal::pstoret<Scalar, PacketType, StoreMode>(m_data + index * m_xpr.innerStride(), x);
615 const XprType& m_xpr;
618 template<
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
619 struct evaluator<Map<PlainObjectType, MapOptions, StrideType> >
620 :
public mapbase_evaluator<Map<PlainObjectType, MapOptions, StrideType>, PlainObjectType>
622 typedef Map<PlainObjectType, MapOptions, StrideType> XprType;
623 typedef typename XprType::Scalar Scalar;
625 typedef typename packet_traits<Scalar>::type PacketScalar;
628 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
629 ? int(PlainObjectType::InnerStrideAtCompileTime)
630 : int(StrideType::InnerStrideAtCompileTime),
631 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
632 ? int(PlainObjectType::OuterStrideAtCompileTime)
633 : int(StrideType::OuterStrideAtCompileTime),
634 HasNoInnerStride = InnerStrideAtCompileTime == 1,
635 HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
636 HasNoStride = HasNoInnerStride && HasNoOuterStride,
637 IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic,
639 PacketAlignment = unpacket_traits<PacketScalar>::alignment,
641 KeepsPacketAccess = bool(HasNoInnerStride)
642 && ( bool(IsDynamicSize)
644 || ( OuterStrideAtCompileTime!=Dynamic
645 && ((static_cast<int>(sizeof(Scalar))*OuterStrideAtCompileTime) % PacketAlignment)==0 ) ),
646 Flags0 = evaluator<PlainObjectType>::Flags,
647 Flags1 = (bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime))
648 ? int(Flags0) : int(Flags0 & ~LinearAccessBit),
649 Flags = KeepsPacketAccess ? int(Flags1) : (int(Flags1) & ~PacketAccessBit),
651 Alignment = int(MapOptions)&int(AlignedMask)
654 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& map)
655 : mapbase_evaluator<XprType, PlainObjectType>(map)
661 template<
typename PlainObjectType,
int RefOptions,
typename Str
ideType>
662 struct evaluator<Ref<PlainObjectType, RefOptions, StrideType> >
663 :
public mapbase_evaluator<Ref<PlainObjectType, RefOptions, StrideType>, PlainObjectType>
665 typedef Ref<PlainObjectType, RefOptions, StrideType> XprType;
668 Flags = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Flags,
669 Alignment = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Alignment
672 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& ref)
673 : mapbase_evaluator<XprType, PlainObjectType>(ref)
679 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel,
680 bool HasDirectAccess = internal::has_direct_access<ArgType>::ret>
struct block_evaluator;
682 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
683 struct evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
684 : block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel>
686 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
687 typedef typename XprType::Scalar Scalar;
689 typedef typename packet_traits<Scalar>::type PacketScalar;
692 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
694 RowsAtCompileTime = traits<XprType>::RowsAtCompileTime,
695 ColsAtCompileTime = traits<XprType>::ColsAtCompileTime,
696 MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime,
697 MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime,
699 ArgTypeIsRowMajor = (int(evaluator<ArgType>::Flags)&
RowMajorBit) != 0,
700 IsRowMajor = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? 1
701 : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
703 HasSameStorageOrderAsArgType = (IsRowMajor == ArgTypeIsRowMajor),
704 InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
705 InnerStrideAtCompileTime = HasSameStorageOrderAsArgType
706 ? int(inner_stride_at_compile_time<ArgType>::ret)
707 : int(outer_stride_at_compile_time<ArgType>::ret),
708 OuterStrideAtCompileTime = HasSameStorageOrderAsArgType
709 ? int(outer_stride_at_compile_time<ArgType>::ret)
710 : int(inner_stride_at_compile_time<ArgType>::ret),
711 MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0)
712 && (InnerStrideAtCompileTime == 1)
713 ? PacketAccessBit : 0,
715 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1 || (InnerPanel && (evaluator<ArgType>::Flags&LinearAccessBit))) ? LinearAccessBit : 0,
717 Flags0 = evaluator<ArgType>::Flags & ( (HereditaryBits & ~
RowMajorBit) |
719 MaskPacketAccessBit),
720 Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit,
722 PacketAlignment = unpacket_traits<PacketScalar>::alignment,
723 Alignment0 = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % int(PacketAlignment)) == 0)) ? int(PacketAlignment) : 0,
724 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ArgType>::Alignment, Alignment0)
726 typedef block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel> block_evaluator_type;
727 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& block) : block_evaluator_type(block) {}
731 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
732 struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, false>
733 : unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
735 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
737 EIGEN_DEVICE_FUNC
explicit block_evaluator(
const XprType& block)
738 : unary_evaluator<XprType>(block)
742 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
743 struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBased>
744 : evaluator_base<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
746 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
748 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& block)
749 : m_argImpl(block.nestedExpression()),
750 m_startRow(block.startRow()),
751 m_startCol(block.startCol())
754 typedef typename XprType::Scalar Scalar;
755 typedef typename XprType::CoeffReturnType CoeffReturnType;
758 RowsAtCompileTime = XprType::RowsAtCompileTime
761 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
763 return m_argImpl.coeff(m_startRow.value() + row, m_startCol.value() + col);
766 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
768 return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
771 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
773 return m_argImpl.coeffRef(m_startRow.value() + row, m_startCol.value() + col);
776 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
778 return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
781 template<
int LoadMode,
typename PacketType>
782 PacketType packet(Index row, Index col)
const
784 return m_argImpl.template packet<LoadMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col);
787 template<
int LoadMode,
typename PacketType>
788 PacketType packet(Index index)
const
790 return packet<LoadMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
791 RowsAtCompileTime == 1 ? index : 0);
794 template<
int StoreMode,
typename PacketType>
795 void writePacket(Index row, Index col,
const PacketType& x)
797 return m_argImpl.template writePacket<StoreMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col, x);
800 template<
int StoreMode,
typename PacketType>
801 void writePacket(Index index,
const PacketType& x)
803 return writePacket<StoreMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
804 RowsAtCompileTime == 1 ? index : 0,
809 evaluator<ArgType> m_argImpl;
810 const variable_if_dynamic<Index, ArgType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
811 const variable_if_dynamic<Index, ArgType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
817 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
818 struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, true>
819 : mapbase_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>,
820 typename Block<ArgType, BlockRows, BlockCols, InnerPanel>::PlainObject>
822 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
823 typedef typename XprType::Scalar Scalar;
825 EIGEN_DEVICE_FUNC
explicit block_evaluator(
const XprType& block)
826 : mapbase_evaluator<XprType, typename XprType::PlainObject>(block)
829 eigen_assert(((
size_t(block.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) &&
"data is not aligned");
838 template<
typename ConditionMatrixType,
typename ThenMatrixType,
typename ElseMatrixType>
839 struct evaluator<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
840 : evaluator_base<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
842 typedef Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> XprType;
844 CoeffReadCost = evaluator<ConditionMatrixType>::CoeffReadCost
845 + EIGEN_SIZE_MAX(evaluator<ThenMatrixType>::CoeffReadCost,
846 evaluator<ElseMatrixType>::CoeffReadCost),
848 Flags = (
unsigned int)evaluator<ThenMatrixType>::Flags & evaluator<ElseMatrixType>::Flags & HereditaryBits,
850 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ThenMatrixType>::Alignment, evaluator<ElseMatrixType>::Alignment)
853 inline EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& select)
854 : m_conditionImpl(select.conditionMatrix()),
855 m_thenImpl(select.thenMatrix()),
856 m_elseImpl(select.elseMatrix())
859 typedef typename XprType::CoeffReturnType CoeffReturnType;
861 inline EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
863 if (m_conditionImpl.coeff(row, col))
864 return m_thenImpl.coeff(row, col);
866 return m_elseImpl.coeff(row, col);
869 inline EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
871 if (m_conditionImpl.coeff(index))
872 return m_thenImpl.coeff(index);
874 return m_elseImpl.coeff(index);
878 evaluator<ConditionMatrixType> m_conditionImpl;
879 evaluator<ThenMatrixType> m_thenImpl;
880 evaluator<ElseMatrixType> m_elseImpl;
886 template<
typename ArgType,
int RowFactor,
int ColFactor>
887 struct unary_evaluator<Replicate<ArgType, RowFactor, ColFactor> >
888 : evaluator_base<Replicate<ArgType, RowFactor, ColFactor> >
890 typedef Replicate<ArgType, RowFactor, ColFactor> XprType;
891 typedef typename XprType::CoeffReturnType CoeffReturnType;
893 Factor = (RowFactor==Dynamic || ColFactor==Dynamic) ? Dynamic : RowFactor*ColFactor
895 typedef typename internal::nested_eval<ArgType,Factor>::type ArgTypeNested;
896 typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
899 CoeffReadCost = evaluator<ArgTypeNestedCleaned>::CoeffReadCost,
901 Flags = (evaluator<ArgTypeNestedCleaned>::Flags & HereditaryBits & ~
RowMajorBit) | (traits<XprType>::Flags &
RowMajorBit),
903 Alignment = evaluator<ArgTypeNestedCleaned>::Alignment
906 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& replicate)
907 : m_arg(replicate.nestedExpression()),
909 m_rows(replicate.nestedExpression().rows()),
910 m_cols(replicate.nestedExpression().cols())
913 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
916 const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
918 : row % m_rows.value();
919 const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
921 : col % m_cols.value();
923 return m_argImpl.coeff(actual_row, actual_col);
926 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
929 const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
930 ? (ColFactor==1 ? index : index%m_cols.value())
931 : (RowFactor==1 ? index : index%m_rows.value());
933 return m_argImpl.coeff(actual_index);
936 template<
int LoadMode,
typename PacketType>
937 PacketType packet(Index row, Index col)
const
939 const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
941 : row % m_rows.value();
942 const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
944 : col % m_cols.value();
946 return m_argImpl.template packet<LoadMode,PacketType>(actual_row, actual_col);
949 template<
int LoadMode,
typename PacketType>
950 PacketType packet(Index index)
const
952 const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
953 ? (ColFactor==1 ? index : index%m_cols.value())
954 : (RowFactor==1 ? index : index%m_rows.value());
956 return m_argImpl.template packet<LoadMode,PacketType>(actual_index);
960 const ArgTypeNested m_arg;
961 evaluator<ArgTypeNestedCleaned> m_argImpl;
962 const variable_if_dynamic<Index, ArgType::RowsAtCompileTime> m_rows;
963 const variable_if_dynamic<Index, ArgType::ColsAtCompileTime> m_cols;
973 template<
typename ArgType,
typename MemberOp,
int Direction>
974 struct evaluator<PartialReduxExpr<ArgType, MemberOp, Direction> >
975 : evaluator_base<PartialReduxExpr<ArgType, MemberOp, Direction> >
977 typedef PartialReduxExpr<ArgType, MemberOp, Direction> XprType;
978 typedef typename XprType::Scalar InputScalar;
980 TraversalSize = Direction==int(
Vertical) ? int(ArgType::RowsAtCompileTime) : int(XprType::ColsAtCompileTime)
982 typedef typename MemberOp::template Cost<InputScalar,int(TraversalSize)> CostOpType;
984 CoeffReadCost = TraversalSize==Dynamic ? Dynamic
985 : TraversalSize * evaluator<ArgType>::CoeffReadCost + int(CostOpType::value),
987 Flags = (traits<XprType>::Flags&
RowMajorBit) | (evaluator<ArgType>::Flags&HereditaryBits),
992 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType expr)
996 typedef typename XprType::CoeffReturnType CoeffReturnType;
998 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
1000 return m_expr.coeff(row, col);
1003 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
1005 return m_expr.coeff(index);
1009 const XprType m_expr;
1018 template<
typename XprType>
1019 struct evaluator_wrapper_base
1020 : evaluator_base<XprType>
1022 typedef typename remove_all<typename XprType::NestedExpressionType>::type ArgType;
1024 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1025 Flags = evaluator<ArgType>::Flags,
1026 Alignment = evaluator<ArgType>::Alignment
1029 EIGEN_DEVICE_FUNC
explicit evaluator_wrapper_base(
const ArgType& arg) : m_argImpl(arg) {}
1031 typedef typename ArgType::Scalar Scalar;
1032 typedef typename ArgType::CoeffReturnType CoeffReturnType;
1034 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
1036 return m_argImpl.coeff(row, col);
1039 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
1041 return m_argImpl.coeff(index);
1044 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
1046 return m_argImpl.coeffRef(row, col);
1049 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
1051 return m_argImpl.coeffRef(index);
1054 template<
int LoadMode,
typename PacketType>
1055 PacketType packet(Index row, Index col)
const
1057 return m_argImpl.template packet<LoadMode,PacketType>(row, col);
1060 template<
int LoadMode,
typename PacketType>
1061 PacketType packet(Index index)
const
1063 return m_argImpl.template packet<LoadMode,PacketType>(index);
1066 template<
int StoreMode,
typename PacketType>
1067 void writePacket(Index row, Index col,
const PacketType& x)
1069 m_argImpl.template writePacket<StoreMode>(row, col, x);
1072 template<
int StoreMode,
typename PacketType>
1073 void writePacket(Index index,
const PacketType& x)
1075 m_argImpl.template writePacket<StoreMode>(index, x);
1079 evaluator<ArgType> m_argImpl;
1082 template<
typename TArgType>
1083 struct unary_evaluator<MatrixWrapper<TArgType> >
1084 : evaluator_wrapper_base<MatrixWrapper<TArgType> >
1086 typedef MatrixWrapper<TArgType> XprType;
1088 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& wrapper)
1089 : evaluator_wrapper_base<MatrixWrapper<TArgType> >(wrapper.nestedExpression())
1093 template<
typename TArgType>
1094 struct unary_evaluator<ArrayWrapper<TArgType> >
1095 : evaluator_wrapper_base<ArrayWrapper<TArgType> >
1097 typedef ArrayWrapper<TArgType> XprType;
1099 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& wrapper)
1100 : evaluator_wrapper_base<ArrayWrapper<TArgType> >(wrapper.nestedExpression())
1108 template<
typename PacketType,
bool ReversePacket>
struct reverse_packet_cond;
1110 template<
typename ArgType,
int Direction>
1111 struct unary_evaluator<Reverse<ArgType, Direction> >
1112 : evaluator_base<Reverse<ArgType, Direction> >
1114 typedef Reverse<ArgType, Direction> XprType;
1115 typedef typename XprType::Scalar Scalar;
1116 typedef typename XprType::CoeffReturnType CoeffReturnType;
1119 IsRowMajor = XprType::IsRowMajor,
1120 IsColMajor = !IsRowMajor,
1124 || ((Direction ==
Vertical) && IsColMajor)
1125 || ((Direction ==
Horizontal) && IsRowMajor),
1127 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1131 Flags0 = evaluator<ArgType>::Flags,
1133 ? LinearAccessBit : 0,
1135 Flags = int(Flags0) & (HereditaryBits | PacketAccessBit | LinearAccess),
1140 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& reverse)
1141 : m_argImpl(reverse.nestedExpression()),
1142 m_rows(ReverseRow ? reverse.nestedExpression().rows() : 0),
1143 m_cols(ReverseCol ? reverse.nestedExpression().cols() : 0)
1146 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
1148 return m_argImpl.coeff(ReverseRow ? m_rows.value() - row - 1 : row,
1149 ReverseCol ? m_cols.value() - col - 1 : col);
1152 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
1154 return m_argImpl.coeff(m_rows.value() * m_cols.value() - index - 1);
1157 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
1159 return m_argImpl.coeffRef(ReverseRow ? m_rows.value() - row - 1 : row,
1160 ReverseCol ? m_cols.value() - col - 1 : col);
1163 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
1165 return m_argImpl.coeffRef(m_rows.value() * m_cols.value() - index - 1);
1168 template<
int LoadMode,
typename PacketType>
1169 PacketType packet(Index row, Index col)
const
1172 PacketSize = unpacket_traits<PacketType>::size,
1173 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1174 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1176 typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet;
1177 return reverse_packet::run(m_argImpl.template packet<LoadMode,PacketType>(
1178 ReverseRow ? m_rows.value() - row - OffsetRow : row,
1179 ReverseCol ? m_cols.value() - col - OffsetCol : col));
1182 template<
int LoadMode,
typename PacketType>
1183 PacketType packet(Index index)
const
1185 enum { PacketSize = unpacket_traits<PacketType>::size };
1186 return preverse(m_argImpl.template packet<LoadMode,PacketType>(m_rows.value() * m_cols.value() - index - PacketSize));
1189 template<
int LoadMode,
typename PacketType>
1190 void writePacket(Index row, Index col,
const PacketType& x)
1194 PacketSize = unpacket_traits<PacketType>::size,
1195 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1196 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1198 typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet;
1199 m_argImpl.template writePacket<LoadMode>(
1200 ReverseRow ? m_rows.value() - row - OffsetRow : row,
1201 ReverseCol ? m_cols.value() - col - OffsetCol : col,
1202 reverse_packet::run(x));
1205 template<
int LoadMode,
typename PacketType>
1206 void writePacket(Index index,
const PacketType& x)
1208 enum { PacketSize = unpacket_traits<PacketType>::size };
1209 m_argImpl.template writePacket<LoadMode>
1210 (m_rows.value() * m_cols.value() - index - PacketSize, preverse(x));
1214 evaluator<ArgType> m_argImpl;
1217 const variable_if_dynamic<Index, ReverseRow ? ArgType::RowsAtCompileTime : 0> m_rows;
1218 const variable_if_dynamic<Index, ReverseCol ? ArgType::ColsAtCompileTime : 0> m_cols;
1224 template<
typename ArgType,
int DiagIndex>
1225 struct evaluator<Diagonal<ArgType, DiagIndex> >
1226 : evaluator_base<Diagonal<ArgType, DiagIndex> >
1228 typedef Diagonal<ArgType, DiagIndex> XprType;
1231 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1238 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& diagonal)
1239 : m_argImpl(diagonal.nestedExpression()),
1240 m_index(diagonal.index())
1243 typedef typename XprType::Scalar Scalar;
1245 typedef typename internal::conditional<!internal::is_same<typename ArgType::StorageKind,Sparse>::value,
1246 typename XprType::CoeffReturnType,Scalar>::type CoeffReturnType;
1248 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index)
const
1250 return m_argImpl.coeff(row + rowOffset(), row + colOffset());
1253 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
1255 return m_argImpl.coeff(index + rowOffset(), index + colOffset());
1258 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index)
1260 return m_argImpl.coeffRef(row + rowOffset(), row + colOffset());
1263 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
1265 return m_argImpl.coeffRef(index + rowOffset(), index + colOffset());
1269 evaluator<ArgType> m_argImpl;
1270 const internal::variable_if_dynamicindex<Index, XprType::DiagIndex> m_index;
1273 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowOffset()
const {
return m_index.value() > 0 ? 0 : -m_index.value(); }
1274 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colOffset()
const {
return m_index.value() > 0 ? m_index.value() : 0; }
1286 template<
typename ArgType>
class EvalToTemp;
1288 template<
typename ArgType>
1289 struct traits<EvalToTemp<ArgType> >
1290 :
public traits<ArgType>
1293 template<
typename ArgType>
1295 :
public dense_xpr_base<EvalToTemp<ArgType> >::type
1299 typedef typename dense_xpr_base<EvalToTemp>::type Base;
1300 EIGEN_GENERIC_PUBLIC_INTERFACE(EvalToTemp)
1302 explicit EvalToTemp(const ArgType& arg)
1306 const ArgType& arg()
const
1313 return m_arg.rows();
1318 return m_arg.cols();
1322 const ArgType& m_arg;
1325 template<
typename ArgType>
1326 struct evaluator<EvalToTemp<ArgType> >
1327 :
public evaluator<typename ArgType::PlainObject>
1329 typedef EvalToTemp<ArgType> XprType;
1330 typedef typename ArgType::PlainObject PlainObject;
1331 typedef evaluator<PlainObject> Base;
1333 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& xpr)
1334 : m_result(xpr.rows(), xpr.cols())
1336 ::new (static_cast<Base*>(
this)) Base(m_result);
1338 call_dense_assignment_loop(m_result, xpr.arg());
1342 EIGEN_DEVICE_FUNC evaluator(const ArgType& arg)
1343 : m_result(arg.rows(), arg.cols())
1345 ::new (static_cast<Base*>(
this)) Base(m_result);
1347 call_dense_assignment_loop(m_result, arg);
1351 PlainObject m_result;
1358 #endif // EIGEN_COREEVALUATORS_H
Definition: Constants.h:257
const unsigned int DirectAccessBit
Definition: Constants.h:141
const unsigned int RowMajorBit
Definition: Constants.h:53
const unsigned int PacketAccessBit
Definition: Constants.h:80
Definition: Constants.h:260
Definition: Constants.h:263
Definition: Eigen_Colamd.h:54
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:57
const unsigned int LinearAccessBit
Definition: Constants.h:116