10 #ifndef EIGEN_FUNCTORS_H
11 #define EIGEN_FUNCTORS_H
24 template<
typename Scalar>
struct scalar_sum_op {
25 EIGEN_EMPTY_STRUCT_CTOR(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); }
34 template<
typename Scalar>
35 struct functor_traits<scalar_sum_op<Scalar> > {
37 Cost = NumTraits<Scalar>::AddCost,
38 PacketAccess = packet_traits<Scalar>::HasAdd
47 template<
typename LhsScalar,
typename RhsScalar>
struct scalar_product_op {
50 Vectorizable = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasMul && packet_traits<RhsScalar>::HasMul
52 typedef typename scalar_product_traits<LhsScalar,RhsScalar>::ReturnType result_type;
53 EIGEN_EMPTY_STRUCT_CTOR(scalar_product_op)
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); }
62 template<
typename LhsScalar,
typename RhsScalar>
63 struct functor_traits<scalar_product_op<LhsScalar,RhsScalar> > {
65 Cost = (NumTraits<LhsScalar>::MulCost + NumTraits<RhsScalar>::MulCost)/2,
66 PacketAccess = scalar_product_op<LhsScalar,RhsScalar>::Vectorizable
75 template<
typename LhsScalar,
typename RhsScalar>
struct scalar_conj_product_op {
78 Conj = NumTraits<LhsScalar>::IsComplex
81 typedef typename scalar_product_traits<LhsScalar,RhsScalar>::ReturnType result_type;
83 EIGEN_EMPTY_STRUCT_CTOR(scalar_conj_product_op)
84 EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b)
const
85 {
return conj_helper<LhsScalar,RhsScalar,Conj,false>().pmul(a,b); }
87 template<
typename Packet>
88 EIGEN_STRONG_INLINE
const Packet packetOp(
const Packet& a,
const Packet& b)
const
89 {
return conj_helper<Packet,Packet,Conj,false>().pmul(a,b); }
91 template<
typename LhsScalar,
typename RhsScalar>
92 struct functor_traits<scalar_conj_product_op<LhsScalar,RhsScalar> > {
94 Cost = NumTraits<LhsScalar>::MulCost,
95 PacketAccess = internal::is_same<LhsScalar, RhsScalar>::value && packet_traits<LhsScalar>::HasMul
104 template<
typename Scalar>
struct scalar_min_op {
105 EIGEN_EMPTY_STRUCT_CTOR(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); }
114 template<
typename Scalar>
115 struct functor_traits<scalar_min_op<Scalar> > {
117 Cost = NumTraits<Scalar>::AddCost,
118 PacketAccess = packet_traits<Scalar>::HasMin
127 template<
typename Scalar>
struct scalar_max_op {
128 EIGEN_EMPTY_STRUCT_CTOR(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); }
137 template<
typename Scalar>
138 struct functor_traits<scalar_max_op<Scalar> > {
140 Cost = NumTraits<Scalar>::AddCost,
141 PacketAccess = packet_traits<Scalar>::HasMax
150 template<
typename Scalar>
struct scalar_hypot_op {
151 EIGEN_EMPTY_STRUCT_CTOR(scalar_hypot_op)
153 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& _x, const Scalar& _y)
const
158 Scalar p = (max)(_x, _y);
159 Scalar q = (min)(_x, _y);
161 return p * sqrt(Scalar(1) + qp*qp);
164 template<
typename Scalar>
165 struct functor_traits<scalar_hypot_op<Scalar> > {
166 enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess=0 };
172 template<
typename Scalar,
typename OtherScalar>
struct scalar_binary_pow_op {
173 EIGEN_EMPTY_STRUCT_CTOR(scalar_binary_pow_op)
174 inline Scalar operator() (const Scalar& a, const OtherScalar& b)
const {
return numext::pow(a, b); }
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 };
188 template<
typename Scalar>
struct scalar_difference_op {
189 EIGEN_EMPTY_STRUCT_CTOR(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); }
195 template<
typename Scalar>
196 struct functor_traits<scalar_difference_op<Scalar> > {
198 Cost = NumTraits<Scalar>::AddCost,
199 PacketAccess = packet_traits<Scalar>::HasSub
208 template<
typename LhsScalar,
typename RhsScalar>
struct scalar_quotient_op {
211 Vectorizable = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasDiv && packet_traits<RhsScalar>::HasDiv
213 typedef typename scalar_product_traits<LhsScalar,RhsScalar>::ReturnType result_type;
214 EIGEN_EMPTY_STRUCT_CTOR(scalar_quotient_op)
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); }
220 template<
typename LhsScalar,
typename RhsScalar>
221 struct functor_traits<scalar_quotient_op<LhsScalar,RhsScalar> > {
223 Cost = (NumTraits<LhsScalar>::MulCost + NumTraits<RhsScalar>::MulCost),
224 PacketAccess = scalar_quotient_op<LhsScalar,RhsScalar>::Vectorizable
235 struct scalar_boolean_and_op {
236 EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_and_op)
237 EIGEN_STRONG_INLINE
bool operator() (const
bool& a, const
bool& b)
const {
return a && b; }
239 template<>
struct functor_traits<scalar_boolean_and_op> {
241 Cost = NumTraits<bool>::AddCost,
251 struct scalar_boolean_or_op {
252 EIGEN_EMPTY_STRUCT_CTOR(scalar_boolean_or_op)
253 EIGEN_STRONG_INLINE
bool operator() (const
bool& a, const
bool& b)
const {
return a || b; }
255 template<>
struct functor_traits<scalar_boolean_or_op> {
257 Cost = NumTraits<bool>::AddCost,
266 template<
typename Scalar, ComparisonName cmp>
struct scalar_cmp_op;
268 template<
typename Scalar, ComparisonName cmp>
269 struct functor_traits<scalar_cmp_op<Scalar, cmp> > {
271 Cost = NumTraits<Scalar>::AddCost,
276 template<ComparisonName Cmp,
typename Scalar>
277 struct result_of<scalar_cmp_op<Scalar, Cmp>(Scalar,Scalar)> {
282 template<
typename Scalar>
struct scalar_cmp_op<Scalar, cmp_EQ> {
283 EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
284 EIGEN_STRONG_INLINE
bool operator()(const Scalar& a, const Scalar& b)
const {
return a==b;}
286 template<
typename Scalar>
struct scalar_cmp_op<Scalar, cmp_LT> {
287 EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
288 EIGEN_STRONG_INLINE
bool operator()(const Scalar& a, const Scalar& b)
const {
return a<b;}
290 template<
typename Scalar>
struct scalar_cmp_op<Scalar, cmp_LE> {
291 EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
292 EIGEN_STRONG_INLINE
bool operator()(const Scalar& a, const Scalar& b)
const {
return a<=b;}
294 template<
typename Scalar>
struct scalar_cmp_op<Scalar, cmp_UNORD> {
295 EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
296 EIGEN_STRONG_INLINE
bool operator()(const Scalar& a, const Scalar& b)
const {
return !(a<=b || b<=a);}
298 template<
typename Scalar>
struct scalar_cmp_op<Scalar, cmp_NEQ> {
299 EIGEN_EMPTY_STRUCT_CTOR(scalar_cmp_op)
300 EIGEN_STRONG_INLINE
bool operator()(const Scalar& a, const Scalar& b)
const {
return a!=b;}
310 template<
typename Scalar>
struct scalar_opposite_op {
311 EIGEN_EMPTY_STRUCT_CTOR(scalar_opposite_op)
312 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a)
const {
return -a; }
313 template<
typename Packet>
314 EIGEN_STRONG_INLINE
const Packet packetOp(
const Packet& a)
const
315 {
return internal::pnegate(a); }
317 template<
typename Scalar>
318 struct functor_traits<scalar_opposite_op<Scalar> >
320 Cost = NumTraits<Scalar>::AddCost,
321 PacketAccess = packet_traits<Scalar>::HasNegate };
329 template<
typename Scalar>
struct scalar_abs_op {
330 EIGEN_EMPTY_STRUCT_CTOR(scalar_abs_op)
331 typedef typename NumTraits<Scalar>::Real result_type;
332 EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a)
const {
using std::abs;
return abs(a); }
333 template<
typename Packet>
334 EIGEN_STRONG_INLINE
const Packet packetOp(
const Packet& a)
const
335 {
return internal::pabs(a); }
337 template<
typename Scalar>
338 struct functor_traits<scalar_abs_op<Scalar> >
341 Cost = NumTraits<Scalar>::AddCost,
342 PacketAccess = packet_traits<Scalar>::HasAbs
351 template<
typename Scalar>
struct scalar_abs2_op {
352 EIGEN_EMPTY_STRUCT_CTOR(scalar_abs2_op)
353 typedef typename NumTraits<Scalar>::Real result_type;
354 EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a)
const {
return numext::abs2(a); }
355 template<
typename Packet>
356 EIGEN_STRONG_INLINE
const Packet packetOp(
const Packet& a)
const
357 {
return internal::pmul(a,a); }
359 template<
typename Scalar>
360 struct functor_traits<scalar_abs2_op<Scalar> >
361 {
enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasAbs2 }; };
368 template<
typename Scalar>
struct scalar_conjugate_op {
369 EIGEN_EMPTY_STRUCT_CTOR(scalar_conjugate_op)
370 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a)
const {
using numext::conj;
return conj(a); }
371 template<
typename Packet>
372 EIGEN_STRONG_INLINE
const Packet packetOp(
const Packet& a)
const {
return internal::pconj(a); }
374 template<
typename Scalar>
375 struct functor_traits<scalar_conjugate_op<Scalar> >
378 Cost = NumTraits<Scalar>::IsComplex ? NumTraits<Scalar>::AddCost : 0,
379 PacketAccess = packet_traits<Scalar>::HasConj
388 template<
typename Scalar,
typename NewType>
389 struct scalar_cast_op {
390 EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
391 typedef NewType result_type;
392 EIGEN_STRONG_INLINE const NewType operator() (const Scalar& a)
const {
return cast<Scalar, NewType>(a); }
394 template<
typename Scalar,
typename NewType>
395 struct functor_traits<scalar_cast_op<Scalar,NewType> >
396 {
enum { Cost = is_same<Scalar, NewType>::value ? 0 : NumTraits<NewType>::AddCost, PacketAccess =
false }; };
403 template<
typename Scalar>
404 struct scalar_real_op {
405 EIGEN_EMPTY_STRUCT_CTOR(scalar_real_op)
406 typedef typename NumTraits<Scalar>::Real result_type;
407 EIGEN_STRONG_INLINE result_type operator() (const Scalar& a)
const {
return numext::real(a); }
409 template<
typename Scalar>
410 struct functor_traits<scalar_real_op<Scalar> >
411 {
enum { Cost = 0, PacketAccess =
false }; };
418 template<
typename Scalar>
419 struct scalar_imag_op {
420 EIGEN_EMPTY_STRUCT_CTOR(scalar_imag_op)
421 typedef typename NumTraits<Scalar>::Real result_type;
422 EIGEN_STRONG_INLINE result_type operator() (const Scalar& a)
const {
return numext::imag(a); }
424 template<
typename Scalar>
425 struct functor_traits<scalar_imag_op<Scalar> >
426 {
enum { Cost = 0, PacketAccess =
false }; };
433 template<
typename Scalar>
434 struct scalar_real_ref_op {
435 EIGEN_EMPTY_STRUCT_CTOR(scalar_real_ref_op)
436 typedef typename NumTraits<Scalar>::Real result_type;
437 EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a)
const {
return numext::real_ref(*const_cast<Scalar*>(&a)); }
439 template<
typename Scalar>
440 struct functor_traits<scalar_real_ref_op<Scalar> >
441 {
enum { Cost = 0, PacketAccess =
false }; };
448 template<
typename Scalar>
449 struct scalar_imag_ref_op {
450 EIGEN_EMPTY_STRUCT_CTOR(scalar_imag_ref_op)
451 typedef typename NumTraits<Scalar>::Real result_type;
452 EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a)
const {
return numext::imag_ref(*const_cast<Scalar*>(&a)); }
454 template<
typename Scalar>
455 struct functor_traits<scalar_imag_ref_op<Scalar> >
456 {
enum { Cost = 0, PacketAccess =
false }; };
464 template<
typename Scalar>
struct scalar_exp_op {
465 EIGEN_EMPTY_STRUCT_CTOR(scalar_exp_op)
466 inline const Scalar operator() (const Scalar& a)
const {
using std::exp;
return exp(a); }
467 typedef typename packet_traits<Scalar>::type Packet;
468 inline Packet packetOp(
const Packet& a)
const {
return internal::pexp(a); }
470 template<
typename Scalar>
471 struct functor_traits<scalar_exp_op<Scalar> >
472 {
enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasExp }; };
480 template<
typename Scalar>
struct scalar_log_op {
481 EIGEN_EMPTY_STRUCT_CTOR(scalar_log_op)
482 inline const Scalar operator() (const Scalar& a)
const {
using std::log;
return log(a); }
483 typedef typename packet_traits<Scalar>::type Packet;
484 inline Packet packetOp(
const Packet& a)
const {
return internal::plog(a); }
486 template<
typename Scalar>
487 struct functor_traits<scalar_log_op<Scalar> >
488 {
enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasLog }; };
503 template<
typename Scalar>
504 struct scalar_multiple_op {
505 typedef typename packet_traits<Scalar>::type Packet;
507 EIGEN_STRONG_INLINE scalar_multiple_op(
const scalar_multiple_op& other) : m_other(other.m_other) { }
508 EIGEN_STRONG_INLINE scalar_multiple_op(
const Scalar& other) : m_other(other) { }
509 EIGEN_STRONG_INLINE Scalar operator() (
const Scalar& a)
const {
return a * m_other; }
510 EIGEN_STRONG_INLINE
const Packet packetOp(
const Packet& a)
const
511 {
return internal::pmul(a, pset1<Packet>(m_other)); }
512 typename add_const_on_value_type<typename NumTraits<Scalar>::Nested>::type m_other;
514 template<
typename Scalar>
515 struct functor_traits<scalar_multiple_op<Scalar> >
516 {
enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
518 template<
typename Scalar1,
typename Scalar2>
519 struct scalar_multiple2_op {
520 typedef typename scalar_product_traits<Scalar1,Scalar2>::ReturnType result_type;
521 EIGEN_STRONG_INLINE scalar_multiple2_op(
const scalar_multiple2_op& other) : m_other(other.m_other) { }
522 EIGEN_STRONG_INLINE scalar_multiple2_op(
const Scalar2& other) : m_other(other) { }
523 EIGEN_STRONG_INLINE result_type operator() (
const Scalar1& a)
const {
return a * m_other; }
524 typename add_const_on_value_type<typename NumTraits<Scalar2>::Nested>::type m_other;
526 template<
typename Scalar1,
typename Scalar2>
527 struct functor_traits<scalar_multiple2_op<Scalar1,Scalar2> >
528 {
enum { Cost = NumTraits<Scalar1>::MulCost, PacketAccess =
false }; };
538 template<
typename Scalar>
539 struct scalar_quotient1_op {
540 typedef typename packet_traits<Scalar>::type Packet;
542 EIGEN_STRONG_INLINE scalar_quotient1_op(
const scalar_quotient1_op& other) : m_other(other.m_other) { }
543 EIGEN_STRONG_INLINE scalar_quotient1_op(
const Scalar& other) : m_other(other) {}
544 EIGEN_STRONG_INLINE Scalar operator() (
const Scalar& a)
const {
return a / m_other; }
545 EIGEN_STRONG_INLINE
const Packet packetOp(
const Packet& a)
const
546 {
return internal::pdiv(a, pset1<Packet>(m_other)); }
547 typename add_const_on_value_type<typename NumTraits<Scalar>::Nested>::type m_other;
549 template<
typename Scalar>
550 struct functor_traits<scalar_quotient1_op<Scalar> >
551 {
enum { Cost = 2 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasDiv }; };
555 template<
typename Scalar>
556 struct scalar_constant_op {
557 typedef typename packet_traits<Scalar>::type Packet;
558 EIGEN_STRONG_INLINE scalar_constant_op(
const scalar_constant_op& other) : m_other(other.m_other) { }
559 EIGEN_STRONG_INLINE scalar_constant_op(
const Scalar& other) : m_other(other) { }
560 template<
typename Index>
561 EIGEN_STRONG_INLINE
const Scalar operator() (Index, Index = 0)
const {
return m_other; }
562 template<
typename Index>
563 EIGEN_STRONG_INLINE
const Packet packetOp(Index, Index = 0)
const {
return internal::pset1<Packet>(m_other); }
564 const Scalar m_other;
566 template<
typename Scalar>
567 struct functor_traits<scalar_constant_op<Scalar> >
569 {
enum { Cost = 1, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable =
true }; };
571 template<
typename Scalar>
struct scalar_identity_op {
572 EIGEN_EMPTY_STRUCT_CTOR(scalar_identity_op)
573 template<typename Index>
574 EIGEN_STRONG_INLINE const Scalar operator() (Index row, Index col)
const {
return row==col ? Scalar(1) : Scalar(0); }
576 template<
typename Scalar>
577 struct functor_traits<scalar_identity_op<Scalar> >
578 {
enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess =
false, IsRepeatable =
true }; };
580 template <
typename Scalar,
bool RandomAccess>
struct linspaced_op_impl;
590 template <
typename Scalar>
591 struct linspaced_op_impl<Scalar,false>
593 typedef typename packet_traits<Scalar>::type Packet;
595 linspaced_op_impl(
const Scalar& low,
const Scalar& step) :
596 m_low(low), m_step(step),
597 m_packetStep(pset1<Packet>(packet_traits<Scalar>::size*step)),
598 m_base(padd(pset1<Packet>(low), pmul(pset1<Packet>(step),plset<Scalar>(-packet_traits<Scalar>::size)))) {}
600 template<
typename Index>
601 EIGEN_STRONG_INLINE
const Scalar operator() (Index i)
const
603 m_base = padd(m_base, pset1<Packet>(m_step));
604 return m_low+Scalar(i)*m_step;
607 template<
typename Index>
608 EIGEN_STRONG_INLINE
const Packet packetOp(Index)
const {
return m_base = padd(m_base,m_packetStep); }
612 const Packet m_packetStep;
613 mutable Packet m_base;
619 template <
typename Scalar>
620 struct linspaced_op_impl<Scalar,true>
622 typedef typename packet_traits<Scalar>::type Packet;
624 linspaced_op_impl(
const Scalar& low,
const Scalar& step) :
625 m_low(low), m_step(step),
626 m_lowPacket(pset1<Packet>(m_low)), m_stepPacket(pset1<Packet>(m_step)), m_interPacket(plset<Scalar>(0)) {}
628 template<
typename Index>
629 EIGEN_STRONG_INLINE
const Scalar operator() (Index i)
const {
return m_low+i*m_step; }
631 template<
typename Index>
632 EIGEN_STRONG_INLINE
const Packet packetOp(Index i)
const
633 {
return internal::padd(m_lowPacket, pmul(m_stepPacket, padd(pset1<Packet>(Scalar(i)),m_interPacket))); }
637 const Packet m_lowPacket;
638 const Packet m_stepPacket;
639 const Packet m_interPacket;
647 template <
typename Scalar,
bool RandomAccess = true>
struct linspaced_op;
648 template <
typename Scalar,
bool RandomAccess>
struct functor_traits< linspaced_op<Scalar,RandomAccess> >
649 {
enum { Cost = 1, PacketAccess = packet_traits<Scalar>::HasSetLinear, IsRepeatable =
true }; };
650 template <
typename Scalar,
bool RandomAccess>
struct linspaced_op
652 typedef typename packet_traits<Scalar>::type Packet;
653 linspaced_op(
const Scalar& low,
const Scalar& high, DenseIndex num_steps) : impl((num_steps==1 ? high : low), (num_steps==1 ? Scalar() : (high-low)/Scalar(num_steps-1))) {}
655 template<
typename Index>
656 EIGEN_STRONG_INLINE
const Scalar operator() (Index i)
const {
return impl(i); }
660 template<
typename Index>
661 EIGEN_STRONG_INLINE
const Scalar operator() (Index row, Index col)
const
663 eigen_assert(col==0 || row==0);
664 return impl(col + row);
667 template<
typename Index>
668 EIGEN_STRONG_INLINE
const Packet packetOp(Index i)
const {
return impl.packetOp(i); }
672 template<
typename Index>
673 EIGEN_STRONG_INLINE
const Packet packetOp(Index row, Index col)
const
675 eigen_assert(col==0 || row==0);
676 return impl.packetOp(col + row);
682 const linspaced_op_impl<Scalar,RandomAccess> impl;
689 template<
typename Functor>
struct functor_has_linear_access {
enum { ret = 1 }; };
690 template<
typename Scalar>
struct functor_has_linear_access<scalar_identity_op<Scalar> > {
enum { ret = 0 }; };
696 template<
typename Functor>
struct functor_is_product_like {
enum { ret = 0 }; };
697 template<
typename LhsScalar,
typename RhsScalar>
struct functor_is_product_like<scalar_product_op<LhsScalar,RhsScalar> > {
enum { ret = 1 }; };
698 template<
typename LhsScalar,
typename RhsScalar>
struct functor_is_product_like<scalar_conj_product_op<LhsScalar,RhsScalar> > {
enum { ret = 1 }; };
699 template<
typename LhsScalar,
typename RhsScalar>
struct functor_is_product_like<scalar_quotient_op<LhsScalar,RhsScalar> > {
enum { ret = 1 }; };
707 template<
typename Scalar>
708 struct scalar_add_op {
709 typedef typename packet_traits<Scalar>::type Packet;
711 inline scalar_add_op(
const scalar_add_op& other) : m_other(other.m_other) { }
712 inline scalar_add_op(
const Scalar& other) : m_other(other) { }
713 inline Scalar operator() (
const Scalar& a)
const {
return a + m_other; }
714 inline const Packet packetOp(
const Packet& a)
const
715 {
return internal::padd(a, pset1<Packet>(m_other)); }
716 const Scalar m_other;
718 template<
typename Scalar>
719 struct functor_traits<scalar_add_op<Scalar> >
720 {
enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = packet_traits<Scalar>::HasAdd }; };
726 template<
typename Scalar>
struct scalar_sqrt_op {
727 EIGEN_EMPTY_STRUCT_CTOR(scalar_sqrt_op)
728 inline const Scalar operator() (const Scalar& a)
const {
using std::sqrt;
return sqrt(a); }
729 typedef typename packet_traits<Scalar>::type Packet;
730 inline Packet packetOp(
const Packet& a)
const {
return internal::psqrt(a); }
732 template<
typename Scalar>
733 struct functor_traits<scalar_sqrt_op<Scalar> >
735 Cost = 5 * NumTraits<Scalar>::MulCost,
736 PacketAccess = packet_traits<Scalar>::HasSqrt
744 template<
typename Scalar>
struct scalar_cos_op {
745 EIGEN_EMPTY_STRUCT_CTOR(scalar_cos_op)
746 inline Scalar operator() (const Scalar& a)
const {
using std::cos;
return cos(a); }
747 typedef typename packet_traits<Scalar>::type Packet;
748 inline Packet packetOp(
const Packet& a)
const {
return internal::pcos(a); }
750 template<
typename Scalar>
751 struct functor_traits<scalar_cos_op<Scalar> >
754 Cost = 5 * NumTraits<Scalar>::MulCost,
755 PacketAccess = packet_traits<Scalar>::HasCos
763 template<
typename Scalar>
struct scalar_sin_op {
764 EIGEN_EMPTY_STRUCT_CTOR(scalar_sin_op)
765 inline const Scalar operator() (const Scalar& a)
const {
using std::sin;
return sin(a); }
766 typedef typename packet_traits<Scalar>::type Packet;
767 inline Packet packetOp(
const Packet& a)
const {
return internal::psin(a); }
769 template<
typename Scalar>
770 struct functor_traits<scalar_sin_op<Scalar> >
773 Cost = 5 * NumTraits<Scalar>::MulCost,
774 PacketAccess = packet_traits<Scalar>::HasSin
783 template<
typename Scalar>
struct scalar_tan_op {
784 EIGEN_EMPTY_STRUCT_CTOR(scalar_tan_op)
785 inline const Scalar operator() (const Scalar& a)
const {
using std::tan;
return tan(a); }
786 typedef typename packet_traits<Scalar>::type Packet;
787 inline Packet packetOp(
const Packet& a)
const {
return internal::ptan(a); }
789 template<
typename Scalar>
790 struct functor_traits<scalar_tan_op<Scalar> >
793 Cost = 5 * NumTraits<Scalar>::MulCost,
794 PacketAccess = packet_traits<Scalar>::HasTan
802 template<
typename Scalar>
struct scalar_acos_op {
803 EIGEN_EMPTY_STRUCT_CTOR(scalar_acos_op)
804 inline const Scalar operator() (const Scalar& a)
const {
using std::acos;
return acos(a); }
805 typedef typename packet_traits<Scalar>::type Packet;
806 inline Packet packetOp(
const Packet& a)
const {
return internal::pacos(a); }
808 template<
typename Scalar>
809 struct functor_traits<scalar_acos_op<Scalar> >
812 Cost = 5 * NumTraits<Scalar>::MulCost,
813 PacketAccess = packet_traits<Scalar>::HasACos
821 template<
typename Scalar>
struct scalar_asin_op {
822 EIGEN_EMPTY_STRUCT_CTOR(scalar_asin_op)
823 inline const Scalar operator() (const Scalar& a)
const {
using std::asin;
return asin(a); }
824 typedef typename packet_traits<Scalar>::type Packet;
825 inline Packet packetOp(
const Packet& a)
const {
return internal::pasin(a); }
827 template<
typename Scalar>
828 struct functor_traits<scalar_asin_op<Scalar> >
831 Cost = 5 * NumTraits<Scalar>::MulCost,
832 PacketAccess = packet_traits<Scalar>::HasASin
840 template<
typename Scalar>
841 struct scalar_pow_op {
843 inline scalar_pow_op(
const scalar_pow_op& other) : m_exponent(other.m_exponent) { }
844 inline scalar_pow_op(
const Scalar& exponent) : m_exponent(exponent) {}
845 inline Scalar operator() (
const Scalar& a)
const {
return numext::pow(a, m_exponent); }
846 const Scalar m_exponent;
848 template<
typename Scalar>
849 struct functor_traits<scalar_pow_op<Scalar> >
850 {
enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess =
false }; };
856 template<
typename Scalar>
857 struct scalar_inverse_mult_op {
858 scalar_inverse_mult_op(
const Scalar& other) : m_other(other) {}
859 inline Scalar operator() (
const Scalar& a)
const {
return m_other / a; }
860 template<
typename Packet>
861 inline const Packet packetOp(
const Packet& a)
const
862 {
return internal::pdiv(pset1<Packet>(m_other),a); }
870 template<
typename Scalar>
871 struct scalar_inverse_op {
872 EIGEN_EMPTY_STRUCT_CTOR(scalar_inverse_op)
873 inline Scalar operator() (const Scalar& a)
const {
return Scalar(1)/a; }
874 template<
typename Packet>
875 inline const Packet packetOp(
const Packet& a)
const
876 {
return internal::pdiv(pset1<Packet>(Scalar(1)),a); }
878 template<
typename Scalar>
879 struct functor_traits<scalar_inverse_op<Scalar> >
880 {
enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasDiv }; };
886 template<
typename Scalar>
887 struct scalar_square_op {
888 EIGEN_EMPTY_STRUCT_CTOR(scalar_square_op)
889 inline Scalar operator() (const Scalar& a)
const {
return a*a; }
890 template<
typename Packet>
891 inline const Packet packetOp(
const Packet& a)
const
892 {
return internal::pmul(a,a); }
894 template<
typename Scalar>
895 struct functor_traits<scalar_square_op<Scalar> >
896 {
enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
902 template<
typename Scalar>
903 struct scalar_cube_op {
904 EIGEN_EMPTY_STRUCT_CTOR(scalar_cube_op)
905 inline Scalar operator() (const Scalar& a)
const {
return a*a*a; }
906 template<
typename Packet>
907 inline const Packet packetOp(
const Packet& a)
const
908 {
return internal::pmul(a,pmul(a,a)); }
910 template<
typename Scalar>
911 struct functor_traits<scalar_cube_op<Scalar> >
912 {
enum { Cost = 2*NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
917 struct functor_traits<std::multiplies<T> >
918 {
enum { Cost = NumTraits<T>::MulCost, PacketAccess =
false }; };
921 struct functor_traits<std::divides<T> >
922 {
enum { Cost = NumTraits<T>::MulCost, PacketAccess =
false }; };
925 struct functor_traits<std::plus<T> >
926 {
enum { Cost = NumTraits<T>::AddCost, PacketAccess =
false }; };
929 struct functor_traits<std::minus<T> >
930 {
enum { Cost = NumTraits<T>::AddCost, PacketAccess =
false }; };
933 struct functor_traits<std::negate<T> >
934 {
enum { Cost = NumTraits<T>::AddCost, PacketAccess =
false }; };
937 struct functor_traits<std::logical_or<T> >
938 {
enum { Cost = 1, PacketAccess =
false }; };
941 struct functor_traits<std::logical_and<T> >
942 {
enum { Cost = 1, PacketAccess =
false }; };
945 struct functor_traits<std::logical_not<T> >
946 {
enum { Cost = 1, PacketAccess =
false }; };
949 struct functor_traits<std::greater<T> >
950 {
enum { Cost = 1, PacketAccess =
false }; };
953 struct functor_traits<std::less<T> >
954 {
enum { Cost = 1, PacketAccess =
false }; };
957 struct functor_traits<std::greater_equal<T> >
958 {
enum { Cost = 1, PacketAccess =
false }; };
961 struct functor_traits<std::less_equal<T> >
962 {
enum { Cost = 1, PacketAccess =
false }; };
965 struct functor_traits<std::equal_to<T> >
966 {
enum { Cost = 1, PacketAccess =
false }; };
969 struct functor_traits<std::not_equal_to<T> >
970 {
enum { Cost = 1, PacketAccess =
false }; };
973 struct functor_traits<std::binder2nd<T> >
974 {
enum { Cost = functor_traits<T>::Cost, PacketAccess =
false }; };
977 struct functor_traits<std::binder1st<T> >
978 {
enum { Cost = functor_traits<T>::Cost, PacketAccess =
false }; };
981 struct functor_traits<std::unary_negate<T> >
982 {
enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess =
false }; };
985 struct functor_traits<std::binary_negate<T> >
986 {
enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess =
false }; };
988 #ifdef EIGEN_STDEXT_SUPPORT
990 template<
typename T0,
typename T1>
991 struct functor_traits<std::project1st<T0,T1> >
992 {
enum { Cost = 0, PacketAccess =
false }; };
994 template<
typename T0,
typename T1>
995 struct functor_traits<std::project2nd<T0,T1> >
996 {
enum { Cost = 0, PacketAccess =
false }; };
998 template<
typename T0,
typename T1>
999 struct functor_traits<std::select2nd<std::pair<T0,T1> > >
1000 {
enum { Cost = 0, PacketAccess =
false }; };
1002 template<
typename T0,
typename T1>
1003 struct functor_traits<std::select1st<std::pair<T0,T1> > >
1004 {
enum { Cost = 0, PacketAccess =
false }; };
1006 template<
typename T0,
typename T1>
1007 struct functor_traits<std::unary_compose<T0,T1> >
1008 {
enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost, PacketAccess =
false }; };
1010 template<
typename T0,
typename T1,
typename T2>
1011 struct functor_traits<std::binary_compose<T0,T1,T2> >
1012 {
enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost + functor_traits<T2>::Cost, PacketAccess =
false }; };
1014 #endif // EIGEN_STDEXT_SUPPORT
1018 #ifdef EIGEN_FUNCTORS_PLUGIN
1019 #include EIGEN_FUNCTORS_PLUGIN
1026 #endif // EIGEN_FUNCTORS_H