Functors.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_FUNCTORS_H
11 #define EIGEN_FUNCTORS_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 // associative functors:
18 
24 template<typename Scalar> struct scalar_sum_op {
26  EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const { return a + b; }
27  template<typename Packet>
28  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
29  { return internal::padd(a,b); }
30  template<typename Packet>
31  EIGEN_STRONG_INLINE const Scalar predux(const Packet& a) const
32  { return internal::predux(a); }
33 };
34 template<typename Scalar>
35 struct functor_traits<scalar_sum_op<Scalar> > {
36  enum {
39  };
40 };
41 
47 template<typename LhsScalar,typename RhsScalar> struct scalar_product_op {
48  enum {
49  // TODO vectorize mixed product
51  };
54  EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a * b; }
55  template<typename Packet>
56  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
57  { return internal::pmul(a,b); }
58  template<typename Packet>
59  EIGEN_STRONG_INLINE const result_type predux(const Packet& a) const
60  { return internal::predux_mul(a); }
61 };
62 template<typename LhsScalar,typename RhsScalar>
63 struct functor_traits<scalar_product_op<LhsScalar,RhsScalar> > {
64  enum {
67  };
68 };
69 
75 template<typename LhsScalar,typename RhsScalar> struct scalar_conj_product_op {
76 
77  enum {
79  };
80 
82 
84  EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const
86 
87  template<typename Packet>
88  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
90 };
91 template<typename LhsScalar,typename RhsScalar>
92 struct functor_traits<scalar_conj_product_op<LhsScalar,RhsScalar> > {
93  enum {
96  };
97 };
98 
104 template<typename Scalar> struct scalar_min_op {
106  EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const { using std::min; return (min)(a, b); }
107  template<typename Packet>
108  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
109  { return internal::pmin(a,b); }
110  template<typename Packet>
111  EIGEN_STRONG_INLINE const Scalar predux(const Packet& a) const
112  { return internal::predux_min(a); }
113 };
114 template<typename Scalar>
115 struct functor_traits<scalar_min_op<Scalar> > {
116  enum {
119  };
120 };
121 
127 template<typename Scalar> struct scalar_max_op {
129  EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const { using std::max; return (max)(a, b); }
130  template<typename Packet>
131  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
132  { return internal::pmax(a,b); }
133  template<typename Packet>
134  EIGEN_STRONG_INLINE const Scalar predux(const Packet& a) const
135  { return internal::predux_max(a); }
136 };
137 template<typename Scalar>
138 struct functor_traits<scalar_max_op<Scalar> > {
139  enum {
142  };
143 };
144 
150 template<typename Scalar> struct scalar_hypot_op {
152 // typedef typename NumTraits<Scalar>::Real result_type;
153  EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& _x, const Scalar& _y) const
154  {
155  using std::max;
156  using std::min;
157  using std::sqrt;
158  Scalar p = (max)(_x, _y);
159  Scalar q = (min)(_x, _y);
160  Scalar qp = q/p;
161  return p * sqrt(Scalar(1) + qp*qp);
162  }
163 };
164 template<typename Scalar>
165 struct functor_traits<scalar_hypot_op<Scalar> > {
166  enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess=0 };
167 };
168 
172 template<typename Scalar, typename OtherScalar> struct scalar_binary_pow_op {
174  inline Scalar operator() (const Scalar& a, const OtherScalar& b) const { return numext::pow(a, b); }
175 };
176 template<typename Scalar, typename OtherScalar>
177 struct functor_traits<scalar_binary_pow_op<Scalar,OtherScalar> > {
178  enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
179 };
180 
181 // other binary functors:
182 
188 template<typename Scalar> struct scalar_difference_op {
190  EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const { return a - b; }
191  template<typename Packet>
192  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
193  { return internal::psub(a,b); }
194 };
195 template<typename Scalar>
197  enum {
200  };
201 };
202 
208 template<typename LhsScalar,typename RhsScalar> struct scalar_quotient_op {
209  enum {
210  // TODO vectorize mixed product
212  };
215  EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a / b; }
216  template<typename Packet>
217  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
218  { return internal::pdiv(a,b); }
219 };
220 template<typename LhsScalar,typename RhsScalar>
221 struct functor_traits<scalar_quotient_op<LhsScalar,RhsScalar> > {
222  enum {
225  };
226 };
227 
228 
229 
237  EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a && b; }
238 };
240  enum {
242  PacketAccess = false
243  };
244 };
245 
253  EIGEN_STRONG_INLINE bool operator() (const bool& a, const bool& b) const { return a || b; }
254 };
256  enum {
258  PacketAccess = false
259  };
260 };
261 
262 // unary functors:
263 
269 template<typename Scalar> struct scalar_opposite_op {
271  EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return -a; }
272  template<typename Packet>
273  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
274  { return internal::pnegate(a); }
275 };
276 template<typename Scalar>
278 { enum {
281 };
282 
288 template<typename Scalar> struct scalar_abs_op {
290  typedef typename NumTraits<Scalar>::Real result_type;
291  EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { using std::abs; return abs(a); }
292  template<typename Packet>
293  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
294  { return internal::pabs(a); }
295 };
296 template<typename Scalar>
298 {
299  enum {
302  };
303 };
304 
310 template<typename Scalar> struct scalar_abs2_op {
312  typedef typename NumTraits<Scalar>::Real result_type;
313  EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return numext::abs2(a); }
314  template<typename Packet>
315  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
316  { return internal::pmul(a,a); }
317 };
318 template<typename Scalar>
320 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasAbs2 }; };
321 
327 template<typename Scalar> struct scalar_conjugate_op {
329  EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { using numext::conj; return conj(a); }
330  template<typename Packet>
331  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const { return internal::pconj(a); }
332 };
333 template<typename Scalar>
335 {
336  enum {
339  };
340 };
341 
347 template<typename Scalar, typename NewType>
350  typedef NewType result_type;
351  EIGEN_STRONG_INLINE const NewType operator() (const Scalar& a) const { return cast<Scalar, NewType>(a); }
352 };
353 template<typename Scalar, typename NewType>
354 struct functor_traits<scalar_cast_op<Scalar,NewType> >
355 { enum { Cost = is_same<Scalar, NewType>::value ? 0 : NumTraits<NewType>::AddCost, PacketAccess = false }; };
356 
362 template<typename Scalar>
365  typedef typename NumTraits<Scalar>::Real result_type;
366  EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::real(a); }
367 };
368 template<typename Scalar>
370 { enum { Cost = 0, PacketAccess = false }; };
371 
377 template<typename Scalar>
380  typedef typename NumTraits<Scalar>::Real result_type;
381  EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::imag(a); }
382 };
383 template<typename Scalar>
385 { enum { Cost = 0, PacketAccess = false }; };
386 
392 template<typename Scalar>
395  typedef typename NumTraits<Scalar>::Real result_type;
396  EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return numext::real_ref(*const_cast<Scalar*>(&a)); }
397 };
398 template<typename Scalar>
400 { enum { Cost = 0, PacketAccess = false }; };
401 
407 template<typename Scalar>
410  typedef typename NumTraits<Scalar>::Real result_type;
411  EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return numext::imag_ref(*const_cast<Scalar*>(&a)); }
412 };
413 template<typename Scalar>
415 { enum { Cost = 0, PacketAccess = false }; };
416 
423 template<typename Scalar> struct scalar_exp_op {
425  inline const Scalar operator() (const Scalar& a) const { using std::exp; return exp(a); }
427  inline Packet packetOp(const Packet& a) const { return internal::pexp(a); }
428 };
429 template<typename Scalar>
431 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasExp }; };
432 
439 template<typename Scalar> struct scalar_log_op {
441  inline const Scalar operator() (const Scalar& a) const { using std::log; return log(a); }
443  inline Packet packetOp(const Packet& a) const { return internal::plog(a); }
444 };
445 template<typename Scalar>
447 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasLog }; };
448 
454 /* NOTE why doing the pset1() in packetOp *is* an optimization ?
455  * indeed it seems better to declare m_other as a Packet and do the pset1() once
456  * in the constructor. However, in practice:
457  * - GCC does not like m_other as a Packet and generate a load every time it needs it
458  * - on the other hand GCC is able to moves the pset1() outside the loop :)
459  * - simpler code ;)
460  * (ICC and gcc 4.4 seems to perform well in both cases, the issue is visible with y = a*x + b*y)
461  */
462 template<typename Scalar>
465  // FIXME default copy constructors seems bugged with std::complex<>
466  EIGEN_STRONG_INLINE scalar_multiple_op(const scalar_multiple_op& other) : m_other(other.m_other) { }
467  EIGEN_STRONG_INLINE scalar_multiple_op(const Scalar& other) : m_other(other) { }
468  EIGEN_STRONG_INLINE Scalar operator() (const Scalar& a) const { return a * m_other; }
469  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
470  { return internal::pmul(a, pset1<Packet>(m_other)); }
472 };
473 template<typename Scalar>
475 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
476 
477 template<typename Scalar1, typename Scalar2>
480  EIGEN_STRONG_INLINE scalar_multiple2_op(const scalar_multiple2_op& other) : m_other(other.m_other) { }
481  EIGEN_STRONG_INLINE scalar_multiple2_op(const Scalar2& other) : m_other(other) { }
482  EIGEN_STRONG_INLINE result_type operator() (const Scalar1& a) const { return a * m_other; }
484 };
485 template<typename Scalar1,typename Scalar2>
486 struct functor_traits<scalar_multiple2_op<Scalar1,Scalar2> >
487 { enum { Cost = NumTraits<Scalar1>::MulCost, PacketAccess = false }; };
488 
497 template<typename Scalar>
500  // FIXME default copy constructors seems bugged with std::complex<>
501  EIGEN_STRONG_INLINE scalar_quotient1_op(const scalar_quotient1_op& other) : m_other(other.m_other) { }
502  EIGEN_STRONG_INLINE scalar_quotient1_op(const Scalar& other) : m_other(other) {}
503  EIGEN_STRONG_INLINE Scalar operator() (const Scalar& a) const { return a / m_other; }
504  EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
505  { return internal::pdiv(a, pset1<Packet>(m_other)); }
507 };
508 template<typename Scalar>
510 { enum { Cost = 2 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasDiv }; };
511 
512 // nullary functors
513 
514 template<typename Scalar>
517  EIGEN_STRONG_INLINE scalar_constant_op(const scalar_constant_op& other) : m_other(other.m_other) { }
518  EIGEN_STRONG_INLINE scalar_constant_op(const Scalar& other) : m_other(other) { }
519  template<typename Index>
520  EIGEN_STRONG_INLINE const Scalar operator() (Index, Index = 0) const { return m_other; }
521  template<typename Index>
522  EIGEN_STRONG_INLINE const Packet packetOp(Index, Index = 0) const { return internal::pset1<Packet>(m_other); }
523  const Scalar m_other;
524 };
525 template<typename Scalar>
527 // FIXME replace this packet test by a safe one
528 { enum { Cost = 1, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = true }; };
529 
530 template<typename Scalar> struct scalar_identity_op {
532  template<typename Index>
533  EIGEN_STRONG_INLINE const Scalar operator() (Index row, Index col) const { return row==col ? Scalar(1) : Scalar(0); }
534 };
535 template<typename Scalar>
537 { enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = false, IsRepeatable = true }; };
538 
539 template <typename Scalar, bool RandomAccess> struct linspaced_op_impl;
540 
541 // linear access for packet ops:
542 // 1) initialization
543 // base = [low, ..., low] + ([step, ..., step] * [-size, ..., 0])
544 // 2) each step (where size is 1 for coeff access or PacketSize for packet access)
545 // base += [size*step, ..., size*step]
546 //
547 // TODO: Perhaps it's better to initialize lazily (so not in the constructor but in packetOp)
548 // in order to avoid the padd() in operator() ?
549 template <typename Scalar>
550 struct linspaced_op_impl<Scalar,false>
551 {
553 
554  linspaced_op_impl(const Scalar& low, const Scalar& step) :
555  m_low(low), m_step(step),
556  m_packetStep(pset1<Packet>(packet_traits<Scalar>::size*step)),
557  m_base(padd(pset1<Packet>(low), pmul(pset1<Packet>(step),plset<Scalar>(-packet_traits<Scalar>::size)))) {}
558 
559  template<typename Index>
560  EIGEN_STRONG_INLINE const Scalar operator() (Index i) const
561  {
562  m_base = padd(m_base, pset1<Packet>(m_step));
563  return m_low+Scalar(i)*m_step;
564  }
565 
566  template<typename Index>
567  EIGEN_STRONG_INLINE const Packet packetOp(Index) const { return m_base = padd(m_base,m_packetStep); }
568 
569  const Scalar m_low;
570  const Scalar m_step;
571  const Packet m_packetStep;
572  mutable Packet m_base;
573 };
574 
575 // random access for packet ops:
576 // 1) each step
577 // [low, ..., low] + ( [step, ..., step] * ( [i, ..., i] + [0, ..., size] ) )
578 template <typename Scalar>
579 struct linspaced_op_impl<Scalar,true>
580 {
582 
583  linspaced_op_impl(const Scalar& low, const Scalar& step) :
584  m_low(low), m_step(step),
585  m_lowPacket(pset1<Packet>(m_low)), m_stepPacket(pset1<Packet>(m_step)), m_interPacket(plset<Scalar>(0)) {}
586 
587  template<typename Index>
588  EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return m_low+i*m_step; }
589 
590  template<typename Index>
591  EIGEN_STRONG_INLINE const Packet packetOp(Index i) const
592  { return internal::padd(m_lowPacket, pmul(m_stepPacket, padd(pset1<Packet>(i),m_interPacket))); }
593 
594  const Scalar m_low;
595  const Scalar m_step;
596  const Packet m_lowPacket;
597  const Packet m_stepPacket;
598  const Packet m_interPacket;
599 };
600 
601 // ----- Linspace functor ----------------------------------------------------------------
602 
603 // Forward declaration (we default to random access which does not really give
604 // us a speed gain when using packet access but it allows to use the functor in
605 // nested expressions).
606 template <typename Scalar, bool RandomAccess = true> struct linspaced_op;
607 template <typename Scalar, bool RandomAccess> struct functor_traits< linspaced_op<Scalar,RandomAccess> >
608 { enum { Cost = 1, PacketAccess = packet_traits<Scalar>::HasSetLinear, IsRepeatable = true }; };
609 template <typename Scalar, bool RandomAccess> struct linspaced_op
610 {
612  linspaced_op(const Scalar& low, const Scalar& high, DenseIndex num_steps) : impl((num_steps==1 ? high : low), (num_steps==1 ? Scalar() : (high-low)/(num_steps-1))) {}
613 
614  template<typename Index>
615  EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return impl(i); }
616 
617  // We need this function when assigning e.g. a RowVectorXd to a MatrixXd since
618  // there row==0 and col is used for the actual iteration.
619  template<typename Index>
620  EIGEN_STRONG_INLINE const Scalar operator() (Index row, Index col) const
621  {
622  eigen_assert(col==0 || row==0);
623  return impl(col + row);
624  }
625 
626  template<typename Index>
627  EIGEN_STRONG_INLINE const Packet packetOp(Index i) const { return impl.packetOp(i); }
628 
629  // We need this function when assigning e.g. a RowVectorXd to a MatrixXd since
630  // there row==0 and col is used for the actual iteration.
631  template<typename Index>
632  EIGEN_STRONG_INLINE const Packet packetOp(Index row, Index col) const
633  {
634  eigen_assert(col==0 || row==0);
635  return impl.packetOp(col + row);
636  }
637 
638  // This proxy object handles the actual required temporaries, the different
639  // implementations (random vs. sequential access) as well as the
640  // correct piping to size 2/4 packet operations.
642 };
643 
644 // all functors allow linear access, except scalar_identity_op. So we fix here a quick meta
645 // to indicate whether a functor allows linear access, just always answering 'yes' except for
646 // scalar_identity_op.
647 // FIXME move this to functor_traits adding a functor_default
648 template<typename Functor> struct functor_has_linear_access { enum { ret = 1 }; };
649 template<typename Scalar> struct functor_has_linear_access<scalar_identity_op<Scalar> > { enum { ret = 0 }; };
650 
651 // In Eigen, any binary op (Product, CwiseBinaryOp) require the Lhs and Rhs to have the same scalar type, except for multiplication
652 // where the mixing of different types is handled by scalar_product_traits
653 // In particular, real * complex<real> is allowed.
654 // FIXME move this to functor_traits adding a functor_default
655 template<typename Functor> struct functor_is_product_like { enum { ret = 0 }; };
656 template<typename LhsScalar,typename RhsScalar> struct functor_is_product_like<scalar_product_op<LhsScalar,RhsScalar> > { enum { ret = 1 }; };
657 template<typename LhsScalar,typename RhsScalar> struct functor_is_product_like<scalar_conj_product_op<LhsScalar,RhsScalar> > { enum { ret = 1 }; };
658 template<typename LhsScalar,typename RhsScalar> struct functor_is_product_like<scalar_quotient_op<LhsScalar,RhsScalar> > { enum { ret = 1 }; };
659 
660 
665 /* If you wonder why doing the pset1() in packetOp() is an optimization check scalar_multiple_op */
666 template<typename Scalar>
669  // FIXME default copy constructors seems bugged with std::complex<>
670  inline scalar_add_op(const scalar_add_op& other) : m_other(other.m_other) { }
671  inline scalar_add_op(const Scalar& other) : m_other(other) { }
672  inline Scalar operator() (const Scalar& a) const { return a + m_other; }
673  inline const Packet packetOp(const Packet& a) const
674  { return internal::padd(a, pset1<Packet>(m_other)); }
675  const Scalar m_other;
676 };
677 template<typename Scalar>
679 { enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = packet_traits<Scalar>::HasAdd }; };
680 
685 template<typename Scalar> struct scalar_sqrt_op {
687  inline const Scalar operator() (const Scalar& a) const { using std::sqrt; return sqrt(a); }
689  inline Packet packetOp(const Packet& a) const { return internal::psqrt(a); }
690 };
691 template<typename Scalar>
693 { enum {
696  };
697 };
698 
703 template<typename Scalar> struct scalar_cos_op {
705  inline Scalar operator() (const Scalar& a) const { using std::cos; return cos(a); }
707  inline Packet packetOp(const Packet& a) const { return internal::pcos(a); }
708 };
709 template<typename Scalar>
711 {
712  enum {
715  };
716 };
717 
722 template<typename Scalar> struct scalar_sin_op {
724  inline const Scalar operator() (const Scalar& a) const { using std::sin; return sin(a); }
726  inline Packet packetOp(const Packet& a) const { return internal::psin(a); }
727 };
728 template<typename Scalar>
730 {
731  enum {
734  };
735 };
736 
737 
742 template<typename Scalar> struct scalar_tan_op {
744  inline const Scalar operator() (const Scalar& a) const { using std::tan; return tan(a); }
746  inline Packet packetOp(const Packet& a) const { return internal::ptan(a); }
747 };
748 template<typename Scalar>
750 {
751  enum {
754  };
755 };
756 
761 template<typename Scalar> struct scalar_acos_op {
763  inline const Scalar operator() (const Scalar& a) const { using std::acos; return acos(a); }
765  inline Packet packetOp(const Packet& a) const { return internal::pacos(a); }
766 };
767 template<typename Scalar>
769 {
770  enum {
773  };
774 };
775 
780 template<typename Scalar> struct scalar_asin_op {
782  inline const Scalar operator() (const Scalar& a) const { using std::asin; return asin(a); }
784  inline Packet packetOp(const Packet& a) const { return internal::pasin(a); }
785 };
786 template<typename Scalar>
788 {
789  enum {
792  };
793 };
794 
799 template<typename Scalar>
801  // FIXME default copy constructors seems bugged with std::complex<>
802  inline scalar_pow_op(const scalar_pow_op& other) : m_exponent(other.m_exponent) { }
803  inline scalar_pow_op(const Scalar& exponent) : m_exponent(exponent) {}
804  inline Scalar operator() (const Scalar& a) const { return numext::pow(a, m_exponent); }
805  const Scalar m_exponent;
806 };
807 template<typename Scalar>
809 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };
810 
815 template<typename Scalar>
817  scalar_inverse_mult_op(const Scalar& other) : m_other(other) {}
818  inline Scalar operator() (const Scalar& a) const { return m_other / a; }
819  template<typename Packet>
820  inline const Packet packetOp(const Packet& a) const
821  { return internal::pdiv(pset1<Packet>(m_other),a); }
822  Scalar m_other;
823 };
824 
829 template<typename Scalar>
832  inline Scalar operator() (const Scalar& a) const { return Scalar(1)/a; }
833  template<typename Packet>
834  inline const Packet packetOp(const Packet& a) const
835  { return internal::pdiv(pset1<Packet>(Scalar(1)),a); }
836 };
837 template<typename Scalar>
839 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasDiv }; };
840 
845 template<typename Scalar>
848  inline Scalar operator() (const Scalar& a) const { return a*a; }
849  template<typename Packet>
850  inline const Packet packetOp(const Packet& a) const
851  { return internal::pmul(a,a); }
852 };
853 template<typename Scalar>
855 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
856 
861 template<typename Scalar>
864  inline Scalar operator() (const Scalar& a) const { return a*a*a; }
865  template<typename Packet>
866  inline const Packet packetOp(const Packet& a) const
867  { return internal::pmul(a,pmul(a,a)); }
868 };
869 template<typename Scalar>
871 { enum { Cost = 2*NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
872 
873 // default functor traits for STL functors:
874 
875 template<typename T>
876 struct functor_traits<std::multiplies<T> >
877 { enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
878 
879 template<typename T>
880 struct functor_traits<std::divides<T> >
881 { enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
882 
883 template<typename T>
884 struct functor_traits<std::plus<T> >
885 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
886 
887 template<typename T>
888 struct functor_traits<std::minus<T> >
889 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
890 
891 template<typename T>
892 struct functor_traits<std::negate<T> >
893 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
894 
895 template<typename T>
896 struct functor_traits<std::logical_or<T> >
897 { enum { Cost = 1, PacketAccess = false }; };
898 
899 template<typename T>
900 struct functor_traits<std::logical_and<T> >
901 { enum { Cost = 1, PacketAccess = false }; };
902 
903 template<typename T>
904 struct functor_traits<std::logical_not<T> >
905 { enum { Cost = 1, PacketAccess = false }; };
906 
907 template<typename T>
908 struct functor_traits<std::greater<T> >
909 { enum { Cost = 1, PacketAccess = false }; };
910 
911 template<typename T>
912 struct functor_traits<std::less<T> >
913 { enum { Cost = 1, PacketAccess = false }; };
914 
915 template<typename T>
916 struct functor_traits<std::greater_equal<T> >
917 { enum { Cost = 1, PacketAccess = false }; };
918 
919 template<typename T>
920 struct functor_traits<std::less_equal<T> >
921 { enum { Cost = 1, PacketAccess = false }; };
922 
923 template<typename T>
924 struct functor_traits<std::equal_to<T> >
925 { enum { Cost = 1, PacketAccess = false }; };
926 
927 template<typename T>
928 struct functor_traits<std::not_equal_to<T> >
929 { enum { Cost = 1, PacketAccess = false }; };
930 
931 template<typename T>
932 struct functor_traits<std::binder2nd<T> >
933 { enum { Cost = functor_traits<T>::Cost, PacketAccess = false }; };
934 
935 template<typename T>
936 struct functor_traits<std::binder1st<T> >
937 { enum { Cost = functor_traits<T>::Cost, PacketAccess = false }; };
938 
939 template<typename T>
940 struct functor_traits<std::unary_negate<T> >
941 { enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; };
942 
943 template<typename T>
944 struct functor_traits<std::binary_negate<T> >
945 { enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; };
946 
947 #ifdef EIGEN_STDEXT_SUPPORT
948 
949 template<typename T0,typename T1>
950 struct functor_traits<std::project1st<T0,T1> >
951 { enum { Cost = 0, PacketAccess = false }; };
952 
953 template<typename T0,typename T1>
954 struct functor_traits<std::project2nd<T0,T1> >
955 { enum { Cost = 0, PacketAccess = false }; };
956 
957 template<typename T0,typename T1>
958 struct functor_traits<std::select2nd<std::pair<T0,T1> > >
959 { enum { Cost = 0, PacketAccess = false }; };
960 
961 template<typename T0,typename T1>
962 struct functor_traits<std::select1st<std::pair<T0,T1> > >
963 { enum { Cost = 0, PacketAccess = false }; };
964 
965 template<typename T0,typename T1>
966 struct functor_traits<std::unary_compose<T0,T1> >
967 { enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost, PacketAccess = false }; };
968 
969 template<typename T0,typename T1,typename T2>
970 struct functor_traits<std::binary_compose<T0,T1,T2> >
971 { enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost + functor_traits<T2>::Cost, PacketAccess = false }; };
972 
973 #endif // EIGEN_STDEXT_SUPPORT
974 
975 // allow to add new functors and specializations of functor_traits from outside Eigen.
976 // this macro is really needed because functor_traits must be specialized after it is declared but before it is used...
977 #ifdef EIGEN_FUNCTORS_PLUGIN
978 #include EIGEN_FUNCTORS_PLUGIN
979 #endif
980 
981 } // end namespace internal
982 
983 } // end namespace Eigen
984 
985 #endif // EIGEN_FUNCTORS_H
Packet packetOp(const Packet &a) const
Definition: Functors.h:427
const Packet packetOp(const Packet &a) const
Definition: Functors.h:673
EIGEN_STRONG_INLINE scalar_quotient1_op(const scalar_quotient1_op &other)
Definition: Functors.h:501
packet_traits< Scalar >::type Packet
Definition: Functors.h:611
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition: Functors.h:108
internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type imag_ref(const Scalar &x)
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
unpacket_traits< Packet >::type predux_min(const Packet &a)
#define EIGEN_EMPTY_STRUCT_CTOR(X)
Definition: XprHelper.h:22
linspaced_op(const Scalar &low, const Scalar &high, DenseIndex num_steps)
Definition: Functors.h:612
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
Definition: Functors.h:504
IntermediateState sqrt(const Expression &arg)
unpacket_traits< Packet >::type predux_mul(const Packet &a)
#define EIGEN_STRONG_INLINE
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pasin(const Packet &a)
Packet packetOp(const Packet &a) const
Definition: Functors.h:443
packet_traits< Scalar >::type Packet
Definition: Functors.h:499
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition: Functors.h:192
#define inline
Definition: Types.h:109
EIGEN_STRONG_INLINE const Scalar predux(const Packet &a) const
Definition: Functors.h:31
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
Definition: Functors.h:273
linspaced_op_impl(const Scalar &low, const Scalar &step)
Definition: Functors.h:554
scalar_pow_op(const scalar_pow_op &other)
Definition: Functors.h:802
NumTraits< Scalar >::Real result_type
Definition: Functors.h:290
const linspaced_op_impl< Scalar, RandomAccess > impl
Definition: Functors.h:641
NumTraits< Scalar >::Real result_type
Definition: Functors.h:410
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: matrix.hpp:471
IntermediateState asin(const Expression &arg)
IntermediateState pow(const Expression &arg1, const Expression &arg2)
NumTraits< Scalar >::Real result_type
Definition: Functors.h:365
Packet packetOp(const Packet &a) const
Definition: Functors.h:689
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psqrt(const Packet &a)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
IntermediateState tan(const Expression &arg)
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition: Functors.h:56
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
Definition: Functors.h:331
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs2_op< Scalar >, const Derived > abs2() const
const ImagReturnType imag() const
packet_traits< Scalar >::type Packet
Definition: Functors.h:764
EIGEN_STRONG_INLINE scalar_quotient1_op(const Scalar &other)
Definition: Functors.h:502
Packet packetOp(const Packet &a) const
Definition: Functors.h:746
linspaced_op_impl(const Scalar &low, const Scalar &step)
Definition: Functors.h:583
scalar_product_traits< LhsScalar, RhsScalar >::ReturnType result_type
Definition: Functors.h:52
const Packet packetOp(const Packet &a) const
Definition: Functors.h:834
Packet pmax(const Packet &a, const Packet &b)
IntermediateState cos(const Expression &arg)
const Packet packetOp(const Packet &a) const
Definition: Functors.h:850
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp(const Packet &a)
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > abs() const
RealReturnType real() const
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptan(const Packet &a)
const Packet packetOp(const Packet &a) const
Definition: Functors.h:866
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition: Functors.h:217
EIGEN_STRONG_INLINE const result_type predux(const Packet &a) const
Definition: Functors.h:59
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pacos(const Packet &a)
Packet psub(const Packet &a, const Packet &b)
IntermediateState acos(const Expression &arg)
Packet pmin(const Packet &a, const Packet &b)
Packet packetOp(const Packet &a) const
Definition: Functors.h:784
unpacket_traits< Packet >::type predux(const Packet &a)
add_const_on_value_type< typename NumTraits< Scalar >::Nested >::type m_other
Definition: Functors.h:506
const Packet packetOp(const Packet &a) const
Definition: Functors.h:820
packet_traits< Scalar >::type Packet
Definition: Functors.h:442
scalar_product_traits< LhsScalar, RhsScalar >::ReturnType result_type
Definition: Functors.h:213
packet_traits< Scalar >::type Packet
Definition: Functors.h:783
EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf &a)
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
Definition: Functors.h:293
EIGEN_STRONG_INLINE const Scalar predux(const Packet &a) const
Definition: Functors.h:111
EIGEN_STRONG_INLINE const Packet packetOp(Index, Index=0) const
Definition: Functors.h:522
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
Definition: Functors.h:315
packet_traits< Scalar >::type Packet
Definition: Functors.h:688
EIGEN_STRONG_INLINE scalar_multiple_op(const Scalar &other)
Definition: Functors.h:467
EIGEN_DEFAULT_DENSE_INDEX_TYPE DenseIndex
Definition: XprHelper.h:27
Packet pdiv(const Packet &a, const Packet &b)
unpacket_traits< Packet >::type predux_max(const Packet &a)
add_const_on_value_type< typename NumTraits< Scalar2 >::Nested >::type m_other
Definition: Functors.h:483
scalar_add_op(const Scalar &other)
Definition: Functors.h:671
EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf &a)
EIGEN_STRONG_INLINE const Packet packetOp(Index i) const
Definition: Functors.h:627
EIGEN_STRONG_INLINE scalar_constant_op(const Scalar &other)
Definition: Functors.h:518
EIGEN_STRONG_INLINE const Packet packetOp(Index row, Index col) const
Definition: Functors.h:632
scalar_pow_op(const Scalar &exponent)
Definition: Functors.h:803
packet_traits< Scalar >::type Packet
Definition: Functors.h:725
RowXpr row(Index i)
Definition: BlockMethods.h:725
packet_traits< Scalar >::type Packet
Definition: Functors.h:516
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition: Functors.h:88
EIGEN_STRONG_INLINE scalar_multiple_op(const scalar_multiple_op &other)
Definition: Functors.h:466
scalar_product_traits< LhsScalar, RhsScalar >::ReturnType result_type
Definition: Functors.h:81
EIGEN_STRONG_INLINE scalar_multiple2_op(const Scalar2 &other)
Definition: Functors.h:481
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog(const Packet &a)
packet_traits< Scalar >::type Packet
Definition: Functors.h:581
Packet pset1(const typename unpacket_traits< Packet >::type &a)
Packet pmul(const Packet &a, const Packet &b)
packet_traits< Scalar >::type Packet
Definition: Functors.h:745
packet_traits< Scalar >::type Packet
Definition: Functors.h:668
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition: Functors.h:131
NumTraits< Scalar >::Real result_type
Definition: Functors.h:380
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcos(const Packet &a)
IntermediateState exp(const Expression &arg)
internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type real_ref(const Scalar &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin(const Packet &a)
add_const_on_value_type< typename NumTraits< Scalar >::Nested >::type m_other
Definition: Functors.h:471
Packet packetOp(const Packet &a) const
Definition: Functors.h:726
ColXpr col(Index i)
Definition: BlockMethods.h:708
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
Definition: Functors.h:469
EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a, const Packet &b) const
Definition: Functors.h:28
scalar_inverse_mult_op(const Scalar &other)
Definition: Functors.h:817
EIGEN_STRONG_INLINE const Packet packetOp(Index i) const
Definition: Functors.h:591
Packet packetOp(const Packet &a) const
Definition: Functors.h:765
#define eigen_assert(x)
EIGEN_STRONG_INLINE const Scalar operator()(const Scalar &a, const Scalar &b) const
Definition: Functors.h:26
NumTraits< Scalar >::Real result_type
Definition: Functors.h:395
packet_traits< Scalar >::type Packet
Definition: Functors.h:706
packet_traits< Scalar >::type Packet
Definition: Functors.h:464
EIGEN_STRONG_INLINE scalar_constant_op(const scalar_constant_op &other)
Definition: Functors.h:517
EIGEN_STRONG_INLINE const Scalar predux(const Packet &a) const
Definition: Functors.h:134
EIGEN_STRONG_INLINE scalar_multiple2_op(const scalar_multiple2_op &other)
Definition: Functors.h:480
scalar_add_op(const scalar_add_op &other)
Definition: Functors.h:670
Packet padd(const Packet &a, const Packet &b)
packet_traits< Scalar >::type plset(const Scalar &a)
EIGEN_STRONG_INLINE const Packet packetOp(Index) const
Definition: Functors.h:567
Packet packetOp(const Packet &a) const
Definition: Functors.h:707
packet_traits< Scalar >::type Packet
Definition: Functors.h:426
EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f &a)
IntermediateState log(const Expression &arg)
scalar_product_traits< Scalar1, Scalar2 >::ReturnType result_type
Definition: Functors.h:479
NumTraits< Scalar >::Real result_type
Definition: Functors.h:312


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:37