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
explicit evaluator(
const T& xpr) : Base(xpr) {}
99 struct evaluator<const T>
103 explicit evaluator(
const T& xpr) : evaluator<T>(xpr) {}
108 template<
typename ExpressionType>
109 struct evaluator_base :
public noncopyable
112 typedef traits<ExpressionType> ExpressionTraits;
126 template<
typename Derived>
127 struct evaluator<PlainObjectBase<Derived> >
128 : evaluator_base<Derived>
130 typedef PlainObjectBase<Derived> PlainObjectType;
131 typedef typename PlainObjectType::Scalar Scalar;
132 typedef typename PlainObjectType::CoeffReturnType CoeffReturnType;
135 IsRowMajor = PlainObjectType::IsRowMajor,
136 IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime,
137 RowsAtCompileTime = PlainObjectType::RowsAtCompileTime,
138 ColsAtCompileTime = PlainObjectType::ColsAtCompileTime,
140 CoeffReadCost = NumTraits<Scalar>::ReadCost,
141 Flags = traits<Derived>::EvaluatorFlags,
142 Alignment = traits<Derived>::Alignment
145 EIGEN_DEVICE_FUNC evaluator()
147 m_outerStride(IsVectorAtCompileTime ? 0
148 : int(IsRowMajor) ? ColsAtCompileTime
151 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
154 EIGEN_DEVICE_FUNC
explicit evaluator(
const PlainObjectType& m)
155 : m_data(m.data()), m_outerStride(IsVectorAtCompileTime ? 0 : m.outerStride())
157 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
160 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
161 CoeffReturnType coeff(
Index row,
Index col)
const 164 return m_data[row * m_outerStride.value() + col];
166 return m_data[row + col * m_outerStride.value()];
169 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
170 CoeffReturnType coeff(
Index index)
const 172 return m_data[index];
175 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
179 return const_cast<Scalar*>(m_data)[row * m_outerStride.value() + col];
181 return const_cast<Scalar*>(m_data)[row + col * m_outerStride.value()];
184 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
185 Scalar& coeffRef(
Index index)
187 return const_cast<Scalar*>(m_data)[index];
190 template<
int LoadMode,
typename PacketType>
195 return ploadt<PacketType, LoadMode>(m_data + row * m_outerStride.value() + col);
197 return ploadt<PacketType, LoadMode>(m_data + row + col * m_outerStride.value());
200 template<
int LoadMode,
typename PacketType>
202 PacketType packet(
Index index)
const 204 return ploadt<PacketType, LoadMode>(m_data + index);
207 template<
int StoreMode,
typename PacketType>
209 void writePacket(
Index row,
Index col,
const PacketType& x)
212 return pstoret<Scalar, PacketType, StoreMode>
213 (const_cast<Scalar*>(m_data) + row * m_outerStride.value() + col, x);
215 return pstoret<Scalar, PacketType, StoreMode>
216 (const_cast<Scalar*>(m_data) + row + col * m_outerStride.value(), x);
219 template<
int StoreMode,
typename PacketType>
221 void writePacket(
Index index,
const PacketType& x)
223 return pstoret<Scalar, PacketType, StoreMode>(const_cast<Scalar*>(m_data) + index, x);
227 const Scalar *m_data;
230 variable_if_dynamic<
Index, IsVectorAtCompileTime ? 0
231 : int(IsRowMajor) ? ColsAtCompileTime
232 : RowsAtCompileTime> m_outerStride;
235 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
236 struct evaluator<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
237 : evaluator<PlainObjectBase<Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
239 typedef Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType;
241 EIGEN_DEVICE_FUNC evaluator() {}
243 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& m)
244 : evaluator<PlainObjectBase<XprType> >(m)
248 template<
typename Scalar,
int Rows,
int Cols,
int Options,
int MaxRows,
int MaxCols>
249 struct evaluator<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
250 : evaluator<PlainObjectBase<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> > >
252 typedef Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> XprType;
254 EIGEN_DEVICE_FUNC evaluator() {}
256 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& m)
257 : evaluator<PlainObjectBase<XprType> >(m)
263 template<
typename ArgType>
264 struct unary_evaluator<Transpose<ArgType>, IndexBased>
265 : evaluator_base<Transpose<ArgType> >
267 typedef Transpose<ArgType> XprType;
270 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
272 Alignment = evaluator<ArgType>::Alignment
275 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& t) : m_argImpl(t.nestedExpression()) {}
277 typedef typename XprType::Scalar Scalar;
278 typedef typename XprType::CoeffReturnType CoeffReturnType;
280 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
281 CoeffReturnType coeff(
Index row,
Index col)
const 283 return m_argImpl.coeff(col, row);
286 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
287 CoeffReturnType coeff(
Index index)
const 289 return m_argImpl.coeff(index);
292 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
295 return m_argImpl.coeffRef(col, row);
298 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
299 typename XprType::Scalar& coeffRef(
Index index)
301 return m_argImpl.coeffRef(index);
304 template<
int LoadMode,
typename PacketType>
308 return m_argImpl.template packet<LoadMode,PacketType>(col, row);
311 template<
int LoadMode,
typename PacketType>
313 PacketType packet(
Index index)
const 315 return m_argImpl.template packet<LoadMode,PacketType>(index);
318 template<
int StoreMode,
typename PacketType>
320 void writePacket(
Index row,
Index col,
const PacketType& x)
322 m_argImpl.template writePacket<StoreMode,PacketType>(col, row, x);
325 template<
int StoreMode,
typename PacketType>
327 void writePacket(
Index index,
const PacketType& x)
329 m_argImpl.template writePacket<StoreMode,PacketType>(index, x);
333 evaluator<ArgType> m_argImpl;
340 template<
typename Scalar,
typename NullaryOp,
341 bool has_nullary = has_nullary_operator<NullaryOp>::value,
342 bool has_unary = has_unary_operator<NullaryOp>::value,
343 bool has_binary = has_binary_operator<NullaryOp>::value>
344 struct nullary_wrapper
346 template <
typename IndexType>
347 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i, IndexType j)
const {
return op(i,j); }
348 template <
typename IndexType>
349 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i)
const {
return op(i); }
351 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); }
352 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); }
355 template<
typename Scalar,
typename NullaryOp>
356 struct nullary_wrapper<Scalar,NullaryOp,true,false,false>
358 template <
typename IndexType>
359 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType=0, IndexType=0)
const {
return op(); }
360 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>(); }
363 template<
typename Scalar,
typename NullaryOp>
364 struct nullary_wrapper<Scalar,NullaryOp,false,false,true>
366 template <
typename IndexType>
367 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i, IndexType j=0)
const {
return op(i,j); }
368 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); }
374 template<
typename Scalar,
typename NullaryOp>
375 struct nullary_wrapper<Scalar,NullaryOp,false,true,false>
377 template <
typename IndexType>
378 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i, IndexType j)
const {
379 eigen_assert(i==0 || j==0);
382 template <
typename T,
typename IndexType> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i, IndexType j)
const {
383 eigen_assert(i==0 || j==0);
384 return op.template packetOp<T>(i+j);
387 template <
typename IndexType>
388 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i)
const {
return op(i); }
389 template <
typename T,
typename IndexType>
390 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i)
const {
return op.template packetOp<T>(i); }
393 template<
typename Scalar,
typename NullaryOp>
394 struct nullary_wrapper<Scalar,NullaryOp,false,false,false> {};
396 #if 0 && EIGEN_COMP_MSVC>0 414 template<
typename T>
struct nullary_wrapper_workaround_msvc {
415 nullary_wrapper_workaround_msvc(
const T&);
419 template<
typename Scalar,
typename NullaryOp>
420 struct nullary_wrapper<Scalar,NullaryOp,true,true,true>
422 template <
typename IndexType>
423 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i, IndexType j)
const {
424 return nullary_wrapper<Scalar,NullaryOp,
425 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
426 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
427 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
operator()(op,i,j);
429 template <
typename IndexType>
430 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar operator()(
const NullaryOp& op, IndexType i)
const {
431 return nullary_wrapper<Scalar,NullaryOp,
432 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
433 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
434 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
operator()(op,i);
437 template <
typename T,
typename IndexType>
438 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i, IndexType j)
const {
439 return nullary_wrapper<Scalar,NullaryOp,
440 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
441 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
442 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
template packetOp<T>(op,i,j);
444 template <
typename T,
typename IndexType>
445 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T packetOp(
const NullaryOp& op, IndexType i)
const {
446 return nullary_wrapper<Scalar,NullaryOp,
447 has_nullary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
448 has_unary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value,
449 has_binary_operator<NullaryOp,nullary_wrapper_workaround_msvc<IndexType> >::value>().
template packetOp<T>(op,i);
452 #endif // MSVC workaround 454 template<
typename NullaryOp,
typename PlainObjectType>
455 struct evaluator<CwiseNullaryOp<NullaryOp,PlainObjectType> >
456 : evaluator_base<CwiseNullaryOp<NullaryOp,PlainObjectType> >
458 typedef CwiseNullaryOp<NullaryOp,PlainObjectType> XprType;
459 typedef typename internal::remove_all<PlainObjectType>::type PlainObjectTypeCleaned;
462 CoeffReadCost = internal::functor_traits<NullaryOp>::Cost,
464 Flags = (evaluator<PlainObjectTypeCleaned>::Flags
469 Alignment = AlignedMax
472 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& n)
473 : m_functor(n.functor()), m_wrapper()
475 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
478 typedef typename XprType::CoeffReturnType CoeffReturnType;
480 template <
typename IndexType>
481 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
482 CoeffReturnType coeff(IndexType row, IndexType col)
const 484 return m_wrapper(m_functor, row, col);
487 template <
typename IndexType>
488 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
489 CoeffReturnType coeff(IndexType index)
const 491 return m_wrapper(m_functor,index);
494 template<
int LoadMode,
typename PacketType,
typename IndexType>
496 PacketType packet(IndexType row, IndexType col)
const 498 return m_wrapper.template packetOp<PacketType>(m_functor, row, col);
501 template<
int LoadMode,
typename PacketType,
typename IndexType>
503 PacketType packet(IndexType index)
const 505 return m_wrapper.template packetOp<PacketType>(m_functor, index);
509 const NullaryOp m_functor;
510 const internal::nullary_wrapper<CoeffReturnType,NullaryOp> m_wrapper;
515 template<
typename UnaryOp,
typename ArgType>
516 struct unary_evaluator<CwiseUnaryOp<UnaryOp, ArgType>, IndexBased >
517 : evaluator_base<CwiseUnaryOp<UnaryOp, ArgType> >
519 typedef CwiseUnaryOp<UnaryOp, ArgType> XprType;
522 CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<UnaryOp>::Cost,
524 Flags = evaluator<ArgType>::Flags
526 Alignment = evaluator<ArgType>::Alignment
529 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
530 explicit unary_evaluator(
const XprType& op)
531 : m_functor(op.functor()),
532 m_argImpl(op.nestedExpression())
534 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
535 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
538 typedef typename XprType::CoeffReturnType CoeffReturnType;
540 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
541 CoeffReturnType coeff(
Index row,
Index col)
const 543 return m_functor(m_argImpl.coeff(row, col));
546 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
547 CoeffReturnType coeff(
Index index)
const 549 return m_functor(m_argImpl.coeff(index));
552 template<
int LoadMode,
typename PacketType>
556 return m_functor.packetOp(m_argImpl.template packet<LoadMode, PacketType>(row, col));
559 template<
int LoadMode,
typename PacketType>
561 PacketType packet(
Index index)
const 563 return m_functor.packetOp(m_argImpl.template packet<LoadMode, PacketType>(index));
567 const UnaryOp m_functor;
568 evaluator<ArgType> m_argImpl;
574 template<
typename TernaryOp,
typename Arg1,
typename Arg2,
typename Arg3>
575 struct evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >
576 :
public ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >
578 typedef CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> XprType;
579 typedef ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> > Base;
581 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& xpr) : Base(xpr) {}
584 template<
typename TernaryOp,
typename Arg1,
typename Arg2,
typename Arg3>
585 struct ternary_evaluator<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3>, IndexBased, IndexBased>
586 : evaluator_base<CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> >
588 typedef CwiseTernaryOp<TernaryOp, Arg1, Arg2, Arg3> XprType;
591 CoeffReadCost = evaluator<Arg1>::CoeffReadCost + evaluator<Arg2>::CoeffReadCost + evaluator<Arg3>::CoeffReadCost + functor_traits<TernaryOp>::Cost,
593 Arg1Flags = evaluator<Arg1>::Flags,
594 Arg2Flags = evaluator<Arg2>::Flags,
595 Arg3Flags = evaluator<Arg3>::Flags,
596 SameType = is_same<typename Arg1::Scalar,typename Arg2::Scalar>::value && is_same<typename Arg1::Scalar,typename Arg3::Scalar>::value,
598 Flags0 = (
int(Arg1Flags) | int(Arg2Flags) | int(Arg3Flags)) & (
600 | (
int(Arg1Flags) &
int(Arg2Flags) &
int(Arg3Flags) &
602 | (functor_traits<TernaryOp>::PacketAccess && StorageOrdersAgree && SameType ?
PacketAccessBit : 0)
607 Alignment = EIGEN_PLAIN_ENUM_MIN(
608 EIGEN_PLAIN_ENUM_MIN(evaluator<Arg1>::Alignment, evaluator<Arg2>::Alignment),
609 evaluator<Arg3>::Alignment)
612 EIGEN_DEVICE_FUNC
explicit ternary_evaluator(
const XprType& xpr)
613 : m_functor(xpr.functor()),
614 m_arg1Impl(xpr.arg1()),
615 m_arg2Impl(xpr.arg2()),
616 m_arg3Impl(xpr.arg3())
618 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<TernaryOp>::Cost);
619 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
622 typedef typename XprType::CoeffReturnType CoeffReturnType;
624 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
625 CoeffReturnType coeff(
Index row,
Index col)
const 627 return m_functor(m_arg1Impl.coeff(row, col), m_arg2Impl.coeff(row, col), m_arg3Impl.coeff(row, col));
630 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
631 CoeffReturnType coeff(
Index index)
const 633 return m_functor(m_arg1Impl.coeff(index), m_arg2Impl.coeff(index), m_arg3Impl.coeff(index));
636 template<
int LoadMode,
typename PacketType>
640 return m_functor.packetOp(m_arg1Impl.template packet<LoadMode,PacketType>(row, col),
641 m_arg2Impl.template packet<LoadMode,PacketType>(row, col),
642 m_arg3Impl.template packet<LoadMode,PacketType>(row, col));
645 template<
int LoadMode,
typename PacketType>
647 PacketType packet(
Index index)
const 649 return m_functor.packetOp(m_arg1Impl.template packet<LoadMode,PacketType>(index),
650 m_arg2Impl.template packet<LoadMode,PacketType>(index),
651 m_arg3Impl.template packet<LoadMode,PacketType>(index));
655 const TernaryOp m_functor;
656 evaluator<Arg1> m_arg1Impl;
657 evaluator<Arg2> m_arg2Impl;
658 evaluator<Arg3> m_arg3Impl;
664 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
665 struct evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
666 :
public binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
668 typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
669 typedef binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> > Base;
671 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& xpr) : Base(xpr) {}
674 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
675 struct binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, IndexBased>
676 : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
678 typedef CwiseBinaryOp<BinaryOp, Lhs, Rhs> XprType;
681 CoeffReadCost = evaluator<Lhs>::CoeffReadCost + evaluator<Rhs>::CoeffReadCost + functor_traits<BinaryOp>::Cost,
683 LhsFlags = evaluator<Lhs>::Flags,
684 RhsFlags = evaluator<Rhs>::Flags,
685 SameType = is_same<typename Lhs::Scalar,typename Rhs::Scalar>::value,
687 Flags0 = (
int(LhsFlags) | int(RhsFlags)) & (
689 | (
int(LhsFlags) &
int(RhsFlags) &
691 | (functor_traits<BinaryOp>::PacketAccess && StorageOrdersAgree && SameType ?
PacketAccessBit : 0)
696 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<Lhs>::Alignment,evaluator<Rhs>::Alignment)
699 EIGEN_DEVICE_FUNC
explicit binary_evaluator(
const XprType& xpr)
700 : m_functor(xpr.functor()),
701 m_lhsImpl(xpr.lhs()),
704 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost);
705 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
708 typedef typename XprType::CoeffReturnType CoeffReturnType;
710 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
711 CoeffReturnType coeff(
Index row,
Index col)
const 713 return m_functor(m_lhsImpl.coeff(row, col), m_rhsImpl.coeff(row, col));
716 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
717 CoeffReturnType coeff(
Index index)
const 719 return m_functor(m_lhsImpl.coeff(index), m_rhsImpl.coeff(index));
722 template<
int LoadMode,
typename PacketType>
726 return m_functor.packetOp(m_lhsImpl.template packet<LoadMode,PacketType>(row, col),
727 m_rhsImpl.template packet<LoadMode,PacketType>(row, col));
730 template<
int LoadMode,
typename PacketType>
732 PacketType packet(
Index index)
const 734 return m_functor.packetOp(m_lhsImpl.template packet<LoadMode,PacketType>(index),
735 m_rhsImpl.template packet<LoadMode,PacketType>(index));
739 const BinaryOp m_functor;
740 evaluator<Lhs> m_lhsImpl;
741 evaluator<Rhs> m_rhsImpl;
746 template<
typename UnaryOp,
typename ArgType>
747 struct unary_evaluator<CwiseUnaryView<UnaryOp, ArgType>, IndexBased>
748 : evaluator_base<CwiseUnaryView<UnaryOp, ArgType> >
750 typedef CwiseUnaryView<UnaryOp, ArgType> XprType;
753 CoeffReadCost = evaluator<ArgType>::CoeffReadCost + functor_traits<UnaryOp>::Cost,
760 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& op)
761 : m_unaryOp(op.functor()),
762 m_argImpl(op.nestedExpression())
764 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
765 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
768 typedef typename XprType::Scalar Scalar;
769 typedef typename XprType::CoeffReturnType CoeffReturnType;
771 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
772 CoeffReturnType coeff(
Index row,
Index col)
const 774 return m_unaryOp(m_argImpl.coeff(row, col));
777 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
778 CoeffReturnType coeff(
Index index)
const 780 return m_unaryOp(m_argImpl.coeff(index));
783 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
786 return m_unaryOp(m_argImpl.coeffRef(row, col));
789 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
790 Scalar& coeffRef(
Index index)
792 return m_unaryOp(m_argImpl.coeffRef(index));
796 const UnaryOp m_unaryOp;
797 evaluator<ArgType> m_argImpl;
804 template<
typename Derived,
typename PlainObjectType>
805 struct mapbase_evaluator;
807 template<
typename Derived,
typename PlainObjectType>
808 struct mapbase_evaluator : evaluator_base<Derived>
810 typedef Derived XprType;
811 typedef typename XprType::PointerType PointerType;
812 typedef typename XprType::Scalar Scalar;
813 typedef typename XprType::CoeffReturnType CoeffReturnType;
816 IsRowMajor = XprType::RowsAtCompileTime,
817 ColsAtCompileTime = XprType::ColsAtCompileTime,
818 CoeffReadCost = NumTraits<Scalar>::ReadCost
821 EIGEN_DEVICE_FUNC
explicit mapbase_evaluator(
const XprType& map)
822 : m_data(const_cast<PointerType>(map.data())),
823 m_innerStride(map.innerStride()),
824 m_outerStride(map.outerStride())
826 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(evaluator<Derived>::Flags&
PacketAccessBit, internal::inner_stride_at_compile_time<Derived>::ret==1),
827 PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
828 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
831 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
832 CoeffReturnType coeff(
Index row,
Index col)
const 834 return m_data[col * colStride() + row * rowStride()];
837 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
838 CoeffReturnType coeff(
Index index)
const 840 return m_data[index * m_innerStride.value()];
843 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
846 return m_data[col * colStride() + row * rowStride()];
849 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
850 Scalar& coeffRef(
Index index)
852 return m_data[index * m_innerStride.value()];
855 template<
int LoadMode,
typename PacketType>
859 PointerType ptr = m_data + row * rowStride() + col * colStride();
860 return internal::ploadt<PacketType, LoadMode>(ptr);
863 template<
int LoadMode,
typename PacketType>
865 PacketType packet(
Index index)
const 867 return internal::ploadt<PacketType, LoadMode>(m_data + index * m_innerStride.value());
870 template<
int StoreMode,
typename PacketType>
872 void writePacket(
Index row,
Index col,
const PacketType& x)
874 PointerType ptr = m_data + row * rowStride() + col * colStride();
875 return internal::pstoret<Scalar, PacketType, StoreMode>(ptr, x);
878 template<
int StoreMode,
typename PacketType>
880 void writePacket(
Index index,
const PacketType& x)
882 internal::pstoret<Scalar, PacketType, StoreMode>(m_data + index * m_innerStride.value(), x);
886 inline Index rowStride()
const {
return XprType::IsRowMajor ? m_outerStride.value() : m_innerStride.value(); }
888 inline Index colStride()
const {
return XprType::IsRowMajor ? m_innerStride.value() : m_outerStride.value(); }
891 const internal::variable_if_dynamic<Index, XprType::InnerStrideAtCompileTime> m_innerStride;
892 const internal::variable_if_dynamic<Index, XprType::OuterStrideAtCompileTime> m_outerStride;
895 template<
typename PlainObjectType,
int MapOptions,
typename Str
ideType>
896 struct evaluator<Map<PlainObjectType, MapOptions, StrideType> >
897 :
public mapbase_evaluator<Map<PlainObjectType, MapOptions, StrideType>, PlainObjectType>
899 typedef Map<PlainObjectType, MapOptions, StrideType> XprType;
900 typedef typename XprType::Scalar Scalar;
902 typedef typename packet_traits<Scalar>::type PacketScalar;
905 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
906 ? int(PlainObjectType::InnerStrideAtCompileTime)
907 : int(StrideType::InnerStrideAtCompileTime),
908 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
909 ? int(PlainObjectType::OuterStrideAtCompileTime)
910 : int(StrideType::OuterStrideAtCompileTime),
911 HasNoInnerStride = InnerStrideAtCompileTime == 1,
912 HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
913 HasNoStride = HasNoInnerStride && HasNoOuterStride,
914 IsDynamicSize = PlainObjectType::SizeAtCompileTime==
Dynamic,
916 PacketAccessMask = bool(HasNoInnerStride) ? ~int(0) : ~int(
PacketAccessBit),
917 LinearAccessMask = bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime) ? ~int(0) : ~int(
LinearAccessBit),
918 Flags = int( evaluator<PlainObjectType>::Flags) & (LinearAccessMask&PacketAccessMask),
920 Alignment = int(MapOptions)&int(AlignedMask)
923 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& map)
924 : mapbase_evaluator<XprType, PlainObjectType>(map)
930 template<
typename PlainObjectType,
int RefOptions,
typename Str
ideType>
931 struct evaluator<Ref<PlainObjectType, RefOptions, StrideType> >
932 :
public mapbase_evaluator<Ref<PlainObjectType, RefOptions, StrideType>, PlainObjectType>
934 typedef Ref<PlainObjectType, RefOptions, StrideType> XprType;
937 Flags = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Flags,
938 Alignment = evaluator<Map<PlainObjectType, RefOptions, StrideType> >::Alignment
941 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& ref)
942 : mapbase_evaluator<XprType, PlainObjectType>(ref)
948 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel,
949 bool HasDirectAccess = internal::has_direct_access<ArgType>::ret>
struct block_evaluator;
951 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
952 struct evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
953 : block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel>
955 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
956 typedef typename XprType::Scalar Scalar;
958 typedef typename packet_traits<Scalar>::type PacketScalar;
961 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
963 RowsAtCompileTime = traits<XprType>::RowsAtCompileTime,
964 ColsAtCompileTime = traits<XprType>::ColsAtCompileTime,
965 MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime,
966 MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime,
968 ArgTypeIsRowMajor = (int(evaluator<ArgType>::Flags)&
RowMajorBit) != 0,
969 IsRowMajor = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? 1
970 : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
972 HasSameStorageOrderAsArgType = (IsRowMajor == ArgTypeIsRowMajor),
973 InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
974 InnerStrideAtCompileTime = HasSameStorageOrderAsArgType
975 ? int(inner_stride_at_compile_time<ArgType>::ret)
976 : int(outer_stride_at_compile_time<ArgType>::ret),
977 OuterStrideAtCompileTime = HasSameStorageOrderAsArgType
978 ? int(outer_stride_at_compile_time<ArgType>::ret)
979 : int(inner_stride_at_compile_time<ArgType>::ret),
980 MaskPacketAccessBit = (InnerStrideAtCompileTime == 1 || HasSameStorageOrderAsArgType) ?
PacketAccessBit : 0,
982 FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1 || (InnerPanel && (evaluator<ArgType>::Flags&
LinearAccessBit))) ?
LinearAccessBit : 0,
984 Flags0 = evaluator<ArgType>::Flags & ( (HereditaryBits & ~
RowMajorBit) |
986 MaskPacketAccessBit),
987 Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit,
989 PacketAlignment = unpacket_traits<PacketScalar>::alignment,
990 Alignment0 = (InnerPanel && (OuterStrideAtCompileTime!=
Dynamic)
991 && (OuterStrideAtCompileTime!=0)
992 && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % int(PacketAlignment)) == 0)) ? int(PacketAlignment) : 0,
993 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ArgType>::Alignment, Alignment0)
995 typedef block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel> block_evaluator_type;
996 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& block) : block_evaluator_type(block)
998 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
1003 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1004 struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, false>
1005 : unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
1007 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
1009 EIGEN_DEVICE_FUNC
explicit block_evaluator(
const XprType& block)
1010 : unary_evaluator<XprType>(block)
1014 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1015 struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBased>
1016 : evaluator_base<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
1018 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
1020 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& block)
1021 : m_argImpl(block.nestedExpression()),
1022 m_startRow(block.startRow()),
1023 m_startCol(block.startCol()),
1024 m_linear_offset(InnerPanel?(XprType::IsRowMajor ? block.startRow()*block.cols() : block.startCol()*block.rows()):0)
1027 typedef typename XprType::Scalar Scalar;
1028 typedef typename XprType::CoeffReturnType CoeffReturnType;
1031 RowsAtCompileTime = XprType::RowsAtCompileTime,
1032 ForwardLinearAccess = InnerPanel && bool(evaluator<ArgType>::Flags&
LinearAccessBit)
1035 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1036 CoeffReturnType coeff(
Index row,
Index col)
const 1038 return m_argImpl.coeff(m_startRow.value() + row, m_startCol.value() + col);
1041 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1042 CoeffReturnType coeff(
Index index)
const 1044 if (ForwardLinearAccess)
1045 return m_argImpl.coeff(m_linear_offset.value() + index);
1047 return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
1050 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1053 return m_argImpl.coeffRef(m_startRow.value() + row, m_startCol.value() + col);
1056 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1057 Scalar& coeffRef(
Index index)
1059 if (ForwardLinearAccess)
1060 return m_argImpl.coeffRef(m_linear_offset.value() + index);
1062 return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
1065 template<
int LoadMode,
typename PacketType>
1067 PacketType packet(
Index row,
Index col)
const 1069 return m_argImpl.template packet<LoadMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col);
1072 template<
int LoadMode,
typename PacketType>
1074 PacketType packet(
Index index)
const 1076 if (ForwardLinearAccess)
1077 return m_argImpl.template packet<LoadMode,PacketType>(m_linear_offset.value() + index);
1079 return packet<LoadMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
1080 RowsAtCompileTime == 1 ? index : 0);
1083 template<
int StoreMode,
typename PacketType>
1085 void writePacket(
Index row,
Index col,
const PacketType& x)
1087 return m_argImpl.template writePacket<StoreMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col, x);
1090 template<
int StoreMode,
typename PacketType>
1092 void writePacket(
Index index,
const PacketType& x)
1094 if (ForwardLinearAccess)
1095 return m_argImpl.template writePacket<StoreMode,PacketType>(m_linear_offset.value() + index, x);
1097 return writePacket<StoreMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
1098 RowsAtCompileTime == 1 ? index : 0,
1103 evaluator<ArgType> m_argImpl;
1104 const variable_if_dynamic<
Index, (ArgType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 :
Dynamic> m_startRow;
1105 const variable_if_dynamic<
Index, (ArgType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 :
Dynamic> m_startCol;
1106 const variable_if_dynamic<Index, InnerPanel ? Dynamic : 0> m_linear_offset;
1112 template<
typename ArgType,
int BlockRows,
int BlockCols,
bool InnerPanel>
1113 struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, true>
1114 : mapbase_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>,
1115 typename Block<ArgType, BlockRows, BlockCols, InnerPanel>::PlainObject>
1117 typedef Block<ArgType, BlockRows, BlockCols, InnerPanel> XprType;
1118 typedef typename XprType::Scalar Scalar;
1120 EIGEN_DEVICE_FUNC
explicit block_evaluator(
const XprType& block)
1121 : mapbase_evaluator<XprType, typename XprType::PlainObject>(block)
1124 eigen_assert(((internal::UIntPtr(block.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) &&
"data is not aligned");
1133 template<
typename ConditionMatrixType,
typename ThenMatrixType,
typename ElseMatrixType>
1134 struct evaluator<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
1135 : evaluator_base<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
1137 typedef Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> XprType;
1139 CoeffReadCost = evaluator<ConditionMatrixType>::CoeffReadCost
1140 + EIGEN_PLAIN_ENUM_MAX(evaluator<ThenMatrixType>::CoeffReadCost,
1141 evaluator<ElseMatrixType>::CoeffReadCost),
1143 Flags = (
unsigned int)evaluator<ThenMatrixType>::Flags & evaluator<ElseMatrixType>::Flags & HereditaryBits,
1145 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ThenMatrixType>::Alignment, evaluator<ElseMatrixType>::Alignment)
1148 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& select)
1149 : m_conditionImpl(select.conditionMatrix()),
1150 m_thenImpl(select.thenMatrix()),
1151 m_elseImpl(select.elseMatrix())
1153 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
1156 typedef typename XprType::CoeffReturnType CoeffReturnType;
1158 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1159 CoeffReturnType coeff(
Index row,
Index col)
const 1161 if (m_conditionImpl.coeff(row, col))
1162 return m_thenImpl.coeff(row, col);
1164 return m_elseImpl.coeff(row, col);
1167 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1168 CoeffReturnType coeff(
Index index)
const 1170 if (m_conditionImpl.coeff(index))
1171 return m_thenImpl.coeff(index);
1173 return m_elseImpl.coeff(index);
1177 evaluator<ConditionMatrixType> m_conditionImpl;
1178 evaluator<ThenMatrixType> m_thenImpl;
1179 evaluator<ElseMatrixType> m_elseImpl;
1185 template<
typename ArgType,
int RowFactor,
int ColFactor>
1186 struct unary_evaluator<Replicate<ArgType, RowFactor, ColFactor> >
1187 : evaluator_base<Replicate<ArgType, RowFactor, ColFactor> >
1189 typedef Replicate<ArgType, RowFactor, ColFactor> XprType;
1190 typedef typename XprType::CoeffReturnType CoeffReturnType;
1194 typedef typename internal::nested_eval<ArgType,Factor>::type ArgTypeNested;
1195 typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
1198 CoeffReadCost = evaluator<ArgTypeNestedCleaned>::CoeffReadCost,
1199 LinearAccessMask = XprType::IsVectorAtCompileTime ?
LinearAccessBit : 0,
1200 Flags = (evaluator<ArgTypeNestedCleaned>::Flags & (HereditaryBits|LinearAccessMask) & ~
RowMajorBit) | (traits<XprType>::Flags &
RowMajorBit),
1202 Alignment = evaluator<ArgTypeNestedCleaned>::Alignment
1205 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& replicate)
1206 : m_arg(replicate.nestedExpression()),
1208 m_rows(replicate.nestedExpression().rows()),
1209 m_cols(replicate.nestedExpression().cols())
1212 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1213 CoeffReturnType coeff(
Index row,
Index col)
const 1216 const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
1217 : RowFactor==1 ? row
1218 : row % m_rows.value();
1219 const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
1220 : ColFactor==1 ? col
1221 : col % m_cols.value();
1223 return m_argImpl.coeff(actual_row, actual_col);
1226 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1227 CoeffReturnType coeff(
Index index)
const 1230 const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
1231 ? (ColFactor==1 ? index : index%m_cols.value())
1232 : (RowFactor==1 ? index : index%m_rows.value());
1234 return m_argImpl.coeff(actual_index);
1237 template<
int LoadMode,
typename PacketType>
1239 PacketType packet(
Index row,
Index col)
const 1241 const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
1242 : RowFactor==1 ? row
1243 : row % m_rows.value();
1244 const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
1245 : ColFactor==1 ? col
1246 : col % m_cols.value();
1248 return m_argImpl.template packet<LoadMode,PacketType>(actual_row, actual_col);
1251 template<
int LoadMode,
typename PacketType>
1253 PacketType packet(
Index index)
const 1255 const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
1256 ? (ColFactor==1 ? index : index%m_cols.value())
1257 : (RowFactor==1 ? index : index%m_rows.value());
1259 return m_argImpl.template packet<LoadMode,PacketType>(actual_index);
1263 const ArgTypeNested m_arg;
1264 evaluator<ArgTypeNestedCleaned> m_argImpl;
1265 const variable_if_dynamic<Index, ArgType::RowsAtCompileTime> m_rows;
1266 const variable_if_dynamic<Index, ArgType::ColsAtCompileTime> m_cols;
1272 template<
typename ArgType,
typename MemberOp,
int Direction>
1273 struct evaluator<PartialReduxExpr<ArgType, MemberOp, Direction> >
1274 : evaluator_base<PartialReduxExpr<ArgType, MemberOp, Direction> >
1276 typedef PartialReduxExpr<ArgType, MemberOp, Direction> XprType;
1277 typedef typename internal::nested_eval<ArgType,1>::type ArgTypeNested;
1278 typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
1279 typedef typename ArgType::Scalar InputScalar;
1280 typedef typename XprType::Scalar Scalar;
1282 TraversalSize = Direction==int(
Vertical) ? int(ArgType::RowsAtCompileTime) : int(ArgType::ColsAtCompileTime)
1284 typedef typename MemberOp::template Cost<InputScalar,int(TraversalSize)> CostOpType;
1287 : TraversalSize * evaluator<ArgType>::CoeffReadCost + int(CostOpType::value),
1294 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType xpr)
1295 : m_arg(xpr.nestedExpression()), m_functor(xpr.functor())
1297 EIGEN_INTERNAL_CHECK_COST_VALUE(TraversalSize==
Dynamic ?
HugeCost :
int(CostOpType::value));
1298 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
1301 typedef typename XprType::CoeffReturnType CoeffReturnType;
1303 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1307 return m_functor(m_arg.col(j));
1309 return m_functor(m_arg.row(i));
1312 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1313 const Scalar coeff(
Index index)
const 1316 return m_functor(m_arg.col(index));
1318 return m_functor(m_arg.row(index));
1322 typename internal::add_const_on_value_type<ArgTypeNested>::type m_arg;
1323 const MemberOp m_functor;
1332 template<
typename XprType>
1333 struct evaluator_wrapper_base
1334 : evaluator_base<XprType>
1336 typedef typename remove_all<typename XprType::NestedExpressionType>::type ArgType;
1338 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1339 Flags = evaluator<ArgType>::Flags,
1340 Alignment = evaluator<ArgType>::Alignment
1343 EIGEN_DEVICE_FUNC
explicit evaluator_wrapper_base(
const ArgType&
arg) : m_argImpl(
arg) {}
1345 typedef typename ArgType::Scalar Scalar;
1346 typedef typename ArgType::CoeffReturnType CoeffReturnType;
1348 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1349 CoeffReturnType coeff(
Index row,
Index col)
const 1351 return m_argImpl.coeff(row, col);
1354 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1355 CoeffReturnType coeff(
Index index)
const 1357 return m_argImpl.coeff(index);
1360 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1363 return m_argImpl.coeffRef(row, col);
1366 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1367 Scalar& coeffRef(
Index index)
1369 return m_argImpl.coeffRef(index);
1372 template<
int LoadMode,
typename PacketType>
1374 PacketType packet(
Index row,
Index col)
const 1376 return m_argImpl.template packet<LoadMode,PacketType>(row, col);
1379 template<
int LoadMode,
typename PacketType>
1381 PacketType packet(
Index index)
const 1383 return m_argImpl.template packet<LoadMode,PacketType>(index);
1386 template<
int StoreMode,
typename PacketType>
1388 void writePacket(
Index row,
Index col,
const PacketType& x)
1390 m_argImpl.template writePacket<StoreMode>(row, col, x);
1393 template<
int StoreMode,
typename PacketType>
1395 void writePacket(
Index index,
const PacketType& x)
1397 m_argImpl.template writePacket<StoreMode>(index, x);
1401 evaluator<ArgType> m_argImpl;
1404 template<
typename TArgType>
1405 struct unary_evaluator<MatrixWrapper<TArgType> >
1406 : evaluator_wrapper_base<MatrixWrapper<TArgType> >
1408 typedef MatrixWrapper<TArgType> XprType;
1410 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& wrapper)
1411 : evaluator_wrapper_base<MatrixWrapper<TArgType> >(wrapper.nestedExpression())
1415 template<
typename TArgType>
1416 struct unary_evaluator<ArrayWrapper<TArgType> >
1417 : evaluator_wrapper_base<ArrayWrapper<TArgType> >
1419 typedef ArrayWrapper<TArgType> XprType;
1421 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& wrapper)
1422 : evaluator_wrapper_base<ArrayWrapper<TArgType> >(wrapper.nestedExpression())
1430 template<
typename PacketType,
bool ReversePacket>
struct reverse_packet_cond;
1432 template<
typename ArgType,
int Direction>
1433 struct unary_evaluator<Reverse<ArgType, Direction> >
1434 : evaluator_base<Reverse<ArgType, Direction> >
1436 typedef Reverse<ArgType, Direction> XprType;
1437 typedef typename XprType::Scalar Scalar;
1438 typedef typename XprType::CoeffReturnType CoeffReturnType;
1441 IsRowMajor = XprType::IsRowMajor,
1442 IsColMajor = !IsRowMajor,
1446 || ((Direction ==
Vertical) && IsColMajor)
1447 || ((Direction ==
Horizontal) && IsRowMajor),
1449 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1453 Flags0 = evaluator<ArgType>::Flags,
1455 || ((ReverseRow && XprType::ColsAtCompileTime==1) || (ReverseCol && XprType::RowsAtCompileTime==1))
1458 Flags =
int(Flags0) & (HereditaryBits |
PacketAccessBit | LinearAccess),
1463 EIGEN_DEVICE_FUNC
explicit unary_evaluator(
const XprType& reverse)
1464 : m_argImpl(reverse.nestedExpression()),
1465 m_rows(ReverseRow ? reverse.nestedExpression().rows() : 1),
1466 m_cols(ReverseCol ? reverse.nestedExpression().cols() : 1)
1469 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1470 CoeffReturnType coeff(
Index row,
Index col)
const 1472 return m_argImpl.coeff(ReverseRow ? m_rows.value() - row - 1 : row,
1473 ReverseCol ? m_cols.value() - col - 1 : col);
1476 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1477 CoeffReturnType coeff(
Index index)
const 1479 return m_argImpl.coeff(m_rows.value() * m_cols.value() - index - 1);
1482 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1485 return m_argImpl.coeffRef(ReverseRow ? m_rows.value() - row - 1 : row,
1486 ReverseCol ? m_cols.value() - col - 1 : col);
1489 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1490 Scalar& coeffRef(
Index index)
1492 return m_argImpl.coeffRef(m_rows.value() * m_cols.value() - index - 1);
1495 template<
int LoadMode,
typename PacketType>
1497 PacketType packet(
Index row,
Index col)
const 1500 PacketSize = unpacket_traits<PacketType>::size,
1501 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1502 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1504 typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet;
1505 return reverse_packet::run(m_argImpl.template packet<LoadMode,PacketType>(
1506 ReverseRow ? m_rows.value() - row - OffsetRow : row,
1507 ReverseCol ? m_cols.value() - col - OffsetCol : col));
1510 template<
int LoadMode,
typename PacketType>
1512 PacketType packet(
Index index)
const 1514 enum { PacketSize = unpacket_traits<PacketType>::size };
1515 return preverse(m_argImpl.template packet<LoadMode,PacketType>(m_rows.value() * m_cols.value() - index - PacketSize));
1518 template<
int LoadMode,
typename PacketType>
1520 void writePacket(
Index row,
Index col,
const PacketType& x)
1524 PacketSize = unpacket_traits<PacketType>::size,
1525 OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1526 OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1528 typedef internal::reverse_packet_cond<PacketType,ReversePacket> reverse_packet;
1529 m_argImpl.template writePacket<LoadMode>(
1530 ReverseRow ? m_rows.value() - row - OffsetRow : row,
1531 ReverseCol ? m_cols.value() - col - OffsetCol : col,
1532 reverse_packet::run(x));
1535 template<
int LoadMode,
typename PacketType>
1537 void writePacket(
Index index,
const PacketType& x)
1539 enum { PacketSize = unpacket_traits<PacketType>::size };
1540 m_argImpl.template writePacket<LoadMode>
1541 (m_rows.value() * m_cols.value() - index - PacketSize, preverse(x));
1545 evaluator<ArgType> m_argImpl;
1549 const variable_if_dynamic<Index, ReverseRow ? ArgType::RowsAtCompileTime : 1> m_rows;
1550 const variable_if_dynamic<Index, ReverseCol ? ArgType::ColsAtCompileTime : 1> m_cols;
1556 template<
typename ArgType,
int DiagIndex>
1557 struct evaluator<Diagonal<ArgType, DiagIndex> >
1558 : evaluator_base<Diagonal<ArgType, DiagIndex> >
1560 typedef Diagonal<ArgType, DiagIndex> XprType;
1563 CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1570 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& diagonal)
1571 : m_argImpl(diagonal.nestedExpression()),
1572 m_index(diagonal.index())
1575 typedef typename XprType::Scalar Scalar;
1576 typedef typename XprType::CoeffReturnType CoeffReturnType;
1578 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1579 CoeffReturnType coeff(
Index row,
Index)
const 1581 return m_argImpl.coeff(row + rowOffset(), row + colOffset());
1584 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1585 CoeffReturnType coeff(
Index index)
const 1587 return m_argImpl.coeff(index + rowOffset(), index + colOffset());
1590 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1593 return m_argImpl.coeffRef(row + rowOffset(), row + colOffset());
1596 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1597 Scalar& coeffRef(
Index index)
1599 return m_argImpl.coeffRef(index + rowOffset(), index + colOffset());
1603 evaluator<ArgType> m_argImpl;
1604 const internal::variable_if_dynamicindex<Index, XprType::DiagIndex> m_index;
1607 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Index rowOffset()
const {
return m_index.value() > 0 ? 0 : -m_index.value(); }
1608 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
Index colOffset()
const {
return m_index.value() > 0 ? m_index.value() : 0; }
1620 template<
typename ArgType>
class EvalToTemp;
1622 template<
typename ArgType>
1623 struct traits<EvalToTemp<ArgType> >
1624 :
public traits<ArgType>
1627 template<
typename ArgType>
1629 :
public dense_xpr_base<EvalToTemp<ArgType> >::type
1633 typedef typename dense_xpr_base<EvalToTemp>::type Base;
1634 EIGEN_GENERIC_PUBLIC_INTERFACE(EvalToTemp)
1636 explicit EvalToTemp(
const ArgType&
arg)
1640 const ArgType&
arg()
const 1647 return m_arg.rows();
1652 return m_arg.cols();
1656 const ArgType& m_arg;
1659 template<
typename ArgType>
1660 struct evaluator<EvalToTemp<ArgType> >
1661 :
public evaluator<typename ArgType::PlainObject>
1663 typedef EvalToTemp<ArgType> XprType;
1664 typedef typename ArgType::PlainObject PlainObject;
1665 typedef evaluator<PlainObject> Base;
1667 EIGEN_DEVICE_FUNC
explicit evaluator(
const XprType& xpr)
1668 : m_result(xpr.
arg())
1670 ::new (static_cast<Base*>(
this)) Base(m_result);
1674 EIGEN_DEVICE_FUNC evaluator(const ArgType&
arg)
1677 ::new (static_cast<Base*>(
this)) Base(m_result);
1681 PlainObject m_result;
1688 #endif // EIGEN_COREEVALUATORS_H const int HugeCost
Definition: Constants.h:39
Definition: Constants.h:265
const unsigned int DirectAccessBit
Definition: Constants.h:150
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:306
const unsigned int RowMajorBit
Definition: Constants.h:61
const unsigned int PacketAccessBit
Definition: Constants.h:89
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: Constants.h:268
Definition: Constants.h:271
const int Dynamic
Definition: Constants.h:21
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:65
const unsigned int LinearAccessBit
Definition: Constants.h:125