Path Tracer
CoreEvaluators.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
6 // Copyright (C) 2011-2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
7 //
8 // This Source Code Form is subject to the terms of the Mozilla
9 // Public License v. 2.0. If a copy of the MPL was not distributed
10 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 
12 
13 #ifndef EIGEN_COREEVALUATORS_H
14 #define EIGEN_COREEVALUATORS_H
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 // This class returns the evaluator kind from the expression storage kind.
21 // Default assumes index based accessors
22 template<typename StorageKind>
24  typedef IndexBased Kind;
25 };
26 
27 // This class returns the evaluator shape from the expression storage kind.
28 // It can be Dense, Sparse, Triangular, Diagonal, SelfAdjoint, Band, etc.
29 template<typename StorageKind> struct storage_kind_to_shape;
30 
31 template<> struct storage_kind_to_shape<Dense> { typedef DenseShape Shape; };
32 template<> struct storage_kind_to_shape<SolverStorage> { typedef SolverShape Shape; };
35 
36 // Evaluators have to be specialized with respect to various criteria such as:
37 // - storage/structure/shape
38 // - scalar type
39 // - etc.
40 // Therefore, we need specialization of evaluator providing additional template arguments for each kind of evaluators.
41 // We currently distinguish the following kind of evaluators:
42 // - unary_evaluator for expressions taking only one arguments (CwiseUnaryOp, CwiseUnaryView, Transpose, MatrixWrapper, ArrayWrapper, Reverse, Replicate)
43 // - binary_evaluator for expression taking two arguments (CwiseBinaryOp)
44 // - ternary_evaluator for expression taking three arguments (CwiseTernaryOp)
45 // - product_evaluator for linear algebra products (Product); special case of binary_evaluator because it requires additional tags for dispatching.
46 // - mapbase_evaluator for Map, Block, Ref
47 // - block_evaluator for Block (special dispatching to a mapbase_evaluator or unary_evaluator)
48 
49 template< typename T,
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;
56 
57 template< typename T,
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;
62 
63 template< typename T,
65  typename Scalar = typename T::Scalar> struct unary_evaluator;
66 
67 // evaluator_traits<T> contains traits for evaluator<T>
68 
69 template<typename T>
71 {
72  // by default, get evaluator kind and shape from storage
74  typedef typename storage_kind_to_shape<typename traits<T>::StorageKind>::Shape Shape;
75 };
76 
77 // Default evaluator traits
78 template<typename T>
80 {
81 };
82 
83 template<typename T, typename Shape = typename evaluator_traits<T>::Shape >
85  static const bool value = false;
86 };
87 
88 // By default, we assume a unary expression:
89 template<typename T>
90 struct evaluator : public unary_evaluator<T>
91 {
92  typedef unary_evaluator<T> Base;
93  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
94  explicit evaluator(const T& xpr) : Base(xpr) {}
95 };
96 
97 
98 // TODO: Think about const-correctness
99 template<typename T>
100 struct evaluator<const T>
101  : evaluator<T>
102 {
103  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
104  explicit evaluator(const T& xpr) : evaluator<T>(xpr) {}
105 };
106 
107 // ---------- base class for all evaluators ----------
108 
109 template<typename ExpressionType>
111 {
112  // TODO that's not very nice to have to propagate all these traits. They are currently only needed to handle outer,inner indices.
114 
115  enum {
116  Alignment = 0
117  };
118  // noncopyable:
119  // Don't make this class inherit noncopyable as this kills EBO (Empty Base Optimization)
120  // and make complex evaluator much larger than then should do.
121  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE evaluator_base() {}
122  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ~evaluator_base() {}
123 private:
124  EIGEN_DEVICE_FUNC evaluator_base(const evaluator_base&);
125  EIGEN_DEVICE_FUNC const evaluator_base& operator=(const evaluator_base&);
126 };
127 
128 // -------------------- Matrix and Array --------------------
129 //
130 // evaluator<PlainObjectBase> is a common base class for the
131 // Matrix and Array evaluators.
132 // Here we directly specialize evaluator. This is not really a unary expression, and it is, by definition, dense,
133 // so no need for more sophisticated dispatching.
134 
135 // this helper permits to completely eliminate m_outerStride if it is known at compiletime.
136 template<typename Scalar,int OuterStride> class plainobjectbase_evaluator_data {
137 public:
138  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
139  plainobjectbase_evaluator_data(const Scalar* ptr, Index outerStride) : data(ptr)
140  {
141 #ifndef EIGEN_INTERNAL_DEBUGGING
142  EIGEN_UNUSED_VARIABLE(outerStride);
143 #endif
144  eigen_internal_assert(outerStride==OuterStride);
145  }
146  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
147  Index outerStride() const { return OuterStride; }
148  const Scalar *data;
149 };
150 
151 template<typename Scalar> class plainobjectbase_evaluator_data<Scalar,Dynamic> {
152 public:
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; }
157  const Scalar *data;
158 protected:
159  Index m_outerStride;
160 };
161 
162 template<typename Derived>
163 struct evaluator<PlainObjectBase<Derived> >
164  : evaluator_base<Derived>
165 {
167  typedef typename PlainObjectType::Scalar Scalar;
168  typedef typename PlainObjectType::CoeffReturnType CoeffReturnType;
169 
170  enum {
171  IsRowMajor = PlainObjectType::IsRowMajor,
172  IsVectorAtCompileTime = PlainObjectType::IsVectorAtCompileTime,
173  RowsAtCompileTime = PlainObjectType::RowsAtCompileTime,
174  ColsAtCompileTime = PlainObjectType::ColsAtCompileTime,
175 
176  CoeffReadCost = NumTraits<Scalar>::ReadCost,
178  Alignment = traits<Derived>::Alignment
179  };
180  enum {
181  // We do not need to know the outer stride for vectors
182  OuterStrideAtCompileTime = IsVectorAtCompileTime ? 0
183  : int(IsRowMajor) ? ColsAtCompileTime
184  : RowsAtCompileTime
185  };
186 
187  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
188  evaluator()
189  : m_d(0,OuterStrideAtCompileTime)
190  {
191  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
192  }
193 
194  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
195  explicit evaluator(const PlainObjectType& m)
196  : m_d(m.data(),IsVectorAtCompileTime ? 0 : m.outerStride())
197  {
198  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
199  }
200 
201  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
202  CoeffReturnType coeff(Index row, Index col) const
203  {
204  if (IsRowMajor)
205  return m_d.data[row * m_d.outerStride() + col];
206  else
207  return m_d.data[row + col * m_d.outerStride()];
208  }
209 
210  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
211  CoeffReturnType coeff(Index index) const
212  {
213  return m_d.data[index];
214  }
215 
216  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
217  Scalar& coeffRef(Index row, Index col)
218  {
219  if (IsRowMajor)
220  return const_cast<Scalar*>(m_d.data)[row * m_d.outerStride() + col];
221  else
222  return const_cast<Scalar*>(m_d.data)[row + col * m_d.outerStride()];
223  }
224 
225  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
226  Scalar& coeffRef(Index index)
227  {
228  return const_cast<Scalar*>(m_d.data)[index];
229  }
230 
231  template<int LoadMode, typename PacketType>
232  EIGEN_STRONG_INLINE
233  PacketType packet(Index row, Index col) const
234  {
235  if (IsRowMajor)
236  return ploadt<PacketType, LoadMode>(m_d.data + row * m_d.outerStride() + col);
237  else
238  return ploadt<PacketType, LoadMode>(m_d.data + row + col * m_d.outerStride());
239  }
240 
241  template<int LoadMode, typename PacketType>
242  EIGEN_STRONG_INLINE
243  PacketType packet(Index index) const
244  {
245  return ploadt<PacketType, LoadMode>(m_d.data + index);
246  }
247 
248  template<int StoreMode,typename PacketType>
249  EIGEN_STRONG_INLINE
250  void writePacket(Index row, Index col, const PacketType& x)
251  {
252  if (IsRowMajor)
253  return pstoret<Scalar, PacketType, StoreMode>
254  (const_cast<Scalar*>(m_d.data) + row * m_d.outerStride() + col, x);
255  else
256  return pstoret<Scalar, PacketType, StoreMode>
257  (const_cast<Scalar*>(m_d.data) + row + col * m_d.outerStride(), x);
258  }
259 
260  template<int StoreMode, typename PacketType>
261  EIGEN_STRONG_INLINE
262  void writePacket(Index index, const PacketType& x)
263  {
264  return pstoret<Scalar, PacketType, StoreMode>(const_cast<Scalar*>(m_d.data) + index, x);
265  }
266 
267 protected:
268 
270 };
271 
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> > >
275 {
277 
278  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
279  evaluator() {}
280 
281  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
282  explicit evaluator(const XprType& m)
284  { }
285 };
286 
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> > >
290 {
292 
293  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
294  evaluator() {}
295 
296  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
297  explicit evaluator(const XprType& m)
299  { }
300 };
301 
302 // -------------------- Transpose --------------------
303 
304 template<typename ArgType>
306  : evaluator_base<Transpose<ArgType> >
307 {
308  typedef Transpose<ArgType> XprType;
309 
310  enum {
311  CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
314  };
315 
316  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
317  explicit unary_evaluator(const XprType& t) : m_argImpl(t.nestedExpression()) {}
318 
319  typedef typename XprType::Scalar Scalar;
320  typedef typename XprType::CoeffReturnType CoeffReturnType;
321 
322  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
323  CoeffReturnType coeff(Index row, Index col) const
324  {
325  return m_argImpl.coeff(col, row);
326  }
327 
328  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
329  CoeffReturnType coeff(Index index) const
330  {
331  return m_argImpl.coeff(index);
332  }
333 
334  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
335  Scalar& coeffRef(Index row, Index col)
336  {
337  return m_argImpl.coeffRef(col, row);
338  }
339 
340  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
341  typename XprType::Scalar& coeffRef(Index index)
342  {
343  return m_argImpl.coeffRef(index);
344  }
345 
346  template<int LoadMode, typename PacketType>
347  EIGEN_STRONG_INLINE
348  PacketType packet(Index row, Index col) const
349  {
350  return m_argImpl.template packet<LoadMode,PacketType>(col, row);
351  }
352 
353  template<int LoadMode, typename PacketType>
354  EIGEN_STRONG_INLINE
355  PacketType packet(Index index) const
356  {
357  return m_argImpl.template packet<LoadMode,PacketType>(index);
358  }
359 
360  template<int StoreMode, typename PacketType>
361  EIGEN_STRONG_INLINE
362  void writePacket(Index row, Index col, const PacketType& x)
363  {
364  m_argImpl.template writePacket<StoreMode,PacketType>(col, row, x);
365  }
366 
367  template<int StoreMode, typename PacketType>
368  EIGEN_STRONG_INLINE
369  void writePacket(Index index, const PacketType& x)
370  {
371  m_argImpl.template writePacket<StoreMode,PacketType>(index, x);
372  }
373 
374 protected:
375  evaluator<ArgType> m_argImpl;
376 };
377 
378 // -------------------- CwiseNullaryOp --------------------
379 // Like Matrix and Array, this is not really a unary expression, so we directly specialize evaluator.
380 // Likewise, there is not need to more sophisticated dispatching here.
381 
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>
387 {
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); }
392 
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); }
395 };
396 
397 template<typename Scalar,typename NullaryOp>
398 struct nullary_wrapper<Scalar,NullaryOp,true,false,false>
399 {
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>(); }
403 };
404 
405 template<typename Scalar,typename NullaryOp>
406 struct nullary_wrapper<Scalar,NullaryOp,false,false,true>
407 {
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); }
411 };
412 
413 // We need the following specialization for vector-only functors assigned to a runtime vector,
414 // for instance, using linspace and assigning a RowVectorXd to a MatrixXd or even a row of a MatrixXd.
415 // In this case, i==0 and j is used for the actual iteration.
416 template<typename Scalar,typename NullaryOp>
417 struct nullary_wrapper<Scalar,NullaryOp,false,true,false>
418 {
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);
422  return op(i+j);
423  }
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);
427  }
428 
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); }
433 };
434 
435 template<typename Scalar,typename NullaryOp>
436 struct nullary_wrapper<Scalar,NullaryOp,false,false,false> {};
437 
438 #if 0 && EIGEN_COMP_MSVC>0
439 // Disable this ugly workaround. This is now handled in traits<Ref>::match,
440 // but this piece of code might still become handly if some other weird compilation
441 // erros pop up again.
442 
443 // MSVC exhibits a weird compilation error when
444 // compiling:
445 // Eigen::MatrixXf A = MatrixXf::Random(3,3);
446 // Ref<const MatrixXf> R = 2.f*A;
447 // and that has_*ary_operator<scalar_constant_op<float>> have not been instantiated yet.
448 // The "problem" is that evaluator<2.f*A> is instantiated by traits<Ref>::match<2.f*A>
449 // and at that time has_*ary_operator<T> returns true regardless of T.
450 // Then nullary_wrapper is badly instantiated as nullary_wrapper<.,.,true,true,true>.
451 // The trick is thus to defer the proper instantiation of nullary_wrapper when coeff(),
452 // and packet() are really instantiated as implemented below:
453 
454 // This is a simple wrapper around Index to enforce the re-instantiation of
455 // has_*ary_operator when needed.
456 template<typename T> struct nullary_wrapper_workaround_msvc {
457  nullary_wrapper_workaround_msvc(const T&);
458  operator T()const;
459 };
460 
461 template<typename Scalar,typename NullaryOp>
462 struct nullary_wrapper<Scalar,NullaryOp,true,true,true>
463 {
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);
470  }
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);
477  }
478 
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);
485  }
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);
492  }
493 };
494 #endif // MSVC workaround
495 
496 template<typename NullaryOp, typename PlainObjectType>
497 struct evaluator<CwiseNullaryOp<NullaryOp,PlainObjectType> >
498  : evaluator_base<CwiseNullaryOp<NullaryOp,PlainObjectType> >
499 {
501  typedef typename internal::remove_all<PlainObjectType>::type PlainObjectTypeCleaned;
502 
503  enum {
505 
507  & ( HereditaryBits
511  Alignment = AlignedMax
512  };
513 
514  EIGEN_DEVICE_FUNC explicit evaluator(const XprType& n)
515  : m_functor(n.functor()), m_wrapper()
516  {
517  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
518  }
519 
520  typedef typename XprType::CoeffReturnType CoeffReturnType;
521 
522  template <typename IndexType>
523  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
524  CoeffReturnType coeff(IndexType row, IndexType col) const
525  {
526  return m_wrapper(m_functor, row, col);
527  }
528 
529  template <typename IndexType>
530  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
531  CoeffReturnType coeff(IndexType index) const
532  {
533  return m_wrapper(m_functor,index);
534  }
535 
536  template<int LoadMode, typename PacketType, typename IndexType>
537  EIGEN_STRONG_INLINE
538  PacketType packet(IndexType row, IndexType col) const
539  {
540  return m_wrapper.template packetOp<PacketType>(m_functor, row, col);
541  }
542 
543  template<int LoadMode, typename PacketType, typename IndexType>
544  EIGEN_STRONG_INLINE
545  PacketType packet(IndexType index) const
546  {
547  return m_wrapper.template packetOp<PacketType>(m_functor, index);
548  }
549 
550 protected:
551  const NullaryOp m_functor;
553 };
554 
555 // -------------------- CwiseUnaryOp --------------------
556 
557 template<typename UnaryOp, typename ArgType>
558 struct unary_evaluator<CwiseUnaryOp<UnaryOp, ArgType>, IndexBased >
559  : evaluator_base<CwiseUnaryOp<UnaryOp, ArgType> >
560 {
562 
563  enum {
565 
569  };
570 
571  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
572  explicit unary_evaluator(const XprType& op) : m_d(op)
573  {
574  EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
575  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
576  }
577 
578  typedef typename XprType::CoeffReturnType CoeffReturnType;
579 
580  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
581  CoeffReturnType coeff(Index row, Index col) const
582  {
583  return m_d.func()(m_d.argImpl.coeff(row, col));
584  }
585 
586  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
587  CoeffReturnType coeff(Index index) const
588  {
589  return m_d.func()(m_d.argImpl.coeff(index));
590  }
591 
592  template<int LoadMode, typename PacketType>
593  EIGEN_STRONG_INLINE
594  PacketType packet(Index row, Index col) const
595  {
596  return m_d.func().packetOp(m_d.argImpl.template packet<LoadMode, PacketType>(row, col));
597  }
598 
599  template<int LoadMode, typename PacketType>
600  EIGEN_STRONG_INLINE
601  PacketType packet(Index index) const
602  {
603  return m_d.func().packetOp(m_d.argImpl.template packet<LoadMode, PacketType>(index));
604  }
605 
606 protected:
607 
608  // this helper permits to completely eliminate the functor if it is empty
609  class Data : private UnaryOp
610  {
611  public:
612  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
613  Data(const XprType& xpr) : UnaryOp(xpr.functor()), argImpl(xpr.nestedExpression()) {}
614  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
615  const UnaryOp& func() const { return static_cast<const UnaryOp&>(*this); }
616  evaluator<ArgType> argImpl;
617  };
618 
619  Data m_d;
620 };
621 
622 // -------------------- CwiseTernaryOp --------------------
623 
624 // this is a ternary expression
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> >
628 {
631 
632  EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) : Base(xpr) {}
633 };
634 
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> >
638 {
640 
641  enum {
643 
644  Arg1Flags = evaluator<Arg1>::Flags,
645  Arg2Flags = evaluator<Arg2>::Flags,
646  Arg3Flags = evaluator<Arg3>::Flags,
648  StorageOrdersAgree = (int(Arg1Flags)&RowMajorBit)==(int(Arg2Flags)&RowMajorBit) && (int(Arg1Flags)&RowMajorBit)==(int(Arg3Flags)&RowMajorBit),
649  Flags0 = (int(Arg1Flags) | int(Arg2Flags) | int(Arg3Flags)) & (
650  HereditaryBits
651  | (int(Arg1Flags) & int(Arg2Flags) & int(Arg3Flags) &
652  ( (StorageOrdersAgree ? LinearAccessBit : 0)
653  | (functor_traits<TernaryOp>::PacketAccess && StorageOrdersAgree && SameType ? PacketAccessBit : 0)
654  )
655  )
656  ),
657  Flags = (Flags0 & ~RowMajorBit) | (Arg1Flags & RowMajorBit),
658  Alignment = EIGEN_PLAIN_ENUM_MIN(
661  };
662 
663  EIGEN_DEVICE_FUNC explicit ternary_evaluator(const XprType& xpr) : m_d(xpr)
664  {
665  EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<TernaryOp>::Cost);
666  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
667  }
668 
669  typedef typename XprType::CoeffReturnType CoeffReturnType;
670 
671  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
672  CoeffReturnType coeff(Index row, Index col) const
673  {
674  return m_d.func()(m_d.arg1Impl.coeff(row, col), m_d.arg2Impl.coeff(row, col), m_d.arg3Impl.coeff(row, col));
675  }
676 
677  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
678  CoeffReturnType coeff(Index index) const
679  {
680  return m_d.func()(m_d.arg1Impl.coeff(index), m_d.arg2Impl.coeff(index), m_d.arg3Impl.coeff(index));
681  }
682 
683  template<int LoadMode, typename PacketType>
684  EIGEN_STRONG_INLINE
685  PacketType packet(Index row, Index col) const
686  {
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));
690  }
691 
692  template<int LoadMode, typename PacketType>
693  EIGEN_STRONG_INLINE
694  PacketType packet(Index index) const
695  {
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));
699  }
700 
701 protected:
702  // this helper permits to completely eliminate the functor if it is empty
703  struct Data : private TernaryOp
704  {
705  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
706  Data(const XprType& xpr) : TernaryOp(xpr.functor()), arg1Impl(xpr.arg1()), arg2Impl(xpr.arg2()), arg3Impl(xpr.arg3()) {}
707  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
708  const TernaryOp& func() const { return static_cast<const TernaryOp&>(*this); }
709  evaluator<Arg1> arg1Impl;
710  evaluator<Arg2> arg2Impl;
711  evaluator<Arg3> arg3Impl;
712  };
713 
714  Data m_d;
715 };
716 
717 // -------------------- CwiseBinaryOp --------------------
718 
719 // this is a binary expression
720 template<typename BinaryOp, typename Lhs, typename Rhs>
721 struct evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
722  : public binary_evaluator<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
723 {
726 
727  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
728  explicit evaluator(const XprType& xpr) : Base(xpr) {}
729 };
730 
731 template<typename BinaryOp, typename Lhs, typename Rhs>
733  : evaluator_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
734 {
736 
737  enum {
739 
740  LhsFlags = evaluator<Lhs>::Flags,
741  RhsFlags = evaluator<Rhs>::Flags,
743  StorageOrdersAgree = (int(LhsFlags)&RowMajorBit)==(int(RhsFlags)&RowMajorBit),
744  Flags0 = (int(LhsFlags) | int(RhsFlags)) & (
745  HereditaryBits
746  | (int(LhsFlags) & int(RhsFlags) &
747  ( (StorageOrdersAgree ? LinearAccessBit : 0)
748  | (functor_traits<BinaryOp>::PacketAccess && StorageOrdersAgree && SameType ? PacketAccessBit : 0)
749  )
750  )
751  ),
752  Flags = (Flags0 & ~RowMajorBit) | (LhsFlags & RowMajorBit),
753  Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<Lhs>::Alignment,evaluator<Rhs>::Alignment)
754  };
755 
756  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
757  explicit binary_evaluator(const XprType& xpr) : m_d(xpr)
758  {
759  EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost);
760  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
761  }
762 
763  typedef typename XprType::CoeffReturnType CoeffReturnType;
764 
765  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
766  CoeffReturnType coeff(Index row, Index col) const
767  {
768  return m_d.func()(m_d.lhsImpl.coeff(row, col), m_d.rhsImpl.coeff(row, col));
769  }
770 
771  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
772  CoeffReturnType coeff(Index index) const
773  {
774  return m_d.func()(m_d.lhsImpl.coeff(index), m_d.rhsImpl.coeff(index));
775  }
776 
777  template<int LoadMode, typename PacketType>
778  EIGEN_STRONG_INLINE
779  PacketType packet(Index row, Index col) const
780  {
781  return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode,PacketType>(row, col),
782  m_d.rhsImpl.template packet<LoadMode,PacketType>(row, col));
783  }
784 
785  template<int LoadMode, typename PacketType>
786  EIGEN_STRONG_INLINE
787  PacketType packet(Index index) const
788  {
789  return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode,PacketType>(index),
790  m_d.rhsImpl.template packet<LoadMode,PacketType>(index));
791  }
792 
793 protected:
794 
795  // this helper permits to completely eliminate the functor if it is empty
796  struct Data : private BinaryOp
797  {
798  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
799  Data(const XprType& xpr) : BinaryOp(xpr.functor()), lhsImpl(xpr.lhs()), rhsImpl(xpr.rhs()) {}
800  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
801  const BinaryOp& func() const { return static_cast<const BinaryOp&>(*this); }
802  evaluator<Lhs> lhsImpl;
803  evaluator<Rhs> rhsImpl;
804  };
805 
806  Data m_d;
807 };
808 
809 // -------------------- CwiseUnaryView --------------------
810 
811 template<typename UnaryOp, typename ArgType>
812 struct unary_evaluator<CwiseUnaryView<UnaryOp, ArgType>, IndexBased>
813  : evaluator_base<CwiseUnaryView<UnaryOp, ArgType> >
814 {
816 
817  enum {
819 
820  Flags = (evaluator<ArgType>::Flags & (HereditaryBits | LinearAccessBit | DirectAccessBit)),
821 
822  Alignment = 0 // FIXME it is not very clear why alignment is necessarily lost...
823  };
824 
825  EIGEN_DEVICE_FUNC explicit unary_evaluator(const XprType& op) : m_d(op)
826  {
827  EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<UnaryOp>::Cost);
828  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
829  }
830 
831  typedef typename XprType::Scalar Scalar;
832  typedef typename XprType::CoeffReturnType CoeffReturnType;
833 
834  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
835  CoeffReturnType coeff(Index row, Index col) const
836  {
837  return m_d.func()(m_d.argImpl.coeff(row, col));
838  }
839 
840  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
841  CoeffReturnType coeff(Index index) const
842  {
843  return m_d.func()(m_d.argImpl.coeff(index));
844  }
845 
846  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
847  Scalar& coeffRef(Index row, Index col)
848  {
849  return m_d.func()(m_d.argImpl.coeffRef(row, col));
850  }
851 
852  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
853  Scalar& coeffRef(Index index)
854  {
855  return m_d.func()(m_d.argImpl.coeffRef(index));
856  }
857 
858 protected:
859 
860  // this helper permits to completely eliminate the functor if it is empty
861  struct Data : private UnaryOp
862  {
863  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
864  Data(const XprType& xpr) : UnaryOp(xpr.functor()), argImpl(xpr.nestedExpression()) {}
865  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
866  const UnaryOp& func() const { return static_cast<const UnaryOp&>(*this); }
867  evaluator<ArgType> argImpl;
868  };
869 
870  Data m_d;
871 };
872 
873 // -------------------- Map --------------------
874 
875 // FIXME perhaps the PlainObjectType could be provided by Derived::PlainObject ?
876 // but that might complicate template specialization
877 template<typename Derived, typename PlainObjectType>
878 struct mapbase_evaluator;
879 
880 template<typename Derived, typename PlainObjectType>
882 {
883  typedef Derived XprType;
884  typedef typename XprType::PointerType PointerType;
885  typedef typename XprType::Scalar Scalar;
886  typedef typename XprType::CoeffReturnType CoeffReturnType;
887 
888  enum {
889  IsRowMajor = XprType::RowsAtCompileTime,
890  ColsAtCompileTime = XprType::ColsAtCompileTime,
891  CoeffReadCost = NumTraits<Scalar>::ReadCost
892  };
893 
894  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
895  explicit mapbase_evaluator(const XprType& map)
896  : m_data(const_cast<PointerType>(map.data())),
897  m_innerStride(map.innerStride()),
898  m_outerStride(map.outerStride())
899  {
901  PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1);
902  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
903  }
904 
905  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
906  CoeffReturnType coeff(Index row, Index col) const
907  {
908  return m_data[col * colStride() + row * rowStride()];
909  }
910 
911  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
912  CoeffReturnType coeff(Index index) const
913  {
914  return m_data[index * m_innerStride.value()];
915  }
916 
917  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
918  Scalar& coeffRef(Index row, Index col)
919  {
920  return m_data[col * colStride() + row * rowStride()];
921  }
922 
923  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
924  Scalar& coeffRef(Index index)
925  {
926  return m_data[index * m_innerStride.value()];
927  }
928 
929  template<int LoadMode, typename PacketType>
930  EIGEN_STRONG_INLINE
931  PacketType packet(Index row, Index col) const
932  {
933  PointerType ptr = m_data + row * rowStride() + col * colStride();
934  return internal::ploadt<PacketType, LoadMode>(ptr);
935  }
936 
937  template<int LoadMode, typename PacketType>
938  EIGEN_STRONG_INLINE
939  PacketType packet(Index index) const
940  {
941  return internal::ploadt<PacketType, LoadMode>(m_data + index * m_innerStride.value());
942  }
943 
944  template<int StoreMode, typename PacketType>
945  EIGEN_STRONG_INLINE
946  void writePacket(Index row, Index col, const PacketType& x)
947  {
948  PointerType ptr = m_data + row * rowStride() + col * colStride();
949  return internal::pstoret<Scalar, PacketType, StoreMode>(ptr, x);
950  }
951 
952  template<int StoreMode, typename PacketType>
953  EIGEN_STRONG_INLINE
954  void writePacket(Index index, const PacketType& x)
955  {
956  internal::pstoret<Scalar, PacketType, StoreMode>(m_data + index * m_innerStride.value(), x);
957  }
958 protected:
959  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
960  Index rowStride() const { return XprType::IsRowMajor ? m_outerStride.value() : m_innerStride.value(); }
961  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
962  Index colStride() const { return XprType::IsRowMajor ? m_innerStride.value() : m_outerStride.value(); }
963 
964  PointerType m_data;
967 };
968 
969 template<typename PlainObjectType, int MapOptions, typename StrideType>
970 struct evaluator<Map<PlainObjectType, MapOptions, StrideType> >
971  : public mapbase_evaluator<Map<PlainObjectType, MapOptions, StrideType>, PlainObjectType>
972 {
974  typedef typename XprType::Scalar Scalar;
975  // TODO: should check for smaller packet types once we can handle multi-sized packet types
976  typedef typename packet_traits<Scalar>::type PacketScalar;
977 
978  enum {
979  InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
980  ? int(PlainObjectType::InnerStrideAtCompileTime)
981  : int(StrideType::InnerStrideAtCompileTime),
982  OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
983  ? int(PlainObjectType::OuterStrideAtCompileTime)
984  : int(StrideType::OuterStrideAtCompileTime),
985  HasNoInnerStride = InnerStrideAtCompileTime == 1,
986  HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
987  HasNoStride = HasNoInnerStride && HasNoOuterStride,
988  IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic,
989 
990  PacketAccessMask = bool(HasNoInnerStride) ? ~int(0) : ~int(PacketAccessBit),
991  LinearAccessMask = bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime) ? ~int(0) : ~int(LinearAccessBit),
992  Flags = int( evaluator<PlainObjectType>::Flags) & (LinearAccessMask&PacketAccessMask),
993 
994  Alignment = int(MapOptions)&int(AlignedMask)
995  };
996 
997  EIGEN_DEVICE_FUNC explicit evaluator(const XprType& map)
999  { }
1000 };
1001 
1002 // -------------------- Ref --------------------
1003 
1004 template<typename PlainObjectType, int RefOptions, typename StrideType>
1005 struct evaluator<Ref<PlainObjectType, RefOptions, StrideType> >
1006  : public mapbase_evaluator<Ref<PlainObjectType, RefOptions, StrideType>, PlainObjectType>
1007 {
1009 
1010  enum {
1013  };
1014 
1015  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1016  explicit evaluator(const XprType& ref)
1018  { }
1019 };
1020 
1021 // -------------------- Block --------------------
1022 
1023 template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel,
1025 
1026 template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel>
1027 struct evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
1028  : block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel>
1029 {
1031  typedef typename XprType::Scalar Scalar;
1032  // TODO: should check for smaller packet types once we can handle multi-sized packet types
1033  typedef typename packet_traits<Scalar>::type PacketScalar;
1034 
1035  enum {
1036  CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1037 
1038  RowsAtCompileTime = traits<XprType>::RowsAtCompileTime,
1039  ColsAtCompileTime = traits<XprType>::ColsAtCompileTime,
1040  MaxRowsAtCompileTime = traits<XprType>::MaxRowsAtCompileTime,
1041  MaxColsAtCompileTime = traits<XprType>::MaxColsAtCompileTime,
1042 
1043  ArgTypeIsRowMajor = (int(evaluator<ArgType>::Flags)&RowMajorBit) != 0,
1044  IsRowMajor = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? 1
1045  : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
1046  : ArgTypeIsRowMajor,
1047  HasSameStorageOrderAsArgType = (IsRowMajor == ArgTypeIsRowMajor),
1048  InnerSize = IsRowMajor ? int(ColsAtCompileTime) : int(RowsAtCompileTime),
1049  InnerStrideAtCompileTime = HasSameStorageOrderAsArgType
1052  OuterStrideAtCompileTime = HasSameStorageOrderAsArgType
1055  MaskPacketAccessBit = (InnerStrideAtCompileTime == 1 || HasSameStorageOrderAsArgType) ? PacketAccessBit : 0,
1056 
1057  FlagsLinearAccessBit = (RowsAtCompileTime == 1 || ColsAtCompileTime == 1 || (InnerPanel && (evaluator<ArgType>::Flags&LinearAccessBit))) ? LinearAccessBit : 0,
1058  FlagsRowMajorBit = XprType::Flags&RowMajorBit,
1059  Flags0 = evaluator<ArgType>::Flags & ( (HereditaryBits & ~RowMajorBit) |
1060  DirectAccessBit |
1061  MaskPacketAccessBit),
1062  Flags = Flags0 | FlagsLinearAccessBit | FlagsRowMajorBit,
1063 
1064  PacketAlignment = unpacket_traits<PacketScalar>::alignment,
1065  Alignment0 = (InnerPanel && (OuterStrideAtCompileTime!=Dynamic)
1066  && (OuterStrideAtCompileTime!=0)
1067  && (((OuterStrideAtCompileTime * int(sizeof(Scalar))) % int(PacketAlignment)) == 0)) ? int(PacketAlignment) : 0,
1068  Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<ArgType>::Alignment, Alignment0)
1069  };
1071  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1072  explicit evaluator(const XprType& block) : block_evaluator_type(block)
1073  {
1074  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
1075  }
1076 };
1077 
1078 // no direct-access => dispatch to a unary evaluator
1079 template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel>
1080 struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, /*HasDirectAccess*/ false>
1081  : unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
1082 {
1084 
1085  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1086  explicit block_evaluator(const XprType& block)
1087  : unary_evaluator<XprType>(block)
1088  {}
1089 };
1090 
1091 template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel>
1092 struct unary_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>, IndexBased>
1093  : evaluator_base<Block<ArgType, BlockRows, BlockCols, InnerPanel> >
1094 {
1096 
1097  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1098  explicit unary_evaluator(const XprType& block)
1099  : m_argImpl(block.nestedExpression()),
1100  m_startRow(block.startRow()),
1101  m_startCol(block.startCol()),
1102  m_linear_offset(ForwardLinearAccess?(ArgType::IsRowMajor ? block.startRow()*block.nestedExpression().cols() + block.startCol() : block.startCol()*block.nestedExpression().rows() + block.startRow()):0)
1103  { }
1104 
1105  typedef typename XprType::Scalar Scalar;
1106  typedef typename XprType::CoeffReturnType CoeffReturnType;
1107 
1108  enum {
1109  RowsAtCompileTime = XprType::RowsAtCompileTime,
1110  ForwardLinearAccess = (InnerPanel || int(XprType::IsRowMajor)==int(ArgType::IsRowMajor)) && bool(evaluator<ArgType>::Flags&LinearAccessBit)
1111  };
1112 
1113  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1114  CoeffReturnType coeff(Index row, Index col) const
1115  {
1116  return m_argImpl.coeff(m_startRow.value() + row, m_startCol.value() + col);
1117  }
1118 
1119  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1120  CoeffReturnType coeff(Index index) const
1121  {
1122  return linear_coeff_impl(index, bool_constant<ForwardLinearAccess>());
1123  }
1124 
1125  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1126  Scalar& coeffRef(Index row, Index col)
1127  {
1128  return m_argImpl.coeffRef(m_startRow.value() + row, m_startCol.value() + col);
1129  }
1130 
1131  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1132  Scalar& coeffRef(Index index)
1133  {
1134  return linear_coeffRef_impl(index, bool_constant<ForwardLinearAccess>());
1135  }
1136 
1137  template<int LoadMode, typename PacketType>
1138  EIGEN_STRONG_INLINE
1139  PacketType packet(Index row, Index col) const
1140  {
1141  return m_argImpl.template packet<LoadMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col);
1142  }
1143 
1144  template<int LoadMode, typename PacketType>
1145  EIGEN_STRONG_INLINE
1146  PacketType packet(Index index) const
1147  {
1148  if (ForwardLinearAccess)
1149  return m_argImpl.template packet<LoadMode,PacketType>(m_linear_offset.value() + index);
1150  else
1151  return packet<LoadMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
1152  RowsAtCompileTime == 1 ? index : 0);
1153  }
1154 
1155  template<int StoreMode, typename PacketType>
1156  EIGEN_STRONG_INLINE
1157  void writePacket(Index row, Index col, const PacketType& x)
1158  {
1159  return m_argImpl.template writePacket<StoreMode,PacketType>(m_startRow.value() + row, m_startCol.value() + col, x);
1160  }
1161 
1162  template<int StoreMode, typename PacketType>
1163  EIGEN_STRONG_INLINE
1164  void writePacket(Index index, const PacketType& x)
1165  {
1166  if (ForwardLinearAccess)
1167  return m_argImpl.template writePacket<StoreMode,PacketType>(m_linear_offset.value() + index, x);
1168  else
1169  return writePacket<StoreMode,PacketType>(RowsAtCompileTime == 1 ? 0 : index,
1170  RowsAtCompileTime == 1 ? index : 0,
1171  x);
1172  }
1173 
1174 protected:
1175  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1176  CoeffReturnType linear_coeff_impl(Index index, internal::true_type /* ForwardLinearAccess */) const
1177  {
1178  return m_argImpl.coeff(m_linear_offset.value() + index);
1179  }
1180  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1181  CoeffReturnType linear_coeff_impl(Index index, internal::false_type /* not ForwardLinearAccess */) const
1182  {
1183  return coeff(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
1184  }
1185 
1186  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1187  Scalar& linear_coeffRef_impl(Index index, internal::true_type /* ForwardLinearAccess */)
1188  {
1189  return m_argImpl.coeffRef(m_linear_offset.value() + index);
1190  }
1191  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1192  Scalar& linear_coeffRef_impl(Index index, internal::false_type /* not ForwardLinearAccess */)
1193  {
1194  return coeffRef(RowsAtCompileTime == 1 ? 0 : index, RowsAtCompileTime == 1 ? index : 0);
1195  }
1196 
1197  evaluator<ArgType> m_argImpl;
1198  const variable_if_dynamic<Index, (ArgType::RowsAtCompileTime == 1 && BlockRows==1) ? 0 : Dynamic> m_startRow;
1199  const variable_if_dynamic<Index, (ArgType::ColsAtCompileTime == 1 && BlockCols==1) ? 0 : Dynamic> m_startCol;
1201 };
1202 
1203 // TODO: This evaluator does not actually use the child evaluator;
1204 // all action is via the data() as returned by the Block expression.
1205 
1206 template<typename ArgType, int BlockRows, int BlockCols, bool InnerPanel>
1207 struct block_evaluator<ArgType, BlockRows, BlockCols, InnerPanel, /* HasDirectAccess */ true>
1208  : mapbase_evaluator<Block<ArgType, BlockRows, BlockCols, InnerPanel>,
1209  typename Block<ArgType, BlockRows, BlockCols, InnerPanel>::PlainObject>
1210 {
1212  typedef typename XprType::Scalar Scalar;
1213 
1214  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1215  explicit block_evaluator(const XprType& block)
1217  {
1218  // TODO: for the 3.3 release, this should be turned to an internal assertion, but let's keep it as is for the beta lifetime
1219  eigen_assert(((internal::UIntPtr(block.data()) % EIGEN_PLAIN_ENUM_MAX(1,evaluator<XprType>::Alignment)) == 0) && "data is not aligned");
1220  }
1221 };
1222 
1223 
1224 // -------------------- Select --------------------
1225 // NOTE shall we introduce a ternary_evaluator?
1226 
1227 // TODO enable vectorization for Select
1228 template<typename ConditionMatrixType, typename ThenMatrixType, typename ElseMatrixType>
1229 struct evaluator<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
1230  : evaluator_base<Select<ConditionMatrixType, ThenMatrixType, ElseMatrixType> >
1231 {
1233  enum {
1235  + EIGEN_PLAIN_ENUM_MAX(evaluator<ThenMatrixType>::CoeffReadCost,
1237 
1238  Flags = (unsigned int)evaluator<ThenMatrixType>::Flags & evaluator<ElseMatrixType>::Flags & HereditaryBits,
1239 
1241  };
1242 
1243  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1244  explicit evaluator(const XprType& select)
1245  : m_conditionImpl(select.conditionMatrix()),
1246  m_thenImpl(select.thenMatrix()),
1247  m_elseImpl(select.elseMatrix())
1248  {
1249  EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
1250  }
1251 
1252  typedef typename XprType::CoeffReturnType CoeffReturnType;
1253 
1254  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1255  CoeffReturnType coeff(Index row, Index col) const
1256  {
1257  if (m_conditionImpl.coeff(row, col))
1258  return m_thenImpl.coeff(row, col);
1259  else
1260  return m_elseImpl.coeff(row, col);
1261  }
1262 
1263  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1264  CoeffReturnType coeff(Index index) const
1265  {
1266  if (m_conditionImpl.coeff(index))
1267  return m_thenImpl.coeff(index);
1268  else
1269  return m_elseImpl.coeff(index);
1270  }
1271 
1272 protected:
1273  evaluator<ConditionMatrixType> m_conditionImpl;
1274  evaluator<ThenMatrixType> m_thenImpl;
1275  evaluator<ElseMatrixType> m_elseImpl;
1276 };
1277 
1278 
1279 // -------------------- Replicate --------------------
1280 
1281 template<typename ArgType, int RowFactor, int ColFactor>
1282 struct unary_evaluator<Replicate<ArgType, RowFactor, ColFactor> >
1283  : evaluator_base<Replicate<ArgType, RowFactor, ColFactor> >
1284 {
1286  typedef typename XprType::CoeffReturnType CoeffReturnType;
1287  enum {
1288  Factor = (RowFactor==Dynamic || ColFactor==Dynamic) ? Dynamic : RowFactor*ColFactor
1289  };
1291  typedef typename internal::remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
1292 
1293  enum {
1295  LinearAccessMask = XprType::IsVectorAtCompileTime ? LinearAccessBit : 0,
1296  Flags = (evaluator<ArgTypeNestedCleaned>::Flags & (HereditaryBits|LinearAccessMask) & ~RowMajorBit) | (traits<XprType>::Flags & RowMajorBit),
1297 
1299  };
1300 
1301  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1302  explicit unary_evaluator(const XprType& replicate)
1303  : m_arg(replicate.nestedExpression()),
1304  m_argImpl(m_arg),
1305  m_rows(replicate.nestedExpression().rows()),
1306  m_cols(replicate.nestedExpression().cols())
1307  {}
1308 
1309  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1310  CoeffReturnType coeff(Index row, Index col) const
1311  {
1312  // try to avoid using modulo; this is a pure optimization strategy
1313  const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
1314  : RowFactor==1 ? row
1315  : row % m_rows.value();
1316  const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
1317  : ColFactor==1 ? col
1318  : col % m_cols.value();
1319 
1320  return m_argImpl.coeff(actual_row, actual_col);
1321  }
1322 
1323  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1324  CoeffReturnType coeff(Index index) const
1325  {
1326  // try to avoid using modulo; this is a pure optimization strategy
1327  const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
1328  ? (ColFactor==1 ? index : index%m_cols.value())
1329  : (RowFactor==1 ? index : index%m_rows.value());
1330 
1331  return m_argImpl.coeff(actual_index);
1332  }
1333 
1334  template<int LoadMode, typename PacketType>
1335  EIGEN_STRONG_INLINE
1336  PacketType packet(Index row, Index col) const
1337  {
1338  const Index actual_row = internal::traits<XprType>::RowsAtCompileTime==1 ? 0
1339  : RowFactor==1 ? row
1340  : row % m_rows.value();
1341  const Index actual_col = internal::traits<XprType>::ColsAtCompileTime==1 ? 0
1342  : ColFactor==1 ? col
1343  : col % m_cols.value();
1344 
1345  return m_argImpl.template packet<LoadMode,PacketType>(actual_row, actual_col);
1346  }
1347 
1348  template<int LoadMode, typename PacketType>
1349  EIGEN_STRONG_INLINE
1350  PacketType packet(Index index) const
1351  {
1352  const Index actual_index = internal::traits<XprType>::RowsAtCompileTime==1
1353  ? (ColFactor==1 ? index : index%m_cols.value())
1354  : (RowFactor==1 ? index : index%m_rows.value());
1355 
1356  return m_argImpl.template packet<LoadMode,PacketType>(actual_index);
1357  }
1358 
1359 protected:
1360  const ArgTypeNested m_arg;
1364 };
1365 
1366 // -------------------- MatrixWrapper and ArrayWrapper --------------------
1367 //
1368 // evaluator_wrapper_base<T> is a common base class for the
1369 // MatrixWrapper and ArrayWrapper evaluators.
1370 
1371 template<typename XprType>
1373  : evaluator_base<XprType>
1374 {
1375  typedef typename remove_all<typename XprType::NestedExpressionType>::type ArgType;
1376  enum {
1377  CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1378  Flags = evaluator<ArgType>::Flags,
1379  Alignment = evaluator<ArgType>::Alignment
1380  };
1381 
1382  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1383  explicit evaluator_wrapper_base(const ArgType& arg) : m_argImpl(arg) {}
1384 
1385  typedef typename ArgType::Scalar Scalar;
1386  typedef typename ArgType::CoeffReturnType CoeffReturnType;
1387 
1388  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1389  CoeffReturnType coeff(Index row, Index col) const
1390  {
1391  return m_argImpl.coeff(row, col);
1392  }
1393 
1394  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1395  CoeffReturnType coeff(Index index) const
1396  {
1397  return m_argImpl.coeff(index);
1398  }
1399 
1400  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1401  Scalar& coeffRef(Index row, Index col)
1402  {
1403  return m_argImpl.coeffRef(row, col);
1404  }
1405 
1406  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1407  Scalar& coeffRef(Index index)
1408  {
1409  return m_argImpl.coeffRef(index);
1410  }
1411 
1412  template<int LoadMode, typename PacketType>
1413  EIGEN_STRONG_INLINE
1414  PacketType packet(Index row, Index col) const
1415  {
1416  return m_argImpl.template packet<LoadMode,PacketType>(row, col);
1417  }
1418 
1419  template<int LoadMode, typename PacketType>
1420  EIGEN_STRONG_INLINE
1421  PacketType packet(Index index) const
1422  {
1423  return m_argImpl.template packet<LoadMode,PacketType>(index);
1424  }
1425 
1426  template<int StoreMode, typename PacketType>
1427  EIGEN_STRONG_INLINE
1428  void writePacket(Index row, Index col, const PacketType& x)
1429  {
1430  m_argImpl.template writePacket<StoreMode>(row, col, x);
1431  }
1432 
1433  template<int StoreMode, typename PacketType>
1434  EIGEN_STRONG_INLINE
1435  void writePacket(Index index, const PacketType& x)
1436  {
1437  m_argImpl.template writePacket<StoreMode>(index, x);
1438  }
1439 
1440 protected:
1441  evaluator<ArgType> m_argImpl;
1442 };
1443 
1444 template<typename TArgType>
1445 struct unary_evaluator<MatrixWrapper<TArgType> >
1446  : evaluator_wrapper_base<MatrixWrapper<TArgType> >
1447 {
1449 
1450  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1451  explicit unary_evaluator(const XprType& wrapper)
1452  : evaluator_wrapper_base<MatrixWrapper<TArgType> >(wrapper.nestedExpression())
1453  { }
1454 };
1455 
1456 template<typename TArgType>
1457 struct unary_evaluator<ArrayWrapper<TArgType> >
1458  : evaluator_wrapper_base<ArrayWrapper<TArgType> >
1459 {
1461 
1462  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1463  explicit unary_evaluator(const XprType& wrapper)
1464  : evaluator_wrapper_base<ArrayWrapper<TArgType> >(wrapper.nestedExpression())
1465  { }
1466 };
1467 
1468 
1469 // -------------------- Reverse --------------------
1470 
1471 // defined in Reverse.h:
1472 template<typename PacketType, bool ReversePacket> struct reverse_packet_cond;
1473 
1474 template<typename ArgType, int Direction>
1475 struct unary_evaluator<Reverse<ArgType, Direction> >
1476  : evaluator_base<Reverse<ArgType, Direction> >
1477 {
1479  typedef typename XprType::Scalar Scalar;
1480  typedef typename XprType::CoeffReturnType CoeffReturnType;
1481 
1482  enum {
1483  IsRowMajor = XprType::IsRowMajor,
1484  IsColMajor = !IsRowMajor,
1485  ReverseRow = (Direction == Vertical) || (Direction == BothDirections),
1486  ReverseCol = (Direction == Horizontal) || (Direction == BothDirections),
1487  ReversePacket = (Direction == BothDirections)
1488  || ((Direction == Vertical) && IsColMajor)
1489  || ((Direction == Horizontal) && IsRowMajor),
1490 
1491  CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1492 
1493  // let's enable LinearAccess only with vectorization because of the product overhead
1494  // FIXME enable DirectAccess with negative strides?
1495  Flags0 = evaluator<ArgType>::Flags,
1496  LinearAccess = ( (Direction==BothDirections) && (int(Flags0)&PacketAccessBit) )
1497  || ((ReverseRow && XprType::ColsAtCompileTime==1) || (ReverseCol && XprType::RowsAtCompileTime==1))
1498  ? LinearAccessBit : 0,
1499 
1500  Flags = int(Flags0) & (HereditaryBits | PacketAccessBit | LinearAccess),
1501 
1502  Alignment = 0 // FIXME in some rare cases, Alignment could be preserved, like a Vector4f.
1503  };
1504 
1505  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1506  explicit unary_evaluator(const XprType& reverse)
1507  : m_argImpl(reverse.nestedExpression()),
1508  m_rows(ReverseRow ? reverse.nestedExpression().rows() : 1),
1509  m_cols(ReverseCol ? reverse.nestedExpression().cols() : 1)
1510  { }
1511 
1512  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1513  CoeffReturnType coeff(Index row, Index col) const
1514  {
1515  return m_argImpl.coeff(ReverseRow ? m_rows.value() - row - 1 : row,
1516  ReverseCol ? m_cols.value() - col - 1 : col);
1517  }
1518 
1519  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1520  CoeffReturnType coeff(Index index) const
1521  {
1522  return m_argImpl.coeff(m_rows.value() * m_cols.value() - index - 1);
1523  }
1524 
1525  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1526  Scalar& coeffRef(Index row, Index col)
1527  {
1528  return m_argImpl.coeffRef(ReverseRow ? m_rows.value() - row - 1 : row,
1529  ReverseCol ? m_cols.value() - col - 1 : col);
1530  }
1531 
1532  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1533  Scalar& coeffRef(Index index)
1534  {
1535  return m_argImpl.coeffRef(m_rows.value() * m_cols.value() - index - 1);
1536  }
1537 
1538  template<int LoadMode, typename PacketType>
1539  EIGEN_STRONG_INLINE
1540  PacketType packet(Index row, Index col) const
1541  {
1542  enum {
1543  PacketSize = unpacket_traits<PacketType>::size,
1544  OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1545  OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1546  };
1548  return reverse_packet::run(m_argImpl.template packet<LoadMode,PacketType>(
1549  ReverseRow ? m_rows.value() - row - OffsetRow : row,
1550  ReverseCol ? m_cols.value() - col - OffsetCol : col));
1551  }
1552 
1553  template<int LoadMode, typename PacketType>
1554  EIGEN_STRONG_INLINE
1555  PacketType packet(Index index) const
1556  {
1557  enum { PacketSize = unpacket_traits<PacketType>::size };
1558  return preverse(m_argImpl.template packet<LoadMode,PacketType>(m_rows.value() * m_cols.value() - index - PacketSize));
1559  }
1560 
1561  template<int LoadMode, typename PacketType>
1562  EIGEN_STRONG_INLINE
1563  void writePacket(Index row, Index col, const PacketType& x)
1564  {
1565  // FIXME we could factorize some code with packet(i,j)
1566  enum {
1567  PacketSize = unpacket_traits<PacketType>::size,
1568  OffsetRow = ReverseRow && IsColMajor ? PacketSize : 1,
1569  OffsetCol = ReverseCol && IsRowMajor ? PacketSize : 1
1570  };
1572  m_argImpl.template writePacket<LoadMode>(
1573  ReverseRow ? m_rows.value() - row - OffsetRow : row,
1574  ReverseCol ? m_cols.value() - col - OffsetCol : col,
1575  reverse_packet::run(x));
1576  }
1577 
1578  template<int LoadMode, typename PacketType>
1579  EIGEN_STRONG_INLINE
1580  void writePacket(Index index, const PacketType& x)
1581  {
1582  enum { PacketSize = unpacket_traits<PacketType>::size };
1583  m_argImpl.template writePacket<LoadMode>
1584  (m_rows.value() * m_cols.value() - index - PacketSize, preverse(x));
1585  }
1586 
1587 protected:
1588  evaluator<ArgType> m_argImpl;
1589 
1590  // If we do not reverse rows, then we do not need to know the number of rows; same for columns
1591  // Nonetheless, in this case it is important to set to 1 such that the coeff(index) method works fine for vectors.
1594 };
1595 
1596 
1597 // -------------------- Diagonal --------------------
1598 
1599 template<typename ArgType, int DiagIndex>
1600 struct evaluator<Diagonal<ArgType, DiagIndex> >
1601  : evaluator_base<Diagonal<ArgType, DiagIndex> >
1602 {
1604 
1605  enum {
1606  CoeffReadCost = evaluator<ArgType>::CoeffReadCost,
1607 
1608  Flags = (unsigned int)(evaluator<ArgType>::Flags & (HereditaryBits | DirectAccessBit) & ~RowMajorBit) | LinearAccessBit,
1609 
1610  Alignment = 0
1611  };
1612 
1613  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1614  explicit evaluator(const XprType& diagonal)
1615  : m_argImpl(diagonal.nestedExpression()),
1616  m_index(diagonal.index())
1617  { }
1618 
1619  typedef typename XprType::Scalar Scalar;
1620  typedef typename XprType::CoeffReturnType CoeffReturnType;
1621 
1622  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1623  CoeffReturnType coeff(Index row, Index) const
1624  {
1625  return m_argImpl.coeff(row + rowOffset(), row + colOffset());
1626  }
1627 
1628  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1629  CoeffReturnType coeff(Index index) const
1630  {
1631  return m_argImpl.coeff(index + rowOffset(), index + colOffset());
1632  }
1633 
1634  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1635  Scalar& coeffRef(Index row, Index)
1636  {
1637  return m_argImpl.coeffRef(row + rowOffset(), row + colOffset());
1638  }
1639 
1640  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1641  Scalar& coeffRef(Index index)
1642  {
1643  return m_argImpl.coeffRef(index + rowOffset(), index + colOffset());
1644  }
1645 
1646 protected:
1647  evaluator<ArgType> m_argImpl;
1649 
1650 private:
1651  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rowOffset() const { return m_index.value() > 0 ? 0 : -m_index.value(); }
1652  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index colOffset() const { return m_index.value() > 0 ? m_index.value() : 0; }
1653 };
1654 
1655 
1656 //----------------------------------------------------------------------
1657 // deprecated code
1658 //----------------------------------------------------------------------
1659 
1660 // -------------------- EvalToTemp --------------------
1661 
1662 // expression class for evaluating nested expression to a temporary
1663 
1664 template<typename ArgType> class EvalToTemp;
1665 
1666 template<typename ArgType>
1667 struct traits<EvalToTemp<ArgType> >
1668  : public traits<ArgType>
1669 { };
1670 
1671 template<typename ArgType>
1673  : public dense_xpr_base<EvalToTemp<ArgType> >::type
1674 {
1675  public:
1676 
1677  typedef typename dense_xpr_base<EvalToTemp>::type Base;
1678  EIGEN_GENERIC_PUBLIC_INTERFACE(EvalToTemp)
1679 
1680  explicit EvalToTemp(const ArgType& arg)
1681  : m_arg(arg)
1682  { }
1683 
1684  const ArgType& arg() const
1685  {
1686  return m_arg;
1687  }
1688 
1689  Index rows() const
1690  {
1691  return m_arg.rows();
1692  }
1693 
1694  Index cols() const
1695  {
1696  return m_arg.cols();
1697  }
1698 
1699  private:
1700  const ArgType& m_arg;
1701 };
1702 
1703 template<typename ArgType>
1704 struct evaluator<EvalToTemp<ArgType> >
1705  : public evaluator<typename ArgType::PlainObject>
1706 {
1707  typedef EvalToTemp<ArgType> XprType;
1708  typedef typename ArgType::PlainObject PlainObject;
1709  typedef evaluator<PlainObject> Base;
1710 
1711  EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr)
1712  : m_result(xpr.arg())
1713  {
1714  ::new (static_cast<Base*>(this)) Base(m_result);
1715  }
1716 
1717  // This constructor is used when nesting an EvalTo evaluator in another evaluator
1718  EIGEN_DEVICE_FUNC evaluator(const ArgType& arg)
1719  : m_result(arg)
1720  {
1721  ::new (static_cast<Base*>(this)) Base(m_result);
1722  }
1723 
1724 protected:
1725  PlainObject m_result;
1726 };
1727 
1728 } // namespace internal
1729 
1730 } // end namespace Eigen
1731 
1732 #endif // EIGEN_COREEVALUATORS_H
Eigen::internal::mapbase_evaluator
Definition: CoreEvaluators.h:882
Eigen::internal::variable_if_dynamic< Index, XprType::InnerStrideAtCompileTime >
Eigen
Namespace containing all symbols from the Eigen library.
Definition: LDLT.h:16
Eigen::SolverShape
Definition: Constants.h:525
Eigen::CwiseUnaryView::functor
const ViewOp & functor() const
Definition: CwiseUnaryView.h:76
Eigen::Block
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:105
Eigen::internal::ternary_evaluator
Definition: CoreEvaluators.h:55
Eigen::CwiseBinaryOp::functor
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const BinaryOp & functor() const
Definition: CwiseBinaryOp.h:144
Eigen::CwiseBinaryOp
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:84
Eigen::DenseShape
Definition: Constants.h:524
Eigen::Horizontal
@ Horizontal
Definition: Constants.h:266
Eigen::internal::evaluator_assume_aliasing
Definition: CoreEvaluators.h:84
Eigen::internal::dense_xpr_base
Definition: XprHelper.h:492
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:65
Eigen::internal::false_type
Definition: Meta.h:64
Eigen::internal::binary_evaluator
Definition: CoreEvaluators.h:61
Eigen::internal::storage_kind_to_shape
Definition: CoreEvaluators.h:29
Eigen::Array
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:47
Eigen::internal::evaluator_traits
Definition: CoreEvaluators.h:80
Eigen::internal::reverse_packet_cond
Definition: Reverse.h:38
Eigen::CwiseTernaryOp::functor
EIGEN_DEVICE_FUNC const TernaryOp & functor() const
Definition: CwiseTernaryOp.h:175
Eigen::ArrayWrapper
Expression of a mathematical vector or matrix as an array object.
Definition: ArrayWrapper.h:43
Eigen::internal::evaluator_base
Definition: CoreEvaluators.h:111
Eigen::CwiseUnaryView
Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector.
Definition: CwiseUnaryView.h:59
Eigen::internal::block_evaluator
Definition: CoreEvaluators.h:1024
Eigen::Transpose
Expression of the transpose of a matrix.
Definition: Transpose.h:54
Eigen::DirectAccessBit
const unsigned int DirectAccessBit
Definition: Constants.h:154
Eigen::CwiseNullaryOp
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:61
Eigen::PacketAccessBit
const unsigned int PacketAccessBit
Definition: Constants.h:93
Eigen::internal::has_binary_operator
Definition: Meta.h:570
Eigen::CwiseBinaryOp::lhs
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const _LhsNested & lhs() const
Definition: CwiseBinaryOp.h:138
Eigen::CwiseNullaryOp::functor
EIGEN_DEVICE_FUNC const NullaryOp & functor() const
Definition: CwiseNullaryOp.h:84
Eigen::internal::evaluator_wrapper_base
Definition: CoreEvaluators.h:1374
Eigen::internal::true_type
Definition: Meta.h:63
Eigen::SolverStorage
Definition: Constants.h:509
Eigen::CwiseUnaryOp::nestedExpression
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const internal::remove_all< XprTypeNested >::type & nestedExpression() const
Definition: CwiseUnaryOp.h:80
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:21
Eigen::internal::unpacket_traits
Definition: XprHelper.h:184
Eigen::Diagonal
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:65
Eigen::Reverse
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:65
Eigen::Replicate
Expression of the multiple replication of a matrix or vector.
Definition: Replicate.h:63
Eigen::internal::outer_stride_at_compile_time
Definition: DenseCoeffsBase.h:671
Eigen::OuterStride
Convenience specialization of Stride to specify only an outer stride See class Map for some examples.
Definition: Stride.h:102
Eigen::PlainObjectBase
Definition: PlainObjectBase.h:100
Eigen::internal::evaluator_traits_base
Definition: CoreEvaluators.h:71
Eigen::CwiseTernaryOp::arg3
EIGEN_DEVICE_FUNC const _Arg3Nested & arg3() const
Definition: CwiseTernaryOp.h:172
Eigen::internal::functor_has_linear_access
Definition: NullaryFunctors.h:151
Eigen::internal::evaluator
Definition: CoreEvaluators.h:91
Eigen::internal::variable_if_dynamicindex< Index, XprType::DiagIndex >
Eigen::internal::storage_kind_to_evaluator_kind
Definition: CoreEvaluators.h:23
Eigen::Vertical
@ Vertical
Definition: Constants.h:263
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
Eigen::internal::nullary_wrapper
Definition: CoreEvaluators.h:387
Eigen::CwiseTernaryOp
Generic expression where a coefficient-wise ternary operator is applied to two expressions.
Definition: CwiseTernaryOp.h:88
Eigen::internal::inner_stride_at_compile_time
Definition: DenseCoeffsBase.h:659
Eigen::LinearAccessBit
const unsigned int LinearAccessBit
Definition: Constants.h:129
Eigen::CwiseTernaryOp::arg1
EIGEN_DEVICE_FUNC const _Arg1Nested & arg1() const
Definition: CwiseTernaryOp.h:166
Eigen::Ref
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:197
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::PermutationStorage
Definition: Constants.h:512
Eigen::CwiseUnaryOp
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:56
Eigen::internal::unary_evaluator
Definition: CoreEvaluators.h:65
Eigen::CwiseBinaryOp::rhs
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const _RhsNested & rhs() const
Definition: CwiseBinaryOp.h:141
Eigen::internal::has_unary_operator
Definition: Meta.h:561
Eigen::internal::EvalToTemp
Definition: CoreEvaluators.h:1674
Eigen::CwiseTernaryOp::arg2
EIGEN_DEVICE_FUNC const _Arg2Nested & arg2() const
Definition: CwiseTernaryOp.h:169
Eigen::TranspositionsStorage
Definition: Constants.h:515
Eigen::BothDirections
@ BothDirections
Definition: Constants.h:269
Eigen::internal::is_same
Definition: Meta.h:115
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:180
Eigen::internal::functor_traits
Definition: XprHelper.h:172
Eigen::MatrixWrapper
Expression of an array as a mathematical vector or matrix.
Definition: ArrayWrapper.h:141
Eigen::EvalBeforeNestingBit
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:69
Eigen::internal::IndexBased
Definition: Constants.h:538
Eigen::CwiseUnaryOp::functor
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const UnaryOp & functor() const
Definition: CwiseUnaryOp.h:75
Eigen::Select
Expression of a coefficient wise version of the C++ ternary operator ?:
Definition: Select.h:54
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:213
Eigen::internal::has_nullary_operator
Definition: Meta.h:552
Eigen::CwiseUnaryView::nestedExpression
const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: CwiseUnaryView.h:80
Eigen::internal::has_direct_access
Definition: ForwardDeclarations.h:26
Eigen::internal::bool_constant
Definition: Meta.h:67
Eigen::Transpose::nestedExpression
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: Transpose.h:76
Eigen::TranspositionsShape
Definition: Constants.h:532
Eigen::PlainObjectBase::data
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Definition: PlainObjectBase.h:255
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:42
Eigen::Dense
Definition: Constants.h:503
Eigen::internal::plainobjectbase_evaluator_data
Definition: CoreEvaluators.h:136
Eigen::PermutationShape
Definition: Constants.h:531