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<SolverStorage> {
typedef SolverShape Shape; };
33 template<>
struct storage_kind_to_shape<PermutationStorage> {
typedef PermutationShape Shape; };
34 template<>
struct storage_kind_to_shape<TranspositionsStorage> {
typedef TranspositionsShape Shape; };
49 typename LhsKind =
typename evaluator_traits<typename T::Lhs>::Kind,
50 typename RhsKind =
typename evaluator_traits<typename T::Rhs>::Kind,
51 typename LhsScalar =
typename traits<typename T::Lhs>::Scalar,
52 typename RhsScalar =
typename traits<typename T::Rhs>::Scalar>
struct binary_evaluator;
55 typename Kind =
typename evaluator_traits<typename T::NestedExpression>::Kind,
56 typename Scalar =
typename T::Scalar>
struct unary_evaluator;
61 struct evaluator_traits_base
64 typedef typename storage_kind_to_evaluator_kind<typename traits<T>::StorageKind>::Kind Kind;
65 typedef typename storage_kind_to_shape<typename traits<T>::StorageKind>::Shape Shape;
69 static const int AssumeAliasing = 0;
74 struct evaluator_traits :
public evaluator_traits_base<T>
81 struct evaluator :
public unary_evaluator<T>
83 typedef unary_evaluator<T> Base;
84 EIGEN_DEVICE_FUNC
explicit evaluator(
const T& xpr) : Base(xpr) {}
90 struct evaluator<const T>
94 explicit evaluator(
const T& xpr) : evaluator<T>(xpr) {}
99 template<
typename ExpressionType>
100 struct evaluator_base :
public noncopyable
103 typedef traits<ExpressionType> ExpressionTraits;
117 template<
typename Derived>
118 struct evaluator<PlainObjectBase<Derived> >
119 : evaluator_base<Derived>
121 typedef PlainObjectBase<Derived> PlainObjectType;
122 typedef typename PlainObjectType::Scalar Scalar;
123 typedef typename PlainObjectType::CoeffReturnType CoeffReturnType;
126 IsRowMajor = PlainObjectType::IsRowMajor,
127 IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime,
128 RowsAtCompileTime = PlainObjectType::RowsAtCompileTime,
129 ColsAtCompileTime = PlainObjectType::ColsAtCompileTime,
131 CoeffReadCost = NumTraits<Scalar>::ReadCost,
132 Flags = traits<Derived>::EvaluatorFlags,
133 Alignment = traits<Derived>::Alignment
136 EIGEN_DEVICE_FUNC evaluator()
138 m_outerStride(IsVectorAtCompileTime ? 0
139 : int(IsRowMajor) ? ColsAtCompileTime
142 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
145 EIGEN_DEVICE_FUNC
explicit evaluator(
const PlainObjectType& m)
146 : m_data(m.data()), m_outerStride(IsVectorAtCompileTime ? 0 : m.outerStride())
148 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
151 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
154 return m_data[row * m_outerStride.value() + col];
156 return m_data[row + col * m_outerStride.value()];
159 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
161 return m_data[index];
164 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
167 return const_cast<Scalar*
>(m_data)[row * m_outerStride.value() + col];
169 return const_cast<Scalar*
>(m_data)[row + col * m_outerStride.value()];
172 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
174 return const_cast<Scalar*
>(m_data)[index];
177 template<
int LoadMode,
typename PacketType>
178 PacketType packet(Index row, Index col)
const
181 return ploadt<PacketType, LoadMode>(m_data + row * m_outerStride.value() + col);
183 return ploadt<PacketType, LoadMode>(m_data + row + col * m_outerStride.value());
186 template<
int LoadMode,
typename PacketType>
187 PacketType packet(Index index)
const
189 return ploadt<PacketType, LoadMode>(m_data + index);
192 template<
int StoreMode,
typename PacketType>
193 void writePacket(Index row, Index col,
const PacketType& x)
196 return pstoret<Scalar, PacketType, StoreMode>
197 (
const_cast<Scalar*
>(m_data) + row * m_outerStride.value() + col, x);
199 return pstoret<Scalar, PacketType, StoreMode>
200 (
const_cast<Scalar*
>(m_data) + row + col * m_outerStride.value(), x);
203 template<
int StoreMode,
typename PacketType>
204 void writePacket(Index index,
const PacketType& x)
206 return pstoret<Scalar, PacketType, StoreMode>(
const_cast<Scalar*
>(m_data) + index, x);
210 const Scalar *m_data;
213 variable_if_dynamic<Index, IsVectorAtCompileTime ? 0
214 : int(IsRowMajor) ? ColsAtCompileTime
215 : RowsAtCompileTime> m_outerStride;
218 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
219 struct evaluator<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
220 : evaluator<PlainObjectBase<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
222 typedef Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType;
224 EIGEN_DEVICE_FUNC evaluator() {}
226 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& m)
227 : evaluator<PlainObjectBase<XprType> >(m)
231 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
232 struct evaluator<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
233 : evaluator<PlainObjectBase<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
235 typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType;
237 EIGEN_DEVICE_FUNC evaluator() {}
239 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& m)
240 : evaluator<PlainObjectBase<XprType> >(m)
246 template<
typename ArgType>
247 struct unary_evaluator<Transpose<ArgType>, IndexBased>
248 : evaluator_base<Transpose<ArgType> >
250 typedef Transpose<ArgType> XprType;
253 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
255 Alignment = evaluator<ArgType>::Alignment
258 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& t) : m_argImpl(t.nestedExpression()) {}
260 typedef typename XprType::Scalar Scalar;
261 typedef typename XprType::CoeffReturnType CoeffReturnType;
263 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
265 return m_argImpl.coeff(col, row);
268 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
270 return m_argImpl.coeff(index);
273 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
275 return m_argImpl.coeffRef(col, row);
278 EIGEN_DEVICE_FUNC
typename XprType::Scalar& coeffRef(Index index)
280 return m_argImpl.coeffRef(index);
283 template<
int LoadMode,
typename PacketType>
284 PacketType packet(Index row, Index col)
const
286 return m_argImpl.template packet<LoadMode,PacketType>(col, row);
289 template<
int LoadMode,
typename PacketType>
290 PacketType packet(Index index)
const
292 return m_argImpl.template packet<LoadMode,PacketType>(index);
295 template<
int StoreMode,
typename PacketType>
296 void writePacket(Index row, Index col,
const PacketType& x)
298 m_argImpl.template writePacket<StoreMode,PacketType>(col, row, x);
301 template<
int StoreMode,
typename PacketType>
302 void writePacket(Index index,
const PacketType& x)
304 m_argImpl.template writePacket<StoreMode,PacketType>(index, x);
308 evaluator<ArgType> m_argImpl;
315 template<
typename NullaryOp,
typename PlainObjectType>
316 struct evaluator<CwiseNullaryOp<NullaryOp,PlainObjectType> >
317 : evaluator_base<CwiseNullaryOp<NullaryOp,PlainObjectType> >
319 typedef CwiseNullaryOp<NullaryOp,PlainObjectType> XprType;
320 typedef typename internal::remove_all<PlainObjectType>::type PlainObjectTypeCleaned;
323 CoeffReadCost = internal::functor_traits<NullaryOp>::Cost,
325 Flags = (evaluator<PlainObjectTypeCleaned>::Flags
330 Alignment = AlignedMax
333 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& n)
334 : m_functor(n.functor())
336 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
339 typedef typename XprType::CoeffReturnType CoeffReturnType;
341 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
343 return m_functor(row, col);
346 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
348 return m_functor(index);
351 template<
int LoadMode,
typename PacketType>
352 PacketType packet(Index row, Index col)
const
354 return m_functor.template packetOp<Index,PacketType>(row, col);
357 template<
int LoadMode,
typename PacketType>
358 PacketType packet(Index index)
const
360 return m_functor.template packetOp<Index,PacketType>(index);
364 const NullaryOp m_functor;
369 template<
typename UnaryOp,
typename ArgType>
370 struct unary_evaluator<CwiseUnaryOp<UnaryOp, ArgType>, IndexBased >
371 : evaluator_base<CwiseUnaryOp<UnaryOp, ArgType> >
373 typedef CwiseUnaryOp<UnaryOp, ArgType> XprType;
376 CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<UnaryOp>::Cost,
378 Flags = evaluator<ArgType>::Flags
380 Alignment = evaluator<ArgType>::Alignment
383 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& op)
384 : m_functor(op.functor()),
385 m_argImpl(op.nestedExpression())
387 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
388 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
391 typedef typename XprType::CoeffReturnType CoeffReturnType;
393 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
395 return m_functor(m_argImpl.coeff(row, col));
398 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
400 return m_functor(m_argImpl.coeff(index));
403 template<
int LoadMode,
typename PacketType>
404 PacketType packet(Index row, Index col)
const
406 return m_functor.packetOp(m_argImpl.template packet<LoadMode, PacketType>(row, col));
409 template<
int LoadMode,
typename PacketType>
410 PacketType packet(Index index)
const
412 return m_functor.packetOp(m_argImpl.template packet<LoadMode, PacketType>(index));
416 const UnaryOp m_functor;
417 evaluator<ArgType> m_argImpl;
423 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
424 struct evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
425 :
public binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
427 typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
428 typedef binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > Base;
430 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& xpr) : Base(xpr) {}
433 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
434 struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, IndexBased>
435 : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
437 typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
440 CoeffReadCost = evaluator<Lhs>::CoeffReadCost + evaluator<Rhs>::CoeffReadCost + functor_traits<BinaryOp>::Cost,
442 LhsFlags = evaluator<Lhs>::Flags,
443 RhsFlags = evaluator<Rhs>::Flags,
444 SameType = is_same<typename Lhs::Scalar,typename Rhs::Scalar>::value,
446 Flags0 = (
int(LhsFlags) | int(RhsFlags)) & (
448 | (
int(LhsFlags) &
int(RhsFlags) &
450 | (functor_traits<BinaryOp>::PacketAccess && StorageOrdersAgree && SameType ?
PacketAccessBit : 0)
455 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<Lhs>::Alignment,evaluator<Rhs>::Alignment)
458 EIGEN_DEVICE_FUNC
explicit binary_evaluator(
const XprType& xpr)
459 : m_functor(xpr.functor()),
460 m_lhsImpl(xpr.lhs()),
463 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost);
464 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
467 typedef typename XprType::CoeffReturnType CoeffReturnType;
469 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
471 return m_functor(m_lhsImpl.coeff(row, col), m_rhsImpl.coeff(row, col));
474 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
476 return m_functor(m_lhsImpl.coeff(index), m_rhsImpl.coeff(index));
479 template<
int LoadMode,
typename PacketType>
480 PacketType packet(Index row, Index col)
const
482 return m_functor.packetOp(m_lhsImpl.template packet<LoadMode,PacketType>(row, col),
483 m_rhsImpl.template packet<LoadMode,PacketType>(row, col));
486 template<
int LoadMode,
typename PacketType>
487 PacketType packet(Index index)
const
489 return m_functor.packetOp(m_lhsImpl.template packet<LoadMode,PacketType>(index),
490 m_rhsImpl.template packet<LoadMode,PacketType>(index));
494 const BinaryOp m_functor;
495 evaluator<Lhs> m_lhsImpl;
496 evaluator<Rhs> m_rhsImpl;
501 template<
typename UnaryOp,
typename ArgType>
502 struct unary_evaluator<CwiseUnaryView<UnaryOp, ArgType>, IndexBased>
503 : evaluator_base<CwiseUnaryView<UnaryOp, ArgType> >
505 typedef CwiseUnaryView<UnaryOp, ArgType> XprType;
508 CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<UnaryOp>::Cost,
510 Flags = (evaluator<ArgType>::Flags & (HereditaryBits | LinearAccessBit |
DirectAccessBit)),
515 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& op)
516 : m_unaryOp(op.functor()),
517 m_argImpl(op.nestedExpression())
519 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
520 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
523 typedef typename XprType::Scalar Scalar;
524 typedef typename XprType::CoeffReturnType CoeffReturnType;
526 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
528 return m_unaryOp(m_argImpl.coeff(row, col));
531 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
533 return m_unaryOp(m_argImpl.coeff(index));
536 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
538 return m_unaryOp(m_argImpl.coeffRef(row, col));
541 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
543 return m_unaryOp(m_argImpl.coeffRef(index));
547 const UnaryOp m_unaryOp;
548 evaluator<ArgType> m_argImpl;
555 template<
typename Derived,
typename PlainObjectType>
556 struct mapbase_evaluator;
558 template<
typename Derived,
typename PlainObjectType>
559 struct mapbase_evaluator : evaluator_base<Derived>
561 typedef Derived XprType;
562 typedef typename XprType::PointerType PointerType;
563 typedef typename XprType::Scalar Scalar;
564 typedef typename XprType::CoeffReturnType CoeffReturnType;
567 IsRowMajor = XprType::RowsAtCompileTime,
568 ColsAtCompileTime = XprType::ColsAtCompileTime,
569 CoeffReadCost = NumTraits<Scalar>::ReadCost
572 EIGEN_DEVICE_FUNC
explicit mapbase_evaluator(
const XprType& map)
573 : m_data(const_cast<PointerType>(map.data())),
576 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(evaluator<Derived>::Flags&PacketAccessBit, internal::inner_stride_at_compile_time<Derived>::ret==1),
577 PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
578 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
581 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
583 return m_data[col * m_xpr.colStride() + row * m_xpr.rowStride()];
586 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
588 return m_data[index * m_xpr.innerStride()];
591 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
593 return m_data[col * m_xpr.colStride() + row * m_xpr.rowStride()];
596 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
598 return m_data[index * m_xpr.innerStride()];
601 template<
int LoadMode,
typename PacketType>
602 PacketType packet(Index row, Index col)
const
604 PointerType ptr = m_data + row * m_xpr.rowStride() + col * m_xpr.colStride();
605 return internal::ploadt<PacketType, LoadMode>(ptr);
608 template<
int LoadMode,
typename PacketType>
609 PacketType packet(Index index)
const
611 return internal::ploadt<PacketType, LoadMode>(m_data + index * m_xpr.innerStride());
614 template<
int StoreMode,
typename PacketType>
615 void writePacket(Index row, Index col,
const PacketType& x)
617 PointerType ptr = m_data + row * m_xpr.rowStride() + col * m_xpr.colStride();
618 return internal::pstoret<Scalar, PacketType, StoreMode>(ptr, x);
621 template<
int StoreMode,
typename PacketType>
622 void writePacket(Index index,
const PacketType& x)
624 internal::pstoret<Scalar, PacketType, StoreMode>(m_data + index * m_xpr.innerStride(), x);
629 const XprType& m_xpr;
632 template<
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
633 struct evaluator<Map<PlainObjectType, MapOptions, StrideType> >
634 :
public mapbase_evaluator<Map<PlainObjectType, MapOptions, StrideType>, PlainObjectType>
636 typedef Map<PlainObjectType, MapOptions, StrideType> XprType;
637 typedef typename XprType::Scalar Scalar;
639 typedef typename packet_traits<Scalar>::type PacketScalar;
642 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
643 ? int(PlainObjectType::InnerStrideAtCompileTime)
644 : int(StrideType::InnerStrideAtCompileTime),
645 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
646 ? int(PlainObjectType::OuterStrideAtCompileTime)
647 : int(StrideType::OuterStrideAtCompileTime),
648 HasNoInnerStride = InnerStrideAtCompileTime == 1,
649 HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
650 HasNoStride = HasNoInnerStride && HasNoOuterStride,
651 IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic,
653 PacketAccessMask = bool(HasNoInnerStride) ? ~int(0) : ~int(PacketAccessBit),
654 LinearAccessMask = bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime) ? ~int(0) : ~int(LinearAccessBit),
655 Flags = int( evaluator<PlainObjectType>::Flags) & (LinearAccessMask&PacketAccessMask),
657 Alignment = int(MapOptions)&int(AlignedMask)
660 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& map)
661 : mapbase_evaluator<XprType, PlainObjectType>(map)
667 template<
typename PlainObjectType,
int RefOptions,
typename Str
ideType>
668 struct evaluator<Ref<PlainObjectType, RefOptions, StrideType> >
669 :
public mapbase_evaluator<Ref<PlainObjectType, RefOptions, StrideType>, PlainObjectType>
671 typedef Ref<PlainObjectType, RefOptions, StrideType> XprType;
674 Flags = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Flags,
675 Alignment = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Alignment
678 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& ref)
679 : mapbase_evaluator<XprType, PlainObjectType>(ref)
685 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel,
686 bool HasDirectAccess = internal::has_direct_access<ArgType>::ret>
struct block_evaluator;
688 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
689 struct evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
690 : block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel>
692 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
693 typedef typename XprType::Scalar Scalar;
695 typedef typename packet_traits<Scalar>::type PacketScalar;
698 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
700 RowsAtCompileTime = traits<XprType>::RowsAtCompileTime,
701 ColsAtCompileTime = traits<XprType>::ColsAtCompileTime,
702 MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime,
703 MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime,
705 ArgTypeIsRowMajor = (int(evaluator<ArgType>::Flags)&
RowMajorBit) != 0,
706 IsRowMajor = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? 1
707 : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
709 HasSameStorageOrderAsArgType = (IsRowMajor == ArgTypeIsRowMajor),
710 InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
711 InnerStrideAtCompileTime = HasSameStorageOrderAsArgType
712 ? int(inner_stride_at_compile_time<ArgType>::ret)
713 : int(outer_stride_at_compile_time<ArgType>::ret),
714 OuterStrideAtCompileTime = HasSameStorageOrderAsArgType
715 ? int(outer_stride_at_compile_time<ArgType>::ret)
716 : int(inner_stride_at_compile_time<ArgType>::ret),
717 MaskPacketAccessBit = (InnerSize == Dynamic || (InnerSize % packet_traits<Scalar>::size) == 0)
718 && (InnerStrideAtCompileTime == 1)
719 ? PacketAccessBit : 0,
721 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1 || (InnerPanel && (evaluator<ArgType>::Flags&LinearAccessBit))) ? LinearAccessBit : 0,
723 Flags0 = evaluator<ArgType>::Flags & ( (HereditaryBits & ~
RowMajorBit) |
725 MaskPacketAccessBit),
726 Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit,
728 PacketAlignment = unpacket_traits<PacketScalar>::alignment,
729 Alignment0 = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic) && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % int(PacketAlignment)) == 0)) ? int(PacketAlignment) : 0,
730 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ArgType>::Alignment, Alignment0)
732 typedef block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel> block_evaluator_type;
733 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& block) : block_evaluator_type(block)
735 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
740 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
741 struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, false>
742 : unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
744 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
746 EIGEN_DEVICE_FUNC
explicit block_evaluator(
const XprType& block)
747 : unary_evaluator<XprType>(block)
751 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
752 struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBased>
753 : evaluator_base<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
755 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
757 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& block)
758 : m_argImpl(block.nestedExpression()),
759 m_startRow(block.startRow()),
760 m_startCol(block.startCol())
763 typedef typename XprType::Scalar Scalar;
764 typedef typename XprType::CoeffReturnType CoeffReturnType;
767 RowsAtCompileTime = XprType::RowsAtCompileTime
770 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
772 return m_argImpl.coeff(m_startRow.value() + row, m_startCol.value() + col);
775 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
777 return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
780 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
782 return m_argImpl.coeffRef(m_startRow.value() + row, m_startCol.value() + col);
785 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
787 return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
790 template<
int LoadMode,
typename PacketType>
791 PacketType packet(Index row, Index col)
const
793 return m_argImpl.template packet<LoadMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col);
796 template<
int LoadMode,
typename PacketType>
797 PacketType packet(Index index)
const
799 return packet<LoadMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
800 RowsAtCompileTime == 1 ? index : 0);
803 template<
int StoreMode,
typename PacketType>
804 void writePacket(Index row, Index col,
const PacketType& x)
806 return m_argImpl.template writePacket<StoreMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col, x);
809 template<
int StoreMode,
typename PacketType>
810 void writePacket(Index index,
const PacketType& x)
812 return writePacket<StoreMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
813 RowsAtCompileTime == 1 ? index : 0,
818 evaluator<ArgType> m_argImpl;
819 const variable_if_dynamic<Index, ArgType::RowsAtCompileTime == 1 ? 0 : Dynamic> m_startRow;
820 const variable_if_dynamic<Index, ArgType::ColsAtCompileTime == 1 ? 0 : Dynamic> m_startCol;
826 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
827 struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, true>
828 : mapbase_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>,
829 typename Block<ArgType, BlockRows, BlockCols, InnerPanel>::PlainObject>
831 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
832 typedef typename XprType::Scalar Scalar;
834 EIGEN_DEVICE_FUNC
explicit block_evaluator(
const XprType& block)
835 : mapbase_evaluator<XprType, typename XprType::PlainObject>(block)
838 eigen_assert(((
size_t(block.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) &&
"data is not aligned");
847 template<
typename ConditionMatrixType,
typename ThenMatrixType,
typename ElseMatrixType>
848 struct evaluator<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
849 : evaluator_base<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
851 typedef Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> XprType;
853 CoeffReadCost = evaluator<ConditionMatrixType>::CoeffReadCost
854 + EIGEN_PLAIN_ENUM_MAX(evaluator<ThenMatrixType>::CoeffReadCost,
855 evaluator<ElseMatrixType>::CoeffReadCost),
857 Flags = (
unsigned int)evaluator<ThenMatrixType>::Flags & evaluator<ElseMatrixType>::Flags & HereditaryBits,
859 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ThenMatrixType>::Alignment, evaluator<ElseMatrixType>::Alignment)
862 inline EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& select)
863 : m_conditionImpl(select.conditionMatrix()),
864 m_thenImpl(select.thenMatrix()),
865 m_elseImpl(select.elseMatrix())
867 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
870 typedef typename XprType::CoeffReturnType CoeffReturnType;
872 inline EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
874 if (m_conditionImpl.coeff(row, col))
875 return m_thenImpl.coeff(row, col);
877 return m_elseImpl.coeff(row, col);
880 inline EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
882 if (m_conditionImpl.coeff(index))
883 return m_thenImpl.coeff(index);
885 return m_elseImpl.coeff(index);
889 evaluator<ConditionMatrixType> m_conditionImpl;
890 evaluator<ThenMatrixType> m_thenImpl;
891 evaluator<ElseMatrixType> m_elseImpl;
897 template<
typename ArgType,
int RowFactor,
int ColFactor>
898 struct unary_evaluator<Replicate<ArgType, RowFactor, ColFactor> >
899 : evaluator_base<Replicate<ArgType, RowFactor, ColFactor> >
901 typedef Replicate<ArgType, RowFactor, ColFactor> XprType;
902 typedef typename XprType::CoeffReturnType CoeffReturnType;
904 Factor = (RowFactor==Dynamic || ColFactor==Dynamic) ? Dynamic : RowFactor*ColFactor
906 typedef typename internal::nested_eval<ArgType,Factor>::type ArgTypeNested;
907 typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
910 CoeffReadCost = evaluator<ArgTypeNestedCleaned>::CoeffReadCost,
911 LinearAccessMask = XprType::IsVectorAtCompileTime ? LinearAccessBit : 0,
912 Flags = (evaluator<ArgTypeNestedCleaned>::Flags & (HereditaryBits|LinearAccessMask) & ~
RowMajorBit) | (traits<XprType>::Flags &
RowMajorBit),
914 Alignment = evaluator<ArgTypeNestedCleaned>::Alignment
917 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& replicate)
918 : m_arg(replicate.nestedExpression()),
920 m_rows(replicate.nestedExpression().rows()),
921 m_cols(replicate.nestedExpression().cols())
924 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
927 const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
929 : row % m_rows.value();
930 const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
932 : col % m_cols.value();
934 return m_argImpl.coeff(actual_row, actual_col);
937 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
940 const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
941 ? (ColFactor==1 ? index : index%m_cols.value())
942 : (RowFactor==1 ? index : index%m_rows.value());
944 return m_argImpl.coeff(actual_index);
947 template<
int LoadMode,
typename PacketType>
948 PacketType packet(Index row, Index col)
const
950 const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
952 : row % m_rows.value();
953 const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
955 : col % m_cols.value();
957 return m_argImpl.template packet<LoadMode,PacketType>(actual_row, actual_col);
960 template<
int LoadMode,
typename PacketType>
961 PacketType packet(Index index)
const
963 const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
964 ? (ColFactor==1 ? index : index%m_cols.value())
965 : (RowFactor==1 ? index : index%m_rows.value());
967 return m_argImpl.template packet<LoadMode,PacketType>(actual_index);
971 const ArgTypeNested m_arg;
972 evaluator<ArgTypeNestedCleaned> m_argImpl;
973 const variable_if_dynamic<Index, ArgType::RowsAtCompileTime> m_rows;
974 const variable_if_dynamic<Index, ArgType::ColsAtCompileTime> m_cols;
980 template<
typename ArgType,
typename MemberOp,
int Direction>
981 struct evaluator<PartialReduxExpr<ArgType, MemberOp, Direction> >
982 : evaluator_base<PartialReduxExpr<ArgType, MemberOp, Direction> >
984 typedef PartialReduxExpr<ArgType, MemberOp, Direction> XprType;
985 typedef typename internal::nested_eval<ArgType,1>::type ArgTypeNested;
986 typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
987 typedef typename ArgType::Scalar InputScalar;
988 typedef typename XprType::Scalar Scalar;
990 TraversalSize = Direction==int(
Vertical) ? int(ArgType::RowsAtCompileTime) : int(ArgType::ColsAtCompileTime)
992 typedef typename MemberOp::template Cost<InputScalar,int(TraversalSize)> CostOpType;
994 CoeffReadCost = TraversalSize==Dynamic ? HugeCost
995 : TraversalSize * evaluator<ArgType>::CoeffReadCost + int(CostOpType::value),
997 Flags = (traits<XprType>::Flags&
RowMajorBit) | (evaluator<ArgType>::Flags&(HereditaryBits&(~
RowMajorBit))),
1002 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType xpr)
1003 : m_arg(xpr.nestedExpression()), m_functor(xpr.functor())
1005 EIGEN_INTERNAL_CHECK_COST_VALUE(TraversalSize==Dynamic ? HugeCost :
int(CostOpType::value));
1006 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
1009 typedef typename XprType::CoeffReturnType CoeffReturnType;
1011 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar coeff(Index i, Index j)
const
1014 return m_functor(m_arg.col(j));
1016 return m_functor(m_arg.row(i));
1019 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Scalar coeff(Index index)
const
1022 return m_functor(m_arg.col(index));
1024 return m_functor(m_arg.row(index));
1028 const ArgTypeNested m_arg;
1029 const MemberOp m_functor;
1038 template<
typename XprType>
1039 struct evaluator_wrapper_base
1040 : evaluator_base<XprType>
1042 typedef typename remove_all<typename XprType::NestedExpressionType>::type ArgType;
1044 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1045 Flags = evaluator<ArgType>::Flags,
1046 Alignment = evaluator<ArgType>::Alignment
1049 EIGEN_DEVICE_FUNC
explicit evaluator_wrapper_base(
const ArgType& arg) : m_argImpl(arg) {}
1051 typedef typename ArgType::Scalar Scalar;
1052 typedef typename ArgType::CoeffReturnType CoeffReturnType;
1054 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
1056 return m_argImpl.coeff(row, col);
1059 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
1061 return m_argImpl.coeff(index);
1064 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
1066 return m_argImpl.coeffRef(row, col);
1069 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
1071 return m_argImpl.coeffRef(index);
1074 template<
int LoadMode,
typename PacketType>
1075 PacketType packet(Index row, Index col)
const
1077 return m_argImpl.template packet<LoadMode,PacketType>(row, col);
1080 template<
int LoadMode,
typename PacketType>
1081 PacketType packet(Index index)
const
1083 return m_argImpl.template packet<LoadMode,PacketType>(index);
1086 template<
int StoreMode,
typename PacketType>
1087 void writePacket(Index row, Index col,
const PacketType& x)
1089 m_argImpl.template writePacket<StoreMode>(row, col, x);
1092 template<
int StoreMode,
typename PacketType>
1093 void writePacket(Index index,
const PacketType& x)
1095 m_argImpl.template writePacket<StoreMode>(index, x);
1099 evaluator<ArgType> m_argImpl;
1102 template<
typename TArgType>
1103 struct unary_evaluator<MatrixWrapper<TArgType> >
1104 : evaluator_wrapper_base<MatrixWrapper<TArgType> >
1106 typedef MatrixWrapper<TArgType> XprType;
1108 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& wrapper)
1109 : evaluator_wrapper_base<MatrixWrapper<TArgType> >(wrapper.nestedExpression())
1113 template<
typename TArgType>
1114 struct unary_evaluator<ArrayWrapper<TArgType> >
1115 : evaluator_wrapper_base<ArrayWrapper<TArgType> >
1117 typedef ArrayWrapper<TArgType> XprType;
1119 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& wrapper)
1120 : evaluator_wrapper_base<ArrayWrapper<TArgType> >(wrapper.nestedExpression())
1128 template<
typename PacketType,
bool ReversePacket>
struct reverse_packet_cond;
1130 template<
typename ArgType,
int Direction>
1131 struct unary_evaluator<Reverse<ArgType, Direction> >
1132 : evaluator_base<Reverse<ArgType, Direction> >
1134 typedef Reverse<ArgType, Direction> XprType;
1135 typedef typename XprType::Scalar Scalar;
1136 typedef typename XprType::CoeffReturnType CoeffReturnType;
1139 IsRowMajor = XprType::IsRowMajor,
1140 IsColMajor = !IsRowMajor,
1144 || ((Direction ==
Vertical) && IsColMajor)
1145 || ((Direction ==
Horizontal) && IsRowMajor),
1147 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1151 Flags0 = evaluator<ArgType>::Flags,
1153 || ((ReverseRow && XprType::ColsAtCompileTime==1) || (ReverseCol && XprType::RowsAtCompileTime==1))
1154 ? LinearAccessBit : 0,
1156 Flags =
int(Flags0) & (HereditaryBits | PacketAccessBit | LinearAccess),
1161 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& reverse)
1162 : m_argImpl(reverse.nestedExpression()),
1163 m_rows(ReverseRow ? reverse.nestedExpression().rows() : 1),
1164 m_cols(ReverseCol ? reverse.nestedExpression().cols() : 1)
1167 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index col)
const
1169 return m_argImpl.coeff(ReverseRow ? m_rows.value() - row - 1 : row,
1170 ReverseCol ? m_cols.value() - col - 1 : col);
1173 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
1175 return m_argImpl.coeff(m_rows.value() * m_cols.value() - index - 1);
1178 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index col)
1180 return m_argImpl.coeffRef(ReverseRow ? m_rows.value() - row - 1 : row,
1181 ReverseCol ? m_cols.value() - col - 1 : col);
1184 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
1186 return m_argImpl.coeffRef(m_rows.value() * m_cols.value() - index - 1);
1189 template<
int LoadMode,
typename PacketType>
1190 PacketType packet(Index row, Index col)
const
1193 PacketSize = unpacket_traits<PacketType>::size,
1194 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1195 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1197 typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet;
1198 return reverse_packet::run(m_argImpl.template packet<LoadMode,PacketType>(
1199 ReverseRow ? m_rows.value() - row - OffsetRow : row,
1200 ReverseCol ? m_cols.value() - col - OffsetCol : col));
1203 template<
int LoadMode,
typename PacketType>
1204 PacketType packet(Index index)
const
1206 enum { PacketSize = unpacket_traits<PacketType>::size };
1207 return preverse(m_argImpl.template packet<LoadMode,PacketType>(m_rows.value() * m_cols.value() - index - PacketSize));
1210 template<
int LoadMode,
typename PacketType>
1211 void writePacket(Index row, Index col,
const PacketType& x)
1215 PacketSize = unpacket_traits<PacketType>::size,
1216 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1217 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1219 typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet;
1220 m_argImpl.template writePacket<LoadMode>(
1221 ReverseRow ? m_rows.value() - row - OffsetRow : row,
1222 ReverseCol ? m_cols.value() - col - OffsetCol : col,
1223 reverse_packet::run(x));
1226 template<
int LoadMode,
typename PacketType>
1227 void writePacket(Index index,
const PacketType& x)
1229 enum { PacketSize = unpacket_traits<PacketType>::size };
1230 m_argImpl.template writePacket<LoadMode>
1231 (m_rows.value() * m_cols.value() - index - PacketSize, preverse(x));
1235 evaluator<ArgType> m_argImpl;
1239 const variable_if_dynamic<Index, ReverseRow ? ArgType::RowsAtCompileTime : 1> m_rows;
1240 const variable_if_dynamic<Index, ReverseCol ? ArgType::ColsAtCompileTime : 1> m_cols;
1246 template<
typename ArgType,
int DiagIndex>
1247 struct evaluator<Diagonal<ArgType, DiagIndex> >
1248 : evaluator_base<Diagonal<ArgType, DiagIndex> >
1250 typedef Diagonal<ArgType, DiagIndex> XprType;
1253 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1260 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& diagonal)
1261 : m_argImpl(diagonal.nestedExpression()),
1262 m_index(diagonal.index())
1265 typedef typename XprType::Scalar Scalar;
1267 typedef typename internal::conditional<!internal::is_same<typename ArgType::StorageKind,Sparse>::value,
1268 typename XprType::CoeffReturnType,Scalar>::type CoeffReturnType;
1270 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index row, Index)
const
1272 return m_argImpl.coeff(row + rowOffset(), row + colOffset());
1275 EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index)
const
1277 return m_argImpl.coeff(index + rowOffset(), index + colOffset());
1280 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index row, Index)
1282 return m_argImpl.coeffRef(row + rowOffset(), row + colOffset());
1285 EIGEN_DEVICE_FUNC Scalar& coeffRef(Index index)
1287 return m_argImpl.coeffRef(index + rowOffset(), index + colOffset());
1291 evaluator<ArgType> m_argImpl;
1292 const internal::variable_if_dynamicindex<Index, XprType::DiagIndex> m_index;
1295 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowOffset()
const {
return m_index.value() > 0 ? 0 : -m_index.value(); }
1296 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colOffset()
const {
return m_index.value() > 0 ? m_index.value() : 0; }
1308 template<
typename ArgType>
class EvalToTemp;
1310 template<
typename ArgType>
1311 struct traits<EvalToTemp<ArgType> >
1312 :
public traits<ArgType>
1315 template<
typename ArgType>
1317 :
public dense_xpr_base<EvalToTemp<ArgType> >::type
1321 typedef typename dense_xpr_base<EvalToTemp>::type Base;
1322 EIGEN_GENERIC_PUBLIC_INTERFACE(EvalToTemp)
1324 explicit EvalToTemp(const ArgType& arg)
1328 const ArgType& arg()
const
1335 return m_arg.rows();
1340 return m_arg.cols();
1344 const ArgType& m_arg;
1347 template<
typename ArgType>
1348 struct evaluator<EvalToTemp<ArgType> >
1349 :
public evaluator<typename ArgType::PlainObject>
1351 typedef EvalToTemp<ArgType> XprType;
1352 typedef typename ArgType::PlainObject PlainObject;
1353 typedef evaluator<PlainObject> Base;
1355 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& xpr)
1356 : m_result(xpr.arg())
1358 ::new (static_cast<Base*>(
this)) Base(m_result);
1362 EIGEN_DEVICE_FUNC evaluator(const ArgType& arg)
1365 ::new (static_cast<Base*>(
this)) Base(m_result);
1369 PlainObject m_result;
1376 #endif // EIGEN_COREEVALUATORS_H
Definition: Constants.h:265
const unsigned int DirectAccessBit
Definition: Constants.h:149
const unsigned int RowMajorBit
Definition: Constants.h:61
const unsigned int PacketAccessBit
Definition: Constants.h:88
Definition: Constants.h:268
Definition: Constants.h:271
Definition: Eigen_Colamd.h:54
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:65
const unsigned int LinearAccessBit
Definition: Constants.h:124