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; };
50 typename Arg1Kind =
typename evaluator_traits<typename T::Arg1>::Kind,
51 typename Arg2Kind =
typename evaluator_traits<typename T::Arg2>::Kind,
52 typename Arg3Kind =
typename evaluator_traits<typename T::Arg3>::Kind,
53 typename Arg1Scalar =
typename traits<typename T::Arg1>::Scalar,
54 typename Arg2Scalar =
typename traits<typename T::Arg2>::Scalar,
55 typename Arg3Scalar =
typename traits<typename T::Arg3>::Scalar>
struct ternary_evaluator;
58 typename LhsKind =
typename evaluator_traits<typename T::Lhs>::Kind,
59 typename RhsKind =
typename evaluator_traits<typename T::Rhs>::Kind,
60 typename LhsScalar =
typename traits<typename T::Lhs>::Scalar,
61 typename RhsScalar =
typename traits<typename T::Rhs>::Scalar>
struct binary_evaluator;
64 typename Kind =
typename evaluator_traits<typename T::NestedExpression>::Kind,
65 typename Scalar =
typename T::Scalar>
struct unary_evaluator;
70 struct evaluator_traits_base
73 typedef typename storage_kind_to_evaluator_kind<typename traits<T>::StorageKind>::Kind Kind;
74 typedef typename storage_kind_to_shape<typename traits<T>::StorageKind>::Shape Shape;
79 struct evaluator_traits :
public evaluator_traits_base<T>
83 template<typename T, typename Shape = typename evaluator_traits<T>::Shape >
84 struct evaluator_assume_aliasing {
85 static const bool value =
false;
90 struct evaluator :
public unary_evaluator<T>
92 typedef unary_evaluator<T> Base;
93 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
94 explicit evaluator(
const T& xpr) : Base(xpr) {}
100 struct evaluator<const T>
103 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
104 explicit evaluator(
const T& xpr) : evaluator<T>(xpr) {}
109 template<
typename ExpressionType>
110 struct evaluator_base
113 typedef traits<ExpressionType> ExpressionTraits;
121 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator_base() {}
122 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ~evaluator_base() {}
124 EIGEN_DEVICE_FUNC evaluator_base(
const evaluator_base&);
125 EIGEN_DEVICE_FUNC
const evaluator_base& operator=(
const evaluator_base&);
136 template<
typename Scalar,
int OuterStr
ide>
class plainobjectbase_evaluator_data {
138 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
139 plainobjectbase_evaluator_data(
const Scalar* ptr,
Index outerStride) : data(ptr)
141 #ifndef EIGEN_INTERNAL_DEBUGGING 142 EIGEN_UNUSED_VARIABLE(outerStride);
144 eigen_internal_assert(outerStride==OuterStride);
146 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
147 Index outerStride() const EIGEN_NOEXCEPT {
return OuterStride; }
151 template<
typename Scalar>
class plainobjectbase_evaluator_data<Scalar,
Dynamic> {
153 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
154 plainobjectbase_evaluator_data(
const Scalar* ptr,
Index outerStride) : data(ptr), m_outerStride(outerStride) {}
155 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
156 Index outerStride()
const {
return m_outerStride; }
162 template<
typename Derived>
163 struct evaluator<PlainObjectBase<Derived> >
164 : evaluator_base<Derived>
166 typedef PlainObjectBase<Derived> PlainObjectType;
167 typedef typename PlainObjectType::Scalar Scalar;
168 typedef typename PlainObjectType::CoeffReturnType CoeffReturnType;
171 IsRowMajor = PlainObjectType::IsRowMajor,
172 IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime,
173 RowsAtCompileTime = PlainObjectType::RowsAtCompileTime,
174 ColsAtCompileTime = PlainObjectType::ColsAtCompileTime,
176 CoeffReadCost = NumTraits<Scalar>::ReadCost,
177 Flags = traits<Derived>::EvaluatorFlags,
178 Alignment = traits<Derived>::Alignment
182 OuterStrideAtCompileTime = IsVectorAtCompileTime ? 0
183 : int(IsRowMajor) ? ColsAtCompileTime
187 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
189 : m_d(0,OuterStrideAtCompileTime)
191 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
194 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
195 explicit evaluator(
const PlainObjectType& m)
196 : m_d(m.data(),IsVectorAtCompileTime ? 0 : m.outerStride())
198 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
201 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
202 CoeffReturnType coeff(
Index row,
Index col)
const 205 return m_d.data[row * m_d.outerStride() + col];
207 return m_d.data[row + col * m_d.outerStride()];
210 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
211 CoeffReturnType coeff(
Index index)
const 213 return m_d.data[index];
216 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
220 return const_cast<Scalar*
>(m_d.data)[row * m_d.outerStride() + col];
222 return const_cast<Scalar*
>(m_d.data)[row + col * m_d.outerStride()];
225 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
226 Scalar& coeffRef(
Index index)
228 return const_cast<Scalar*
>(m_d.data)[index];
231 template<
int LoadMode,
typename PacketType>
236 return ploadt<PacketType, LoadMode>(m_d.data + row * m_d.outerStride() + col);
238 return ploadt<PacketType, LoadMode>(m_d.data + row + col * m_d.outerStride());
241 template<
int LoadMode,
typename PacketType>
243 PacketType packet(
Index index)
const 245 return ploadt<PacketType, LoadMode>(m_d.data + index);
248 template<
int StoreMode,
typename PacketType>
250 void writePacket(
Index row,
Index col,
const PacketType& x)
253 return pstoret<Scalar, PacketType, StoreMode>
254 (
const_cast<Scalar*
>(m_d.data) + row * m_d.outerStride() + col, x);
256 return pstoret<Scalar, PacketType, StoreMode>
257 (
const_cast<Scalar*
>(m_d.data) + row + col * m_d.outerStride(), x);
260 template<
int StoreMode,
typename PacketType>
262 void writePacket(
Index index,
const PacketType& x)
264 return pstoret<Scalar, PacketType, StoreMode>(
const_cast<Scalar*
>(m_d.data) + index, x);
269 plainobjectbase_evaluator_data<Scalar,OuterStrideAtCompileTime> m_d;
272 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
273 struct evaluator<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
274 : evaluator<PlainObjectBase<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
276 typedef Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType;
278 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
281 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
282 explicit evaluator(
const XprType& m)
283 : evaluator<PlainObjectBase<XprType> >(m)
287 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
288 struct evaluator<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
289 : evaluator<PlainObjectBase<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
291 typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType;
293 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
296 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
297 explicit evaluator(
const XprType& m)
298 : evaluator<PlainObjectBase<XprType> >(m)
304 template<
typename ArgType>
305 struct unary_evaluator<Transpose<ArgType>, IndexBased>
306 : evaluator_base<Transpose<ArgType> >
308 typedef Transpose<ArgType> XprType;
311 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
313 Alignment = evaluator<ArgType>::Alignment
316 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
317 explicit unary_evaluator(
const XprType& t) : m_argImpl(t.nestedExpression()) {}
319 typedef typename XprType::Scalar Scalar;
320 typedef typename XprType::CoeffReturnType CoeffReturnType;
322 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
323 CoeffReturnType coeff(
Index row,
Index col)
const 325 return m_argImpl.coeff(col, row);
328 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
329 CoeffReturnType coeff(
Index index)
const 331 return m_argImpl.coeff(index);
334 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
337 return m_argImpl.coeffRef(col, row);
340 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
341 typename XprType::Scalar& coeffRef(
Index index)
343 return m_argImpl.coeffRef(index);
346 template<
int LoadMode,
typename PacketType>
350 return m_argImpl.template packet<LoadMode,PacketType>(col, row);
353 template<
int LoadMode,
typename PacketType>
355 PacketType packet(
Index index)
const 357 return m_argImpl.template packet<LoadMode,PacketType>(index);
360 template<
int StoreMode,
typename PacketType>
362 void writePacket(
Index row,
Index col,
const PacketType& x)
364 m_argImpl.template writePacket<StoreMode,PacketType>(col, row, x);
367 template<
int StoreMode,
typename PacketType>
369 void writePacket(
Index index,
const PacketType& x)
371 m_argImpl.template writePacket<StoreMode,PacketType>(index, x);
375 evaluator<ArgType> m_argImpl;
382 template<
typename Scalar,
typename NullaryOp,
383 bool has_nullary = has_nullary_operator<NullaryOp>::value,
384 bool has_unary = has_unary_operator<NullaryOp>::value,
385 bool has_binary = has_binary_operator<NullaryOp>::value>
386 struct nullary_wrapper
388 template <
typename IndexType>
389 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i, IndexType j)
const {
return op(i,j); }
390 template <
typename IndexType>
391 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i)
const {
return op(i); }
393 template <
typename T,
typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i, IndexType j)
const {
return op.template packetOp<T>(i,j); }
394 template <
typename T,
typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i)
const {
return op.template packetOp<T>(i); }
397 template<
typename Scalar,
typename NullaryOp>
398 struct nullary_wrapper<Scalar,NullaryOp,true,false,false>
400 template <
typename IndexType>
401 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType=0, IndexType=0)
const {
return op(); }
402 template <
typename T,
typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType=0, IndexType=0)
const {
return op.template packetOp<T>(); }
405 template<
typename Scalar,
typename NullaryOp>
406 struct nullary_wrapper<Scalar,NullaryOp,false,false,true>
408 template <
typename IndexType>
409 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i, IndexType j=0)
const {
return op(i,j); }
410 template <
typename T,
typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i, IndexType j=0)
const {
return op.template packetOp<T>(i,j); }
416 template<
typename Scalar,
typename NullaryOp>
417 struct nullary_wrapper<Scalar,NullaryOp,false,true,false>
419 template <
typename IndexType>
420 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i, IndexType j)
const {
421 eigen_assert(i==0 || j==0);
424 template <
typename T,
typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i, IndexType j)
const {
425 eigen_assert(i==0 || j==0);
426 return op.template packetOp<T>(i+j);
429 template <
typename IndexType>
430 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i)
const {
return op(i); }
431 template <
typename T,
typename IndexType>
432 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i)
const {
return op.template packetOp<T>(i); }
435 template<
typename Scalar,
typename NullaryOp>
436 struct nullary_wrapper<Scalar,NullaryOp,false,false,false> {};
438 #if 0 && EIGEN_COMP_MSVC>0 456 template<
typename T>
struct nullary_wrapper_workaround_msvc {
457 nullary_wrapper_workaround_msvc(
const T&);
461 template<
typename Scalar,
typename NullaryOp>
462 struct nullary_wrapper<Scalar,NullaryOp,true,true,true>
464 template <
typename IndexType>
465 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i, IndexType j)
const {
466 return nullary_wrapper<Scalar,NullaryOp,
467 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
468 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
469 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
operator()(op,i,j);
471 template <
typename IndexType>
472 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i)
const {
473 return nullary_wrapper<Scalar,NullaryOp,
474 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
475 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
476 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
operator()(op,i);
479 template <
typename T,
typename IndexType>
480 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i, IndexType j)
const {
481 return nullary_wrapper<Scalar,NullaryOp,
482 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
483 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
484 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
template packetOp<T>(op,i,j);
486 template <
typename T,
typename IndexType>
487 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i)
const {
488 return nullary_wrapper<Scalar,NullaryOp,
489 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
490 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
491 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
template packetOp<T>(op,i);
494 #endif // MSVC workaround 496 template<
typename NullaryOp,
typename PlainObjectType>
497 struct evaluator<CwiseNullaryOp<NullaryOp,PlainObjectType> >
498 : evaluator_base<CwiseNullaryOp<NullaryOp,PlainObjectType> >
500 typedef CwiseNullaryOp<NullaryOp,PlainObjectType> XprType;
501 typedef typename internal::remove_all<PlainObjectType>::type PlainObjectTypeCleaned;
504 CoeffReadCost = internal::functor_traits<NullaryOp>::Cost,
506 Flags = (evaluator<PlainObjectTypeCleaned>::Flags
511 Alignment = AlignedMax
514 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& n)
515 : m_functor(n.functor()), m_wrapper()
517 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
520 typedef typename XprType::CoeffReturnType CoeffReturnType;
522 template <
typename IndexType>
523 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
524 CoeffReturnType coeff(IndexType row, IndexType col)
const 526 return m_wrapper(m_functor, row, col);
529 template <
typename IndexType>
530 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
531 CoeffReturnType coeff(IndexType index)
const 533 return m_wrapper(m_functor,index);
536 template<
int LoadMode,
typename PacketType,
typename IndexType>
538 PacketType packet(IndexType row, IndexType col)
const 540 return m_wrapper.template packetOp<PacketType>(m_functor, row, col);
543 template<
int LoadMode,
typename PacketType,
typename IndexType>
545 PacketType packet(IndexType index)
const 547 return m_wrapper.template packetOp<PacketType>(m_functor, index);
551 const NullaryOp m_functor;
552 const internal::nullary_wrapper<CoeffReturnType,NullaryOp> m_wrapper;
557 template<
typename UnaryOp,
typename ArgType>
558 struct unary_evaluator<CwiseUnaryOp<UnaryOp, ArgType>, IndexBased >
559 : evaluator_base<CwiseUnaryOp<UnaryOp, ArgType> >
561 typedef CwiseUnaryOp<UnaryOp, ArgType> XprType;
564 CoeffReadCost = int(evaluator<ArgType>::CoeffReadCost) + int(functor_traits<UnaryOp>::Cost),
566 Flags = evaluator<ArgType>::Flags
568 Alignment = evaluator<ArgType>::Alignment
571 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
572 explicit unary_evaluator(
const XprType& op) : m_d(op)
574 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
575 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
578 typedef typename XprType::CoeffReturnType CoeffReturnType;
580 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
581 CoeffReturnType coeff(
Index row,
Index col)
const 583 return m_d.func()(m_d.argImpl.coeff(row, col));
586 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
587 CoeffReturnType coeff(
Index index)
const 589 return m_d.func()(m_d.argImpl.coeff(index));
592 template<
int LoadMode,
typename PacketType>
596 return m_d.func().packetOp(m_d.argImpl.template packet<LoadMode, PacketType>(row, col));
599 template<
int LoadMode,
typename PacketType>
601 PacketType packet(
Index index)
const 603 return m_d.func().packetOp(m_d.argImpl.template packet<LoadMode, PacketType>(index));
611 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
612 Data(
const XprType& xpr) : op(xpr.functor()), argImpl(xpr.nestedExpression()) {}
613 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
614 const UnaryOp& func()
const {
return op; }
616 evaluator<ArgType> argImpl;
625 template<
typename TernaryOp,
typename Arg1,
typename Arg2,
typename Arg3>
626 struct evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >
627 :
public ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >
629 typedef CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> XprType;
630 typedef ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > Base;
632 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& xpr) : Base(xpr) {}
635 template<
typename TernaryOp,
typename Arg1,
typename Arg2,
typename Arg3>
636 struct ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3>, IndexBased, IndexBased>
637 : evaluator_base<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >
639 typedef CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> XprType;
642 CoeffReadCost = int(evaluator<Arg1>::CoeffReadCost) + int(evaluator<Arg2>::CoeffReadCost) + int(evaluator<Arg3>::CoeffReadCost) + int(functor_traits<TernaryOp>::Cost),
644 Arg1Flags = evaluator<Arg1>::Flags,
645 Arg2Flags = evaluator<Arg2>::Flags,
646 Arg3Flags = evaluator<Arg3>::Flags,
647 SameType = is_same<typename Arg1::Scalar,typename Arg2::Scalar>::value && is_same<typename Arg1::Scalar,typename Arg3::Scalar>::value,
649 Flags0 = (
int(Arg1Flags) | int(Arg2Flags) | int(Arg3Flags)) & (
651 | (
int(Arg1Flags) &
int(Arg2Flags) &
int(Arg3Flags) &
653 | (functor_traits<TernaryOp>::PacketAccess && StorageOrdersAgree && SameType ?
PacketAccessBit : 0)
658 Alignment = EIGEN_PLAIN_ENUM_MIN(
659 EIGEN_PLAIN_ENUM_MIN(evaluator<Arg1>::Alignment, evaluator<Arg2>::Alignment),
660 evaluator<Arg3>::Alignment)
663 EIGEN_DEVICE_FUNC
explicit ternary_evaluator(
const XprType& xpr) : m_d(xpr)
665 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<TernaryOp>::Cost);
666 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
669 typedef typename XprType::CoeffReturnType CoeffReturnType;
671 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
672 CoeffReturnType coeff(
Index row,
Index col)
const 674 return m_d.func()(m_d.arg1Impl.coeff(row, col), m_d.arg2Impl.coeff(row, col), m_d.arg3Impl.coeff(row, col));
677 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
678 CoeffReturnType coeff(
Index index)
const 680 return m_d.func()(m_d.arg1Impl.coeff(index), m_d.arg2Impl.coeff(index), m_d.arg3Impl.coeff(index));
683 template<
int LoadMode,
typename PacketType>
687 return m_d.func().packetOp(m_d.arg1Impl.template packet<LoadMode,PacketType>(row, col),
688 m_d.arg2Impl.template packet<LoadMode,PacketType>(row, col),
689 m_d.arg3Impl.template packet<LoadMode,PacketType>(row, col));
692 template<
int LoadMode,
typename PacketType>
694 PacketType packet(
Index index)
const 696 return m_d.func().packetOp(m_d.arg1Impl.template packet<LoadMode,PacketType>(index),
697 m_d.arg2Impl.template packet<LoadMode,PacketType>(index),
698 m_d.arg3Impl.template packet<LoadMode,PacketType>(index));
705 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
706 Data(
const XprType& xpr) : op(xpr.functor()), arg1Impl(xpr.arg1()), arg2Impl(xpr.arg2()), arg3Impl(xpr.arg3()) {}
707 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
708 const TernaryOp& func()
const {
return op; }
710 evaluator<Arg1> arg1Impl;
711 evaluator<Arg2> arg2Impl;
712 evaluator<Arg3> arg3Impl;
721 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
722 struct evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
723 :
public binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
725 typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
726 typedef binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > Base;
728 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
729 explicit evaluator(
const XprType& xpr) : Base(xpr) {}
732 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
733 struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, IndexBased>
734 : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
736 typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
739 CoeffReadCost = int(evaluator<Lhs>::CoeffReadCost) + int(evaluator<Rhs>::CoeffReadCost) + int(functor_traits<BinaryOp>::Cost),
741 LhsFlags = evaluator<Lhs>::Flags,
742 RhsFlags = evaluator<Rhs>::Flags,
743 SameType = is_same<typename Lhs::Scalar,typename Rhs::Scalar>::value,
745 Flags0 = (
int(LhsFlags) | int(RhsFlags)) & (
747 | (
int(LhsFlags) &
int(RhsFlags) &
748 ( (StorageOrdersAgree ? LinearAccessBit : 0)
749 | (functor_traits<BinaryOp>::PacketAccess && StorageOrdersAgree && SameType ? PacketAccessBit : 0)
754 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<Lhs>::Alignment,evaluator<Rhs>::Alignment)
757 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
758 explicit binary_evaluator(
const XprType& xpr) : m_d(xpr)
760 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost);
761 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
764 typedef typename XprType::CoeffReturnType CoeffReturnType;
766 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
767 CoeffReturnType coeff(
Index row,
Index col)
const 769 return m_d.func()(m_d.lhsImpl.coeff(row, col), m_d.rhsImpl.coeff(row, col));
772 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
773 CoeffReturnType coeff(
Index index)
const 775 return m_d.func()(m_d.lhsImpl.coeff(index), m_d.rhsImpl.coeff(index));
778 template<
int LoadMode,
typename PacketType>
782 return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode,PacketType>(row, col),
783 m_d.rhsImpl.template packet<LoadMode,PacketType>(row, col));
786 template<
int LoadMode,
typename PacketType>
788 PacketType packet(
Index index)
const 790 return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode,PacketType>(index),
791 m_d.rhsImpl.template packet<LoadMode,PacketType>(index));
799 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
800 Data(
const XprType& xpr) : op(xpr.functor()), lhsImpl(xpr.lhs()), rhsImpl(xpr.rhs()) {}
801 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
802 const BinaryOp& func()
const {
return op; }
804 evaluator<Lhs> lhsImpl;
805 evaluator<Rhs> rhsImpl;
813 template<
typename UnaryOp,
typename ArgType>
814 struct unary_evaluator<CwiseUnaryView<UnaryOp, ArgType>, IndexBased>
815 : evaluator_base<CwiseUnaryView<UnaryOp, ArgType> >
817 typedef CwiseUnaryView<UnaryOp, ArgType> XprType;
820 CoeffReadCost = int(evaluator<ArgType>::CoeffReadCost) + int(functor_traits<UnaryOp>::Cost),
822 Flags = (evaluator<ArgType>::Flags & (HereditaryBits | LinearAccessBit |
DirectAccessBit)),
827 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& op) : m_d(op)
829 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
830 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
833 typedef typename XprType::Scalar Scalar;
834 typedef typename XprType::CoeffReturnType CoeffReturnType;
836 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
837 CoeffReturnType coeff(
Index row,
Index col)
const 839 return m_d.func()(m_d.argImpl.coeff(row, col));
842 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
843 CoeffReturnType coeff(
Index index)
const 845 return m_d.func()(m_d.argImpl.coeff(index));
848 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
851 return m_d.func()(m_d.argImpl.coeffRef(row, col));
854 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
855 Scalar& coeffRef(
Index index)
857 return m_d.func()(m_d.argImpl.coeffRef(index));
865 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
866 Data(
const XprType& xpr) : op(xpr.functor()), argImpl(xpr.nestedExpression()) {}
867 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
868 const UnaryOp& func()
const {
return op; }
870 evaluator<ArgType> argImpl;
880 template<
typename Derived,
typename PlainObjectType>
881 struct mapbase_evaluator;
883 template<
typename Derived,
typename PlainObjectType>
884 struct mapbase_evaluator : evaluator_base<Derived>
886 typedef Derived XprType;
887 typedef typename XprType::PointerType PointerType;
888 typedef typename XprType::Scalar Scalar;
889 typedef typename XprType::CoeffReturnType CoeffReturnType;
892 IsRowMajor = XprType::RowsAtCompileTime,
893 ColsAtCompileTime = XprType::ColsAtCompileTime,
894 CoeffReadCost = NumTraits<Scalar>::ReadCost
897 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
898 explicit mapbase_evaluator(
const XprType& map)
899 : m_data(const_cast<PointerType>(map.data())),
900 m_innerStride(map.innerStride()),
901 m_outerStride(map.outerStride())
903 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(evaluator<Derived>::Flags&PacketAccessBit, internal::inner_stride_at_compile_time<Derived>::ret==1),
904 PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
905 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
908 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
909 CoeffReturnType coeff(
Index row,
Index col)
const 911 return m_data[col * colStride() + row * rowStride()];
914 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
915 CoeffReturnType coeff(
Index index)
const 917 return m_data[index * m_innerStride.value()];
920 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
923 return m_data[col * colStride() + row * rowStride()];
926 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
927 Scalar& coeffRef(
Index index)
929 return m_data[index * m_innerStride.value()];
932 template<
int LoadMode,
typename PacketType>
936 PointerType ptr = m_data + row * rowStride() + col * colStride();
937 return internal::ploadt<PacketType, LoadMode>(ptr);
940 template<
int LoadMode,
typename PacketType>
942 PacketType packet(
Index index)
const 944 return internal::ploadt<PacketType, LoadMode>(m_data + index * m_innerStride.value());
947 template<
int StoreMode,
typename PacketType>
949 void writePacket(
Index row,
Index col,
const PacketType& x)
951 PointerType ptr = m_data + row * rowStride() + col * colStride();
952 return internal::pstoret<Scalar, PacketType, StoreMode>(ptr, x);
955 template<
int StoreMode,
typename PacketType>
957 void writePacket(
Index index,
const PacketType& x)
959 internal::pstoret<Scalar, PacketType, StoreMode>(m_data + index * m_innerStride.value(), x);
962 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
963 Index rowStride() const EIGEN_NOEXCEPT {
964 return XprType::IsRowMajor ? m_outerStride.value() : m_innerStride.value();
966 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
967 Index colStride() const EIGEN_NOEXCEPT {
968 return XprType::IsRowMajor ? m_innerStride.value() : m_outerStride.value();
972 const internal::variable_if_dynamic<Index, XprType::InnerStrideAtCompileTime> m_innerStride;
973 const internal::variable_if_dynamic<Index, XprType::OuterStrideAtCompileTime> m_outerStride;
976 template<
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
977 struct evaluator<Map<PlainObjectType, MapOptions, StrideType> >
978 :
public mapbase_evaluator<Map<PlainObjectType, MapOptions, StrideType>, PlainObjectType>
980 typedef Map<PlainObjectType, MapOptions, StrideType> XprType;
981 typedef typename XprType::Scalar Scalar;
983 typedef typename packet_traits<Scalar>::type PacketScalar;
986 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
987 ? int(PlainObjectType::InnerStrideAtCompileTime)
988 : int(StrideType::InnerStrideAtCompileTime),
989 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
990 ? int(PlainObjectType::OuterStrideAtCompileTime)
991 : int(StrideType::OuterStrideAtCompileTime),
992 HasNoInnerStride = InnerStrideAtCompileTime == 1,
993 HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
994 HasNoStride = HasNoInnerStride && HasNoOuterStride,
995 IsDynamicSize = PlainObjectType::SizeAtCompileTime==
Dynamic,
997 PacketAccessMask = bool(HasNoInnerStride) ? ~int(0) : ~int(PacketAccessBit),
998 LinearAccessMask = bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime) ? ~int(0) : ~int(LinearAccessBit),
999 Flags = int( evaluator<PlainObjectType>::Flags) & (LinearAccessMask&PacketAccessMask),
1001 Alignment = int(MapOptions)&int(AlignedMask)
1004 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& map)
1005 : mapbase_evaluator<XprType, PlainObjectType>(map)
1011 template<
typename PlainObjectType,
int RefOptions,
typename Str
ideType>
1012 struct evaluator<Ref<PlainObjectType, RefOptions, StrideType> >
1013 :
public mapbase_evaluator<Ref<PlainObjectType, RefOptions, StrideType>, PlainObjectType>
1015 typedef Ref<PlainObjectType, RefOptions, StrideType> XprType;
1018 Flags = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Flags,
1019 Alignment = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Alignment
1022 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1023 explicit evaluator(
const XprType& ref)
1024 : mapbase_evaluator<XprType, PlainObjectType>(ref)
1030 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel,
1031 bool HasDirectAccess = internal::has_direct_access<ArgType>::ret>
struct block_evaluator;
1033 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1034 struct evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
1035 : block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel>
1037 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
1038 typedef typename XprType::Scalar Scalar;
1040 typedef typename packet_traits<Scalar>::type PacketScalar;
1043 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1045 RowsAtCompileTime = traits<XprType>::RowsAtCompileTime,
1046 ColsAtCompileTime = traits<XprType>::ColsAtCompileTime,
1047 MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime,
1048 MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime,
1050 ArgTypeIsRowMajor = (int(evaluator<ArgType>::Flags)&
RowMajorBit) != 0,
1051 IsRowMajor = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? 1
1052 : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
1053 : ArgTypeIsRowMajor,
1054 HasSameStorageOrderAsArgType = (IsRowMajor == ArgTypeIsRowMajor),
1055 InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
1056 InnerStrideAtCompileTime = HasSameStorageOrderAsArgType
1057 ? int(inner_stride_at_compile_time<ArgType>::ret)
1058 : int(outer_stride_at_compile_time<ArgType>::ret),
1059 OuterStrideAtCompileTime = HasSameStorageOrderAsArgType
1060 ? int(outer_stride_at_compile_time<ArgType>::ret)
1061 : int(inner_stride_at_compile_time<ArgType>::ret),
1062 MaskPacketAccessBit = (InnerStrideAtCompileTime == 1 || HasSameStorageOrderAsArgType) ? PacketAccessBit : 0,
1064 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1 || (InnerPanel && (evaluator<ArgType>::Flags&LinearAccessBit))) ? LinearAccessBit : 0,
1066 Flags0 = evaluator<ArgType>::Flags & ( (HereditaryBits & ~
RowMajorBit) |
1068 MaskPacketAccessBit),
1069 Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit,
1071 PacketAlignment = unpacket_traits<PacketScalar>::alignment,
1072 Alignment0 = (InnerPanel && (OuterStrideAtCompileTime!=
Dynamic)
1073 && (OuterStrideAtCompileTime!=0)
1074 && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % int(PacketAlignment)) == 0)) ? int(PacketAlignment) : 0,
1075 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ArgType>::Alignment, Alignment0)
1077 typedef block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel> block_evaluator_type;
1078 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1079 explicit evaluator(
const XprType& block) : block_evaluator_type(block)
1081 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
1086 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1087 struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, false>
1088 : unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
1090 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
1092 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1093 explicit block_evaluator(
const XprType& block)
1094 : unary_evaluator<XprType>(block)
1098 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1099 struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBased>
1100 : evaluator_base<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
1102 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
1104 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1105 explicit unary_evaluator(
const XprType& block)
1106 : m_argImpl(block.nestedExpression()),
1107 m_startRow(block.startRow()),
1108 m_startCol(block.startCol()),
1109 m_linear_offset(ForwardLinearAccess?(ArgType::IsRowMajor ? block.startRow()*block.nestedExpression().cols() + block.startCol() : block.startCol()*block.nestedExpression().rows() + block.startRow()):0)
1112 typedef typename XprType::Scalar Scalar;
1113 typedef typename XprType::CoeffReturnType CoeffReturnType;
1116 RowsAtCompileTime = XprType::RowsAtCompileTime,
1117 ForwardLinearAccess = (InnerPanel || int(XprType::IsRowMajor)==int(ArgType::IsRowMajor)) &&
bool(evaluator<ArgType>::Flags&LinearAccessBit)
1120 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1121 CoeffReturnType coeff(
Index row,
Index col)
const 1123 return m_argImpl.coeff(m_startRow.value() + row, m_startCol.value() + col);
1126 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1127 CoeffReturnType coeff(
Index index)
const 1129 return linear_coeff_impl(index, bool_constant<ForwardLinearAccess>());
1132 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1135 return m_argImpl.coeffRef(m_startRow.value() + row, m_startCol.value() + col);
1138 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1139 Scalar& coeffRef(
Index index)
1141 return linear_coeffRef_impl(index, bool_constant<ForwardLinearAccess>());
1144 template<
int LoadMode,
typename PacketType>
1146 PacketType packet(
Index row,
Index col)
const 1148 return m_argImpl.template packet<LoadMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col);
1151 template<
int LoadMode,
typename PacketType>
1153 PacketType packet(
Index index)
const 1155 if (ForwardLinearAccess)
1156 return m_argImpl.template packet<LoadMode,PacketType>(m_linear_offset.value() + index);
1158 return packet<LoadMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
1159 RowsAtCompileTime == 1 ? index : 0);
1162 template<
int StoreMode,
typename PacketType>
1164 void writePacket(
Index row,
Index col,
const PacketType& x)
1166 return m_argImpl.template writePacket<StoreMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col, x);
1169 template<
int StoreMode,
typename PacketType>
1171 void writePacket(
Index index,
const PacketType& x)
1173 if (ForwardLinearAccess)
1174 return m_argImpl.template writePacket<StoreMode,PacketType>(m_linear_offset.value() + index, x);
1176 return writePacket<StoreMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
1177 RowsAtCompileTime == 1 ? index : 0,
1182 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1183 CoeffReturnType linear_coeff_impl(
Index index, internal::true_type )
const 1185 return m_argImpl.coeff(m_linear_offset.value() + index);
1187 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1188 CoeffReturnType linear_coeff_impl(
Index index, internal::false_type )
const 1190 return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
1193 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1194 Scalar& linear_coeffRef_impl(
Index index, internal::true_type )
1196 return m_argImpl.coeffRef(m_linear_offset.value() + index);
1198 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1199 Scalar& linear_coeffRef_impl(
Index index, internal::false_type )
1201 return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
1204 evaluator<ArgType> m_argImpl;
1205 const variable_if_dynamic<Index, (ArgType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
1206 const variable_if_dynamic<Index, (ArgType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
1207 const variable_if_dynamic<Index, ForwardLinearAccess ? Dynamic : 0> m_linear_offset;
1213 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1214 struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, true>
1215 : mapbase_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>,
1216 typename Block<ArgType, BlockRows, BlockCols, InnerPanel>::PlainObject>
1218 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
1219 typedef typename XprType::Scalar Scalar;
1221 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1222 explicit block_evaluator(
const XprType& block)
1223 : mapbase_evaluator<XprType, typename XprType::PlainObject>(block)
1226 eigen_assert(((internal::UIntPtr(block.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) &&
"data is not aligned");
1235 template<
typename ConditionMatrixType,
typename ThenMatrixType,
typename ElseMatrixType>
1236 struct evaluator<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
1237 : evaluator_base<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
1239 typedef Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> XprType;
1241 CoeffReadCost = evaluator<ConditionMatrixType>::CoeffReadCost
1242 + EIGEN_PLAIN_ENUM_MAX(evaluator<ThenMatrixType>::CoeffReadCost,
1243 evaluator<ElseMatrixType>::CoeffReadCost),
1245 Flags = (
unsigned int)evaluator<ThenMatrixType>::Flags & evaluator<ElseMatrixType>::Flags & HereditaryBits,
1247 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ThenMatrixType>::Alignment, evaluator<ElseMatrixType>::Alignment)
1250 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1251 explicit evaluator(
const XprType& select)
1252 : m_conditionImpl(select.conditionMatrix()),
1253 m_thenImpl(select.thenMatrix()),
1254 m_elseImpl(select.elseMatrix())
1256 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
1259 typedef typename XprType::CoeffReturnType CoeffReturnType;
1261 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1262 CoeffReturnType coeff(
Index row,
Index col)
const 1264 if (m_conditionImpl.coeff(row, col))
1265 return m_thenImpl.coeff(row, col);
1267 return m_elseImpl.coeff(row, col);
1270 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1271 CoeffReturnType coeff(
Index index)
const 1273 if (m_conditionImpl.coeff(index))
1274 return m_thenImpl.coeff(index);
1276 return m_elseImpl.coeff(index);
1280 evaluator<ConditionMatrixType> m_conditionImpl;
1281 evaluator<ThenMatrixType> m_thenImpl;
1282 evaluator<ElseMatrixType> m_elseImpl;
1288 template<
typename ArgType,
int RowFactor,
int ColFactor>
1289 struct unary_evaluator<Replicate<ArgType, RowFactor, ColFactor> >
1290 : evaluator_base<Replicate<ArgType, RowFactor, ColFactor> >
1292 typedef Replicate<ArgType, RowFactor, ColFactor> XprType;
1293 typedef typename XprType::CoeffReturnType CoeffReturnType;
1297 typedef typename internal::nested_eval<ArgType,Factor>::type ArgTypeNested;
1298 typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
1301 CoeffReadCost = evaluator<ArgTypeNestedCleaned>::CoeffReadCost,
1302 LinearAccessMask = XprType::IsVectorAtCompileTime ?
LinearAccessBit : 0,
1303 Flags = (evaluator<ArgTypeNestedCleaned>::Flags & (HereditaryBits|LinearAccessMask) & ~
RowMajorBit) | (traits<XprType>::Flags &
RowMajorBit),
1305 Alignment = evaluator<ArgTypeNestedCleaned>::Alignment
1308 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1309 explicit unary_evaluator(
const XprType& replicate)
1310 : m_arg(replicate.nestedExpression()),
1312 m_rows(replicate.nestedExpression().rows()),
1313 m_cols(replicate.nestedExpression().cols())
1316 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1317 CoeffReturnType coeff(
Index row,
Index col)
const 1320 const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
1321 : RowFactor==1 ? row
1322 : row % m_rows.value();
1323 const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
1324 : ColFactor==1 ? col
1325 : col % m_cols.value();
1327 return m_argImpl.coeff(actual_row, actual_col);
1330 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1331 CoeffReturnType coeff(
Index index)
const 1334 const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
1335 ? (ColFactor==1 ? index : index%m_cols.value())
1336 : (RowFactor==1 ? index : index%m_rows.value());
1338 return m_argImpl.coeff(actual_index);
1341 template<
int LoadMode,
typename PacketType>
1343 PacketType packet(
Index row,
Index col)
const 1345 const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
1346 : RowFactor==1 ? row
1347 : row % m_rows.value();
1348 const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
1349 : ColFactor==1 ? col
1350 : col % m_cols.value();
1352 return m_argImpl.template packet<LoadMode,PacketType>(actual_row, actual_col);
1355 template<
int LoadMode,
typename PacketType>
1357 PacketType packet(
Index index)
const 1359 const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
1360 ? (ColFactor==1 ? index : index%m_cols.value())
1361 : (RowFactor==1 ? index : index%m_rows.value());
1363 return m_argImpl.template packet<LoadMode,PacketType>(actual_index);
1367 const ArgTypeNested m_arg;
1368 evaluator<ArgTypeNestedCleaned> m_argImpl;
1369 const variable_if_dynamic<Index, ArgType::RowsAtCompileTime> m_rows;
1370 const variable_if_dynamic<Index, ArgType::ColsAtCompileTime> m_cols;
1378 template<
typename XprType>
1379 struct evaluator_wrapper_base
1380 : evaluator_base<XprType>
1382 typedef typename remove_all<typename XprType::NestedExpressionType>::type ArgType;
1384 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1385 Flags = evaluator<ArgType>::Flags,
1386 Alignment = evaluator<ArgType>::Alignment
1389 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1390 explicit evaluator_wrapper_base(
const ArgType&
arg) : m_argImpl(arg) {}
1392 typedef typename ArgType::Scalar Scalar;
1393 typedef typename ArgType::CoeffReturnType CoeffReturnType;
1395 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1396 CoeffReturnType coeff(
Index row,
Index col)
const 1398 return m_argImpl.coeff(row, col);
1401 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1402 CoeffReturnType coeff(
Index index)
const 1404 return m_argImpl.coeff(index);
1407 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1410 return m_argImpl.coeffRef(row, col);
1413 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1414 Scalar& coeffRef(
Index index)
1416 return m_argImpl.coeffRef(index);
1419 template<
int LoadMode,
typename PacketType>
1421 PacketType packet(
Index row,
Index col)
const 1423 return m_argImpl.template packet<LoadMode,PacketType>(row, col);
1426 template<
int LoadMode,
typename PacketType>
1428 PacketType packet(
Index index)
const 1430 return m_argImpl.template packet<LoadMode,PacketType>(index);
1433 template<
int StoreMode,
typename PacketType>
1435 void writePacket(
Index row,
Index col,
const PacketType& x)
1437 m_argImpl.template writePacket<StoreMode>(row, col, x);
1440 template<
int StoreMode,
typename PacketType>
1442 void writePacket(
Index index,
const PacketType& x)
1444 m_argImpl.template writePacket<StoreMode>(index, x);
1448 evaluator<ArgType> m_argImpl;
1451 template<
typename TArgType>
1452 struct unary_evaluator<MatrixWrapper<TArgType> >
1453 : evaluator_wrapper_base<MatrixWrapper<TArgType> >
1455 typedef MatrixWrapper<TArgType> XprType;
1457 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1458 explicit unary_evaluator(
const XprType& wrapper)
1459 : evaluator_wrapper_base<MatrixWrapper<TArgType> >(wrapper.nestedExpression())
1463 template<
typename TArgType>
1464 struct unary_evaluator<ArrayWrapper<TArgType> >
1465 : evaluator_wrapper_base<ArrayWrapper<TArgType> >
1467 typedef ArrayWrapper<TArgType> XprType;
1469 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1470 explicit unary_evaluator(
const XprType& wrapper)
1471 : evaluator_wrapper_base<ArrayWrapper<TArgType> >(wrapper.nestedExpression())
1479 template<
typename PacketType,
bool ReversePacket>
struct reverse_packet_cond;
1481 template<
typename ArgType,
int Direction>
1482 struct unary_evaluator<Reverse<ArgType, Direction> >
1483 : evaluator_base<Reverse<ArgType, Direction> >
1485 typedef Reverse<ArgType, Direction> XprType;
1486 typedef typename XprType::Scalar Scalar;
1487 typedef typename XprType::CoeffReturnType CoeffReturnType;
1490 IsRowMajor = XprType::IsRowMajor,
1491 IsColMajor = !IsRowMajor,
1495 || ((Direction ==
Vertical) && IsColMajor)
1496 || ((Direction ==
Horizontal) && IsRowMajor),
1498 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1502 Flags0 = evaluator<ArgType>::Flags,
1504 || ((ReverseRow && XprType::ColsAtCompileTime==1) || (ReverseCol && XprType::RowsAtCompileTime==1))
1505 ? LinearAccessBit : 0,
1507 Flags =
int(Flags0) & (HereditaryBits | PacketAccessBit | LinearAccess),
1512 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1513 explicit unary_evaluator(
const XprType& reverse)
1514 : m_argImpl(reverse.nestedExpression()),
1515 m_rows(ReverseRow ? reverse.nestedExpression().rows() : 1),
1516 m_cols(ReverseCol ? reverse.nestedExpression().cols() : 1)
1519 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1520 CoeffReturnType coeff(
Index row,
Index col)
const 1522 return m_argImpl.coeff(ReverseRow ? m_rows.value() - row - 1 : row,
1523 ReverseCol ? m_cols.value() - col - 1 : col);
1526 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1527 CoeffReturnType coeff(
Index index)
const 1529 return m_argImpl.coeff(m_rows.value() * m_cols.value() - index - 1);
1532 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1535 return m_argImpl.coeffRef(ReverseRow ? m_rows.value() - row - 1 : row,
1536 ReverseCol ? m_cols.value() - col - 1 : col);
1539 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1540 Scalar& coeffRef(
Index index)
1542 return m_argImpl.coeffRef(m_rows.value() * m_cols.value() - index - 1);
1545 template<
int LoadMode,
typename PacketType>
1547 PacketType packet(
Index row,
Index col)
const 1550 PacketSize = unpacket_traits<PacketType>::size,
1551 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1552 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1554 typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet;
1555 return reverse_packet::run(m_argImpl.template packet<LoadMode,PacketType>(
1556 ReverseRow ? m_rows.value() - row - OffsetRow : row,
1557 ReverseCol ? m_cols.value() - col - OffsetCol : col));
1560 template<
int LoadMode,
typename PacketType>
1562 PacketType packet(
Index index)
const 1564 enum { PacketSize = unpacket_traits<PacketType>::size };
1565 return preverse(m_argImpl.template packet<LoadMode,PacketType>(m_rows.value() * m_cols.value() - index - PacketSize));
1568 template<
int LoadMode,
typename PacketType>
1570 void writePacket(
Index row,
Index col,
const PacketType& x)
1574 PacketSize = unpacket_traits<PacketType>::size,
1575 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1576 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1578 typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet;
1579 m_argImpl.template writePacket<LoadMode>(
1580 ReverseRow ? m_rows.value() - row - OffsetRow : row,
1581 ReverseCol ? m_cols.value() - col - OffsetCol : col,
1582 reverse_packet::run(x));
1585 template<
int LoadMode,
typename PacketType>
1587 void writePacket(
Index index,
const PacketType& x)
1589 enum { PacketSize = unpacket_traits<PacketType>::size };
1590 m_argImpl.template writePacket<LoadMode>
1591 (m_rows.value() * m_cols.value() - index - PacketSize, preverse(x));
1595 evaluator<ArgType> m_argImpl;
1599 const variable_if_dynamic<Index, ReverseRow ? ArgType::RowsAtCompileTime : 1> m_rows;
1600 const variable_if_dynamic<Index, ReverseCol ? ArgType::ColsAtCompileTime : 1> m_cols;
1606 template<
typename ArgType,
int DiagIndex>
1607 struct evaluator<Diagonal<ArgType, DiagIndex> >
1608 : evaluator_base<Diagonal<ArgType, DiagIndex> >
1610 typedef Diagonal<ArgType, DiagIndex> XprType;
1613 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1620 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1621 explicit evaluator(
const XprType& diagonal)
1622 : m_argImpl(diagonal.nestedExpression()),
1623 m_index(diagonal.index())
1626 typedef typename XprType::Scalar Scalar;
1627 typedef typename XprType::CoeffReturnType CoeffReturnType;
1629 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1630 CoeffReturnType coeff(
Index row,
Index)
const 1632 return m_argImpl.coeff(row + rowOffset(), row + colOffset());
1635 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1636 CoeffReturnType coeff(
Index index)
const 1638 return m_argImpl.coeff(index + rowOffset(), index + colOffset());
1641 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1644 return m_argImpl.coeffRef(row + rowOffset(), row + colOffset());
1647 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1648 Scalar& coeffRef(
Index index)
1650 return m_argImpl.coeffRef(index + rowOffset(), index + colOffset());
1654 evaluator<ArgType> m_argImpl;
1655 const internal::variable_if_dynamicindex<Index, XprType::DiagIndex> m_index;
1658 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
1659 Index rowOffset()
const {
return m_index.value() > 0 ? 0 : -m_index.value(); }
1660 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
1661 Index colOffset()
const {
return m_index.value() > 0 ? m_index.value() : 0; }
1673 template<
typename ArgType>
class EvalToTemp;
1675 template<
typename ArgType>
1676 struct traits<EvalToTemp<ArgType> >
1677 :
public traits<ArgType>
1680 template<
typename ArgType>
1682 :
public dense_xpr_base<EvalToTemp<ArgType> >::type
1686 typedef typename dense_xpr_base<EvalToTemp>::type Base;
1687 EIGEN_GENERIC_PUBLIC_INTERFACE(EvalToTemp)
1689 explicit EvalToTemp(
const ArgType&
arg)
1693 const ArgType&
arg()
const 1698 EIGEN_CONSTEXPR
Index rows() const EIGEN_NOEXCEPT
1700 return m_arg.rows();
1703 EIGEN_CONSTEXPR
Index cols() const EIGEN_NOEXCEPT
1705 return m_arg.cols();
1709 const ArgType& m_arg;
1712 template<
typename ArgType>
1713 struct evaluator<EvalToTemp<ArgType> >
1714 :
public evaluator<typename ArgType::PlainObject>
1716 typedef EvalToTemp<ArgType> XprType;
1717 typedef typename ArgType::PlainObject PlainObject;
1718 typedef evaluator<PlainObject> Base;
1720 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& xpr)
1721 : m_result(xpr.
arg())
1723 ::new (static_cast<Base*>(
this)) Base(m_result);
1727 EIGEN_DEVICE_FUNC evaluator(const ArgType&
arg)
1730 ::new (static_cast<Base*>(
this)) Base(m_result);
1734 PlainObject m_result;
1741 #endif // EIGEN_COREEVALUATORS_H Definition: Constants.h:264
const unsigned int DirectAccessBit
Definition: Constants.h:155
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_arg_op< typename Derived::Scalar >, const Derived > arg(const Eigen::ArrayBase< Derived > &x)
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: Constants.h:267
Definition: Constants.h:270
Definition: Eigen_Colamd.h:50
const int Dynamic
Definition: Constants.h:22
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:70
const unsigned int LinearAccessBit
Definition: Constants.h:130