UnaryFunctors.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-2016 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_UNARY_FUNCTORS_H
11 #define EIGEN_UNARY_FUNCTORS_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
22 template<typename Scalar> struct scalar_opposite_op {
24  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return -a; }
25  template<typename Packet>
27  { return internal::pnegate(a); }
28 };
29 template<typename Scalar>
31 { enum {
34 };
35 
41 template<typename Scalar> struct scalar_abs_op {
43  typedef typename NumTraits<Scalar>::Real result_type;
44  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return numext::abs(a); }
45  template<typename Packet>
47  { return internal::pabs(a); }
48 };
49 template<typename Scalar>
51 {
52  enum {
55  };
56 };
57 
63 template<typename Scalar> struct scalar_score_coeff_op : scalar_abs_op<Scalar>
64 {
65  typedef void Score_is_abs;
66 };
67 template<typename Scalar>
68 struct functor_traits<scalar_score_coeff_op<Scalar> > : functor_traits<scalar_abs_op<Scalar> > {};
69 
70 /* Avoid recomputing abs when we know the score and they are the same. Not a true Eigen functor. */
71 template<typename Scalar, typename=void> struct abs_knowing_score
72 {
74  typedef typename NumTraits<Scalar>::Real result_type;
75  template<typename Score>
76  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a, const Score&) const { return numext::abs(a); }
77 };
78 template<typename Scalar> struct abs_knowing_score<Scalar, typename scalar_score_coeff_op<Scalar>::Score_is_abs>
79 {
81  typedef typename NumTraits<Scalar>::Real result_type;
82  template<typename Scal>
83  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scal&, const result_type& a) const { return a; }
84 };
85 
91 template<typename Scalar> struct scalar_abs2_op {
93  typedef typename NumTraits<Scalar>::Real result_type;
95  EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return numext::abs2(a); }
96  template<typename Packet>
98  { return internal::pmul(a,a); }
99 };
100 template<typename Scalar>
102 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasAbs2 }; };
103 
109 template<typename Scalar> struct scalar_conjugate_op {
112  EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::conj(a); }
113  template<typename Packet>
115 };
116 template<typename Scalar>
118 {
119  enum {
120  Cost = 0,
121  // Yes the cost is zero even for complexes because in most cases for which
122  // the cost is used, conjugation turns to be a no-op. Some examples:
123  // cost(a*conj(b)) == cost(a*b)
124  // cost(a+conj(b)) == cost(a+b)
125  // <etc.
126  // If we don't set it to zero, then:
127  // A.conjugate().lazyProduct(B.conjugate())
128  // will bake its operands. We definitely don't want that!
130  };
131 };
132 
138 template<typename Scalar> struct scalar_arg_op {
140  typedef typename NumTraits<Scalar>::Real result_type;
141  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return numext::arg(a); }
142  template<typename Packet>
144  { return internal::parg(a); }
145 };
146 template<typename Scalar>
148 {
149  enum {
152  };
153 };
159 template<typename Scalar, typename NewType>
162  typedef NewType result_type;
163  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const NewType operator() (const Scalar& a) const { return cast<Scalar, NewType>(a); }
164 };
165 template<typename Scalar, typename NewType>
166 struct functor_traits<scalar_cast_op<Scalar,NewType> >
167 { enum { Cost = is_same<Scalar, NewType>::value ? 0 : NumTraits<NewType>::AddCost, PacketAccess = false }; };
168 
174 template<typename Scalar, int N>
177 
178  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const
179  { return a >> N; }
180  template<typename Packet>
182  { return internal::parithmetic_shift_right<N>(a); }
183 };
184 template<typename Scalar, int N>
186 { enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = packet_traits<Scalar>::HasShift }; };
187 
193 template<typename Scalar, int N>
196 
197  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const
198  { return a << N; }
199  template<typename Packet>
201  { return internal::plogical_shift_left<N>(a); }
202 };
203 template<typename Scalar, int N>
205 { enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = packet_traits<Scalar>::HasShift }; };
206 
212 template<typename Scalar>
215  typedef typename NumTraits<Scalar>::Real result_type;
217  EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::real(a); }
218 };
219 template<typename Scalar>
221 { enum { Cost = 0, PacketAccess = false }; };
222 
228 template<typename Scalar>
231  typedef typename NumTraits<Scalar>::Real result_type;
233  EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::imag(a); }
234 };
235 template<typename Scalar>
237 { enum { Cost = 0, PacketAccess = false }; };
238 
244 template<typename Scalar>
247  typedef typename NumTraits<Scalar>::Real result_type;
249  EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return numext::real_ref(*const_cast<Scalar*>(&a)); }
250 };
251 template<typename Scalar>
253 { enum { Cost = 0, PacketAccess = false }; };
254 
260 template<typename Scalar>
263  typedef typename NumTraits<Scalar>::Real result_type;
265  EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return numext::imag_ref(*const_cast<Scalar*>(&a)); }
266 };
267 template<typename Scalar>
269 { enum { Cost = 0, PacketAccess = false }; };
270 
277 template<typename Scalar> struct scalar_exp_op {
279  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::exp(a); }
280  template <typename Packet>
281  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pexp(a); }
282 };
283 template <typename Scalar>
284 struct functor_traits<scalar_exp_op<Scalar> > {
285  enum {
287  // The following numbers are based on the AVX implementation.
288 #ifdef EIGEN_VECTORIZE_FMA
289  // Haswell can issue 2 add/mul/madd per cycle.
290  Cost =
291  (sizeof(Scalar) == 4
292  // float: 8 pmadd, 4 pmul, 2 padd/psub, 6 other
294  // double: 7 pmadd, 5 pmul, 3 padd/psub, 1 div, 13 other
298 #else
299  Cost =
300  (sizeof(Scalar) == 4
301  // float: 7 pmadd, 6 pmul, 4 padd/psub, 10 other
303  // double: 7 pmadd, 5 pmul, 3 padd/psub, 1 div, 13 other
307 #endif
308  };
309 };
310 
317 template<typename Scalar> struct scalar_expm1_op {
319  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::expm1(a); }
320  template <typename Packet>
321  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pexpm1(a); }
322 };
323 template <typename Scalar>
324 struct functor_traits<scalar_expm1_op<Scalar> > {
325  enum {
327  Cost = functor_traits<scalar_exp_op<Scalar> >::Cost // TODO measure cost of expm1
328  };
329 };
330 
337 template<typename Scalar> struct scalar_log_op {
339  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::log(a); }
340  template <typename Packet>
341  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog(a); }
342 };
343 template <typename Scalar>
344 struct functor_traits<scalar_log_op<Scalar> > {
345  enum {
347  Cost =
348  (PacketAccess
349  // The following numbers are based on the AVX implementation.
350 #ifdef EIGEN_VECTORIZE_FMA
351  // 8 pmadd, 6 pmul, 8 padd/psub, 16 other, can issue 2 add/mul/madd per cycle.
353 #else
354  // 8 pmadd, 6 pmul, 8 padd/psub, 20 other
356 #endif
357  // Measured cost of std::log.
358  : sizeof(Scalar)==4 ? 40 : 85)
359  };
360 };
361 
368 template<typename Scalar> struct scalar_log1p_op {
370  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::log1p(a); }
371  template <typename Packet>
372  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog1p(a); }
373 };
374 template <typename Scalar>
375 struct functor_traits<scalar_log1p_op<Scalar> > {
376  enum {
378  Cost = functor_traits<scalar_log_op<Scalar> >::Cost // TODO measure cost of log1p
379  };
380 };
381 
388 template<typename Scalar> struct scalar_log10_op {
390  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { EIGEN_USING_STD(log10) return log10(a); }
391  template <typename Packet>
392  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog10(a); }
393 };
394 template<typename Scalar>
396 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasLog10 }; };
397 
404 template<typename Scalar> struct scalar_log2_op {
406  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return Scalar(EIGEN_LOG2E) * numext::log(a); }
407  template <typename Packet>
408  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::plog2(a); }
409 };
410 template<typename Scalar>
412 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasLog }; };
413 
418 template<typename Scalar> struct scalar_sqrt_op {
420  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::sqrt(a); }
421  template <typename Packet>
422  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psqrt(a); }
423 };
424 template <typename Scalar>
425 struct functor_traits<scalar_sqrt_op<Scalar> > {
426  enum {
427 #if EIGEN_FAST_MATH
428  // The following numbers are based on the AVX implementation.
429  Cost = (sizeof(Scalar) == 8 ? 28
430  // 4 pmul, 1 pmadd, 3 other
433 #else
434  // The following numbers are based on min VSQRT throughput on Haswell.
435  Cost = (sizeof(Scalar) == 8 ? 28 : 14),
436 #endif
438  };
439 };
440 
441 // Boolean specialization to eliminate -Wimplicit-conversion-floating-point-to-bool warnings.
442 template<> struct scalar_sqrt_op<bool> {
444  EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline bool operator() (const bool& a) const { return a; }
445  template <typename Packet>
446  EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return a; }
447 };
448 template <>
450  enum { Cost = 1, PacketAccess = packet_traits<bool>::Vectorizable };
451 };
452 
457 template<typename Scalar> struct scalar_rsqrt_op {
459  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::rsqrt(a); }
460  template <typename Packet>
461  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::prsqrt(a); }
462 };
463 
464 template<typename Scalar>
466 { enum {
469  };
470 };
471 
476 template<typename Scalar> struct scalar_cos_op {
478  EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return numext::cos(a); }
479  template <typename Packet>
480  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pcos(a); }
481 };
482 template<typename Scalar>
484 {
485  enum {
488  };
489 };
490 
495 template<typename Scalar> struct scalar_sin_op {
497  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::sin(a); }
498  template <typename Packet>
499  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psin(a); }
500 };
501 template<typename Scalar>
503 {
504  enum {
507  };
508 };
509 
510 
515 template<typename Scalar> struct scalar_tan_op {
517  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::tan(a); }
518  template <typename Packet>
519  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::ptan(a); }
520 };
521 template<typename Scalar>
523 {
524  enum {
527  };
528 };
529 
534 template<typename Scalar> struct scalar_acos_op {
536  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::acos(a); }
537  template <typename Packet>
538  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pacos(a); }
539 };
540 template<typename Scalar>
542 {
543  enum {
546  };
547 };
548 
553 template<typename Scalar> struct scalar_asin_op {
555  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::asin(a); }
556  template <typename Packet>
557  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pasin(a); }
558 };
559 template<typename Scalar>
561 {
562  enum {
565  };
566 };
567 
568 
573 template<typename Scalar> struct scalar_atan_op {
575  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::atan(a); }
576  template <typename Packet>
577  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::patan(a); }
578 };
579 template<typename Scalar>
581 {
582  enum {
585  };
586 };
587 
592 template <typename Scalar>
595  EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::tanh(a); }
596  template <typename Packet>
597  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& x) const { return ptanh(x); }
598 };
599 
600 template <typename Scalar>
601 struct functor_traits<scalar_tanh_op<Scalar> > {
602  enum {
605 // The following numbers are based on the AVX implementation,
606 #ifdef EIGEN_VECTORIZE_FMA
607  // Haswell can issue 2 add/mul/madd per cycle.
608  // 9 pmadd, 2 pmul, 1 div, 2 other
612 #else
616 #endif
617  // This number assumes a naive implementation of tanh
622  };
623 };
624 
625 #if EIGEN_HAS_CXX11_MATH
626 
630 template <typename Scalar>
631 struct scalar_atanh_op {
632  EIGEN_EMPTY_STRUCT_CTOR(scalar_atanh_op)
633  EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::atanh(a); }
634 };
635 
636 template <typename Scalar>
637 struct functor_traits<scalar_atanh_op<Scalar> > {
638  enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
639 };
640 #endif
641 
646 template<typename Scalar> struct scalar_sinh_op {
648  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::sinh(a); }
649  template <typename Packet>
650  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psinh(a); }
651 };
652 template<typename Scalar>
654 {
655  enum {
658  };
659 };
660 
661 #if EIGEN_HAS_CXX11_MATH
662 
666 template <typename Scalar>
667 struct scalar_asinh_op {
668  EIGEN_EMPTY_STRUCT_CTOR(scalar_asinh_op)
669  EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::asinh(a); }
670 };
671 
672 template <typename Scalar>
673 struct functor_traits<scalar_asinh_op<Scalar> > {
674  enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
675 };
676 #endif
677 
682 template<typename Scalar> struct scalar_cosh_op {
684  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const { return numext::cosh(a); }
685  template <typename Packet>
686  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pcosh(a); }
687 };
688 template<typename Scalar>
690 {
691  enum {
694  };
695 };
696 
697 #if EIGEN_HAS_CXX11_MATH
698 
702 template <typename Scalar>
703 struct scalar_acosh_op {
704  EIGEN_EMPTY_STRUCT_CTOR(scalar_acosh_op)
705  EIGEN_DEVICE_FUNC inline const Scalar operator()(const Scalar& a) const { return numext::acosh(a); }
706 };
707 
708 template <typename Scalar>
709 struct functor_traits<scalar_acosh_op<Scalar> > {
710  enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
711 };
712 #endif
713 
718 template<typename Scalar>
721  EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return Scalar(1)/a; }
722  template<typename Packet>
723  EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const
724  { return internal::pdiv(pset1<Packet>(Scalar(1)),a); }
725 };
726 template <typename Scalar>
728  enum {
731  };
732 };
733 
738 template<typename Scalar>
741  EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return a*a; }
742  template<typename Packet>
743  EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const
744  { return internal::pmul(a,a); }
745 };
746 template<typename Scalar>
748 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
749 
750 // Boolean specialization to avoid -Wint-in-bool-context warnings on GCC.
751 template<>
752 struct scalar_square_op<bool> {
754  EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline bool operator() (const bool& a) const { return a; }
755  template<typename Packet>
757  { return a; }
758 };
759 template<>
761 { enum { Cost = 0, PacketAccess = packet_traits<bool>::Vectorizable }; };
762 
767 template<typename Scalar>
770  EIGEN_DEVICE_FUNC inline Scalar operator() (const Scalar& a) const { return a*a*a; }
771  template<typename Packet>
772  EIGEN_DEVICE_FUNC inline const Packet packetOp(const Packet& a) const
773  { return internal::pmul(a,pmul(a,a)); }
774 };
775 template<typename Scalar>
777 { enum { Cost = 2*NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
778 
779 // Boolean specialization to avoid -Wint-in-bool-context warnings on GCC.
780 template<>
781 struct scalar_cube_op<bool> {
783  EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline bool operator() (const bool& a) const { return a; }
784  template<typename Packet>
786  { return a; }
787 };
788 template<>
790 { enum { Cost = 0, PacketAccess = packet_traits<bool>::Vectorizable }; };
791 
796 template<typename Scalar> struct scalar_round_op {
798  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::round(a); }
799  template <typename Packet>
800  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pround(a); }
801 };
802 template<typename Scalar>
804 {
805  enum {
808  };
809 };
810 
815 template<typename Scalar> struct scalar_floor_op {
817  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::floor(a); }
818  template <typename Packet>
819  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pfloor(a); }
820 };
821 template<typename Scalar>
823 {
824  enum {
827  };
828 };
829 
834 template<typename Scalar> struct scalar_rint_op {
836  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::rint(a); }
837  template <typename Packet>
838  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::print(a); }
839 };
840 template<typename Scalar>
842 {
843  enum {
846  };
847 };
848 
853 template<typename Scalar> struct scalar_ceil_op {
855  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::ceil(a); }
856  template <typename Packet>
857  EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::pceil(a); }
858 };
859 template<typename Scalar>
861 {
862  enum {
865  };
866 };
867 
872 template<typename Scalar> struct scalar_isnan_op {
874  typedef bool result_type;
875  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const {
876 #if defined(SYCL_DEVICE_ONLY)
877  return numext::isnan(a);
878 #else
879  return (numext::isnan)(a);
880 #endif
881  }
882 };
883 template<typename Scalar>
885 {
886  enum {
888  PacketAccess = false
889  };
890 };
891 
896 template<typename Scalar> struct scalar_isinf_op {
898  typedef bool result_type;
899  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const {
900 #if defined(SYCL_DEVICE_ONLY)
901  return numext::isinf(a);
902 #else
903  return (numext::isinf)(a);
904 #endif
905  }
906 };
907 template<typename Scalar>
909 {
910  enum {
912  PacketAccess = false
913  };
914 };
915 
920 template<typename Scalar> struct scalar_isfinite_op {
922  typedef bool result_type;
923  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const {
924 #if defined(SYCL_DEVICE_ONLY)
925  return numext::isfinite(a);
926 #else
927  return (numext::isfinite)(a);
928 #endif
929  }
930 };
931 template<typename Scalar>
933 {
934  enum {
936  PacketAccess = false
937  };
938 };
939 
945 template<typename Scalar> struct scalar_boolean_not_op {
947  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator() (const bool& a) const { return !a; }
948 };
949 template<typename Scalar>
951  enum {
953  PacketAccess = false
954  };
955 };
956 
962 template<typename Scalar>
963 struct scalar_sign_op<Scalar, false, true> {
965  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const
966  {
967  return Scalar( (a>Scalar(0)) - (a<Scalar(0)) );
968  }
969  //TODO
970  //template <typename Packet>
971  //EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psign(a); }
972 };
973 
974 template<typename Scalar>
975 struct scalar_sign_op<Scalar, false, false> {
977  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const
978  {
979  return (numext::isnan)(a) ? a : Scalar( (a>Scalar(0)) - (a<Scalar(0)) );
980  }
981  //TODO
982  //template <typename Packet>
983  //EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psign(a); }
984 };
985 
986 template<typename Scalar, bool is_integer>
987 struct scalar_sign_op<Scalar,true, is_integer> {
989  EIGEN_DEVICE_FUNC inline const Scalar operator() (const Scalar& a) const
990  {
991  typedef typename NumTraits<Scalar>::Real real_type;
992  real_type aa = numext::abs(a);
993  if (aa==real_type(0))
994  return Scalar(0);
995  aa = real_type(1)/aa;
996  return Scalar(a.real()*aa, a.imag()*aa );
997  }
998  //TODO
999  //template <typename Packet>
1000  //EIGEN_DEVICE_FUNC inline Packet packetOp(const Packet& a) const { return internal::psign(a); }
1001 };
1002 template<typename Scalar>
1004 { enum {
1005  Cost =
1007  ? ( 8*NumTraits<Scalar>::MulCost ) // roughly
1010  };
1011 };
1012 
1017 template <typename T>
1020  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const {
1021  return packetOp(x);
1022  }
1023 
1024  template <typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1025  Packet packetOp(const Packet& x) const {
1026  const Packet one = pset1<Packet>(T(1));
1027  return pdiv(one, padd(one, pexp(pnegate(x))));
1028  }
1029 };
1030 
1031 #ifndef EIGEN_GPU_COMPILE_PHASE
1032 
1043 template <>
1046  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float operator()(const float& x) const {
1047  return packetOp(x);
1048  }
1049 
1050  template <typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
1051  Packet packetOp(const Packet& _x) const {
1052  const Packet cutoff_lower = pset1<Packet>(-9.f);
1053  const Packet lt_mask = pcmp_lt<Packet>(_x, cutoff_lower);
1054  const bool any_small = predux_any(lt_mask);
1055 
1056  // The upper cut-off is the smallest x for which the rational approximation evaluates to 1.
1057  // Choosing this value saves us a few instructions clamping the results at the end.
1058 #ifdef EIGEN_VECTORIZE_FMA
1059  const Packet cutoff_upper = pset1<Packet>(15.7243833541870117f);
1060 #else
1061  const Packet cutoff_upper = pset1<Packet>(15.6437711715698242f);
1062 #endif
1063  const Packet x = pmin(_x, cutoff_upper);
1064 
1065  // The monomial coefficients of the numerator polynomial (odd).
1066  const Packet alpha_1 = pset1<Packet>(2.48287947061529e-01f);
1067  const Packet alpha_3 = pset1<Packet>(8.51377133304701e-03f);
1068  const Packet alpha_5 = pset1<Packet>(6.08574864600143e-05f);
1069  const Packet alpha_7 = pset1<Packet>(1.15627324459942e-07f);
1070  const Packet alpha_9 = pset1<Packet>(4.37031012579801e-11f);
1071 
1072  // The monomial coefficients of the denominator polynomial (even).
1073  const Packet beta_0 = pset1<Packet>(9.93151921023180e-01f);
1074  const Packet beta_2 = pset1<Packet>(1.16817656904453e-01f);
1075  const Packet beta_4 = pset1<Packet>(1.70198817374094e-03f);
1076  const Packet beta_6 = pset1<Packet>(6.29106785017040e-06f);
1077  const Packet beta_8 = pset1<Packet>(5.76102136993427e-09f);
1078  const Packet beta_10 = pset1<Packet>(6.10247389755681e-13f);
1079 
1080  // Since the polynomials are odd/even, we need x^2.
1081  const Packet x2 = pmul(x, x);
1082 
1083  // Evaluate the numerator polynomial p.
1084  Packet p = pmadd(x2, alpha_9, alpha_7);
1085  p = pmadd(x2, p, alpha_5);
1086  p = pmadd(x2, p, alpha_3);
1087  p = pmadd(x2, p, alpha_1);
1088  p = pmul(x, p);
1089 
1090  // Evaluate the denominator polynomial q.
1091  Packet q = pmadd(x2, beta_10, beta_8);
1092  q = pmadd(x2, q, beta_6);
1093  q = pmadd(x2, q, beta_4);
1094  q = pmadd(x2, q, beta_2);
1095  q = pmadd(x2, q, beta_0);
1096  // Divide the numerator by the denominator and shift it up.
1097  const Packet logistic = padd(pdiv(p, q), pset1<Packet>(0.5f));
1098  if (EIGEN_PREDICT_FALSE(any_small)) {
1099  const Packet exponential = pexp(_x);
1100  return pselect(lt_mask, exponential, logistic);
1101  } else {
1102  return logistic;
1103  }
1104  }
1105 };
1106 #endif // #ifndef EIGEN_GPU_COMPILE_PHASE
1107 
1108 template <typename T>
1110  enum {
1111  // The cost estimate for float here here is for the common(?) case where
1112  // all arguments are greater than -9.
1116  : NumTraits<T>::AddCost * 2 +
1118  PacketAccess =
1124  };
1125 };
1126 
1127 } // end namespace internal
1128 
1129 } // end namespace Eigen
1130 
1131 #endif // EIGEN_FUNCTORS_H
EIGEN_DEVICE_FUNC const Log1pReturnType log1p() const
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
SCALAR Scalar
Definition: bench_gemm.cpp:46
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
#define EIGEN_EMPTY_STRUCT_CTOR(X)
Definition: XprHelper.h:22
EIGEN_STRONG_INLINE bool predux_any(const Packet4f &x)
EIGEN_DEVICE_FUNC internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type real_ref(const Scalar &x)
float real
Definition: datatypes.h:10
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pasin(const Packet &a)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog2(const Packet &a)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T exp(const T &x)
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet patan(const Packet &a)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T rsqrt(const T &x)
NumTraits< Scalar >::Real result_type
Definition: UnaryFunctors.h:43
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &x) const
NumTraits< Scalar >::Real result_type
Definition: UnaryFunctors.h:74
NumTraits< Scalar >::Real result_type
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
NumTraits< Scalar >::Real result_type
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptanh(const Packet &a)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T cos(const T &x)
EIGEN_DEVICE_FUNC const Packet packetOp(const Packet &a) const
#define N
Definition: gksort.c:12
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psinh(const Packet &a)
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
AnnoyingScalar conj(const AnnoyingScalar &x)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar &a) const
Definition: UnaryFunctors.h:24
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T atan(const T &x)
EIGEN_DEVICE_FUNC const Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC Packet padd(const Packet &a, const Packet &b)
EIGEN_DEVICE_FUNC T() ceil(const T &x)
EIGEN_DEVICE_FUNC Packet pmin(const Packet &a, const Packet &b)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexp(const Packet &a)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
Definition: UnaryFunctors.h:26
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pceil(const Packet &a)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ptan(const Packet &a)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &x) const
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog1p(const Packet &a)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE internal::enable_if< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real >::type abs(const T &x)
#define EIGEN_FAST_MATH
Definition: Macros.h:49
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC const Expm1ReturnType expm1() const
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
NumTraits< Scalar >::Real result_type
EIGEN_DEVICE_FUNC Packet parg(const Packet &a)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T tanh(const T &x)
EIGEN_DEVICE_FUNC const RintReturnType rint() const
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pacos(const Packet &a)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T tan(const T &x)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isfinite(const Eigen::bfloat16 &h)
Definition: BFloat16.h:671
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Eigen::Triplet< double > T
EIGEN_DEVICE_FUNC T() floor(const T &x)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
EIGEN_DEVICE_FUNC internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type imag_ref(const Scalar &x)
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC const Scalar & q
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T sin(const T &x)
EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf &a)
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
#define EIGEN_LOG2E
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC const Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isinf(const Eigen::bfloat16 &h)
Definition: BFloat16.h:665
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
Definition: UnaryFunctors.h:46
EIGEN_DEPRECATED EIGEN_DEVICE_FUNC const Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
Definition: UnaryFunctors.h:97
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T asin(const T &x)
mp::number< mp::cpp_dec_float< 100 >, mp::et_on > Real
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &_x) const
EIGEN_DEVICE_FUNC const Packet packetOp(const Packet &a) const
EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf &a)
EIGEN_DEVICE_FUNC Packet pdiv(const Packet &a, const Packet &b)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC const Log10ReturnType log10() const
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog10(const Packet &a)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pfloor(const Packet &a)
#define EIGEN_USING_STD(FUNC)
Definition: Macros.h:1185
#define EIGEN_DEPRECATED
Definition: Macros.h:1058
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plog(const Packet &a)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isnan(const Eigen::bfloat16 &h)
Definition: BFloat16.h:659
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pround(const Packet &a)
float * p
EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f &a, const Packet4f &b, const Packet4f &c)
#define EIGEN_PREDICT_FALSE(x)
Definition: Macros.h:1321
EIGEN_STRONG_INLINE Packet4f pselect(const Packet4f &mask, const Packet4f &a, const Packet4f &b)
EIGEN_DEVICE_FUNC const ImagReturnType imag() const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T cosh(const T &x)
NumTraits< Scalar >::Real result_type
EIGEN_STRONG_INLINE Packet4f psqrt(const Packet4f &a)
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcos(const Packet &a)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T sinh(const T &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pexpm1(const Packet &a)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet psin(const Packet &a)
EIGEN_STRONG_INLINE Packet4f prsqrt(const Packet4f &a)
EIGEN_DEVICE_FUNC const LogisticReturnType logistic() const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T acos(const T &x)
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T log(const T &x)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float sqrt(const float &x)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
NumTraits< Scalar >::Real result_type
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp(const Packet &a) const
EIGEN_DEVICE_FUNC bool abs2(bool x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pcosh(const Packet &a)
EIGEN_DEVICE_FUNC Packet pmul(const Packet &a, const Packet &b)
EIGEN_DEVICE_FUNC Packet packetOp(const Packet &a) const
EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f &a)
EIGEN_DEVICE_FUNC const RoundReturnType round() const
NumTraits< Scalar >::Real result_type
Definition: UnaryFunctors.h:93


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:40:41