00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_FUNCTORS_H
00026 #define EIGEN_FUNCTORS_H
00027
00028 namespace internal {
00029
00030
00031
00037 template<typename Scalar> struct scalar_sum_op {
00038 EIGEN_EMPTY_STRUCT_CTOR(scalar_sum_op)
00039 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const { return a + b; }
00040 template<typename Packet>
00041 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
00042 { return internal::padd(a,b); }
00043 template<typename Packet>
00044 EIGEN_STRONG_INLINE const Scalar predux(const Packet& a) const
00045 { return internal::predux(a); }
00046 };
00047 template<typename Scalar>
00048 struct functor_traits<scalar_sum_op<Scalar> > {
00049 enum {
00050 Cost = NumTraits<Scalar>::AddCost,
00051 PacketAccess = packet_traits<Scalar>::HasAdd
00052 };
00053 };
00054
00060 template<typename LhsScalar,typename RhsScalar> struct scalar_product_op {
00061 enum {
00062
00063 Vectorizable = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasMul && packet_traits<RhsScalar>::HasMul
00064 };
00065 typedef typename scalar_product_traits<LhsScalar,RhsScalar>::ReturnType result_type;
00066 EIGEN_EMPTY_STRUCT_CTOR(scalar_product_op)
00067 EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a * b; }
00068 template<typename Packet>
00069 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
00070 { return internal::pmul(a,b); }
00071 template<typename Packet>
00072 EIGEN_STRONG_INLINE const result_type predux(const Packet& a) const
00073 { return internal::predux_mul(a); }
00074 };
00075 template<typename LhsScalar,typename RhsScalar>
00076 struct functor_traits<scalar_product_op<LhsScalar,RhsScalar> > {
00077 enum {
00078 Cost = (NumTraits<LhsScalar>::MulCost + NumTraits<RhsScalar>::MulCost)/2,
00079 PacketAccess = scalar_product_op<LhsScalar,RhsScalar>::Vectorizable
00080 };
00081 };
00082
00088 template<typename LhsScalar,typename RhsScalar> struct scalar_conj_product_op {
00089
00090 enum {
00091 Conj = NumTraits<LhsScalar>::IsComplex
00092 };
00093
00094 typedef typename scalar_product_traits<LhsScalar,RhsScalar>::ReturnType result_type;
00095
00096 EIGEN_EMPTY_STRUCT_CTOR(scalar_conj_product_op)
00097 EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const
00098 { return conj_helper<LhsScalar,RhsScalar,Conj,false>().pmul(a,b); }
00099
00100 template<typename Packet>
00101 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
00102 { return conj_helper<Packet,Packet,Conj,false>().pmul(a,b); }
00103 };
00104 template<typename LhsScalar,typename RhsScalar>
00105 struct functor_traits<scalar_conj_product_op<LhsScalar,RhsScalar> > {
00106 enum {
00107 Cost = NumTraits<LhsScalar>::MulCost,
00108 PacketAccess = internal::is_same<LhsScalar, RhsScalar>::value && packet_traits<LhsScalar>::HasMul
00109 };
00110 };
00111
00117 template<typename Scalar> struct scalar_min_op {
00118 EIGEN_EMPTY_STRUCT_CTOR(scalar_min_op)
00119 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const { return std::min(a, b); }
00120 template<typename Packet>
00121 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
00122 { return internal::pmin(a,b); }
00123 template<typename Packet>
00124 EIGEN_STRONG_INLINE const Scalar predux(const Packet& a) const
00125 { return internal::predux_min(a); }
00126 };
00127 template<typename Scalar>
00128 struct functor_traits<scalar_min_op<Scalar> > {
00129 enum {
00130 Cost = NumTraits<Scalar>::AddCost,
00131 PacketAccess = packet_traits<Scalar>::HasMin
00132 };
00133 };
00134
00140 template<typename Scalar> struct scalar_max_op {
00141 EIGEN_EMPTY_STRUCT_CTOR(scalar_max_op)
00142 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const { return std::max(a, b); }
00143 template<typename Packet>
00144 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
00145 { return internal::pmax(a,b); }
00146 template<typename Packet>
00147 EIGEN_STRONG_INLINE const Scalar predux(const Packet& a) const
00148 { return internal::predux_max(a); }
00149 };
00150 template<typename Scalar>
00151 struct functor_traits<scalar_max_op<Scalar> > {
00152 enum {
00153 Cost = NumTraits<Scalar>::AddCost,
00154 PacketAccess = packet_traits<Scalar>::HasMax
00155 };
00156 };
00157
00163 template<typename Scalar> struct scalar_hypot_op {
00164 EIGEN_EMPTY_STRUCT_CTOR(scalar_hypot_op)
00165
00166 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& _x, const Scalar& _y) const
00167 {
00168 Scalar p = std::max(_x, _y);
00169 Scalar q = std::min(_x, _y);
00170 Scalar qp = q/p;
00171 return p * sqrt(Scalar(1) + qp*qp);
00172 }
00173 };
00174 template<typename Scalar>
00175 struct functor_traits<scalar_hypot_op<Scalar> > {
00176 enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess=0 };
00177 };
00178
00179
00180
00186 template<typename Scalar> struct scalar_difference_op {
00187 EIGEN_EMPTY_STRUCT_CTOR(scalar_difference_op)
00188 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const { return a - b; }
00189 template<typename Packet>
00190 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
00191 { return internal::psub(a,b); }
00192 };
00193 template<typename Scalar>
00194 struct functor_traits<scalar_difference_op<Scalar> > {
00195 enum {
00196 Cost = NumTraits<Scalar>::AddCost,
00197 PacketAccess = packet_traits<Scalar>::HasSub
00198 };
00199 };
00200
00206 template<typename Scalar> struct scalar_quotient_op {
00207 EIGEN_EMPTY_STRUCT_CTOR(scalar_quotient_op)
00208 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& b) const { return a / b; }
00209 template<typename Packet>
00210 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
00211 { return internal::pdiv(a,b); }
00212 };
00213 template<typename Scalar>
00214 struct functor_traits<scalar_quotient_op<Scalar> > {
00215 enum {
00216 Cost = 2 * NumTraits<Scalar>::MulCost,
00217 PacketAccess = packet_traits<Scalar>::HasDiv
00218 };
00219 };
00220
00221
00222
00228 template<typename Scalar> struct scalar_opposite_op {
00229 EIGEN_EMPTY_STRUCT_CTOR(scalar_opposite_op)
00230 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return -a; }
00231 template<typename Packet>
00232 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
00233 { return internal::pnegate(a); }
00234 };
00235 template<typename Scalar>
00236 struct functor_traits<scalar_opposite_op<Scalar> >
00237 { enum {
00238 Cost = NumTraits<Scalar>::AddCost,
00239 PacketAccess = packet_traits<Scalar>::HasNegate };
00240 };
00241
00247 template<typename Scalar> struct scalar_abs_op {
00248 EIGEN_EMPTY_STRUCT_CTOR(scalar_abs_op)
00249 typedef typename NumTraits<Scalar>::Real result_type;
00250 EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return abs(a); }
00251 template<typename Packet>
00252 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
00253 { return internal::pabs(a); }
00254 };
00255 template<typename Scalar>
00256 struct functor_traits<scalar_abs_op<Scalar> >
00257 {
00258 enum {
00259 Cost = NumTraits<Scalar>::AddCost,
00260 PacketAccess = packet_traits<Scalar>::HasAbs
00261 };
00262 };
00263
00269 template<typename Scalar> struct scalar_abs2_op {
00270 EIGEN_EMPTY_STRUCT_CTOR(scalar_abs2_op)
00271 typedef typename NumTraits<Scalar>::Real result_type;
00272 EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return abs2(a); }
00273 template<typename Packet>
00274 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
00275 { return internal::pmul(a,a); }
00276 };
00277 template<typename Scalar>
00278 struct functor_traits<scalar_abs2_op<Scalar> >
00279 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasAbs2 }; };
00280
00286 template<typename Scalar> struct scalar_conjugate_op {
00287 EIGEN_EMPTY_STRUCT_CTOR(scalar_conjugate_op)
00288 EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return conj(a); }
00289 template<typename Packet>
00290 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const { return internal::pconj(a); }
00291 };
00292 template<typename Scalar>
00293 struct functor_traits<scalar_conjugate_op<Scalar> >
00294 {
00295 enum {
00296 Cost = NumTraits<Scalar>::IsComplex ? NumTraits<Scalar>::AddCost : 0,
00297 PacketAccess = packet_traits<Scalar>::HasConj
00298 };
00299 };
00300
00306 template<typename Scalar, typename NewType>
00307 struct scalar_cast_op {
00308 EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op)
00309 typedef NewType result_type;
00310 EIGEN_STRONG_INLINE const NewType operator() (const Scalar& a) const { return cast<Scalar, NewType>(a); }
00311 };
00312 template<typename Scalar, typename NewType>
00313 struct functor_traits<scalar_cast_op<Scalar,NewType> >
00314 { enum { Cost = is_same<Scalar, NewType>::value ? 0 : NumTraits<NewType>::AddCost, PacketAccess = false }; };
00315
00321 template<typename Scalar>
00322 struct scalar_real_op {
00323 EIGEN_EMPTY_STRUCT_CTOR(scalar_real_op)
00324 typedef typename NumTraits<Scalar>::Real result_type;
00325 EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return real(a); }
00326 };
00327 template<typename Scalar>
00328 struct functor_traits<scalar_real_op<Scalar> >
00329 { enum { Cost = 0, PacketAccess = false }; };
00330
00336 template<typename Scalar>
00337 struct scalar_imag_op {
00338 EIGEN_EMPTY_STRUCT_CTOR(scalar_imag_op)
00339 typedef typename NumTraits<Scalar>::Real result_type;
00340 EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return imag(a); }
00341 };
00342 template<typename Scalar>
00343 struct functor_traits<scalar_imag_op<Scalar> >
00344 { enum { Cost = 0, PacketAccess = false }; };
00345
00351 template<typename Scalar>
00352 struct scalar_real_ref_op {
00353 EIGEN_EMPTY_STRUCT_CTOR(scalar_real_ref_op)
00354 typedef typename NumTraits<Scalar>::Real result_type;
00355 EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return real_ref(*const_cast<Scalar*>(&a)); }
00356 };
00357 template<typename Scalar>
00358 struct functor_traits<scalar_real_ref_op<Scalar> >
00359 { enum { Cost = 0, PacketAccess = false }; };
00360
00366 template<typename Scalar>
00367 struct scalar_imag_ref_op {
00368 EIGEN_EMPTY_STRUCT_CTOR(scalar_imag_ref_op)
00369 typedef typename NumTraits<Scalar>::Real result_type;
00370 EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return imag_ref(*const_cast<Scalar*>(&a)); }
00371 };
00372 template<typename Scalar>
00373 struct functor_traits<scalar_imag_ref_op<Scalar> >
00374 { enum { Cost = 0, PacketAccess = false }; };
00375
00382 template<typename Scalar> struct scalar_exp_op {
00383 EIGEN_EMPTY_STRUCT_CTOR(scalar_exp_op)
00384 inline const Scalar operator() (const Scalar& a) const { return exp(a); }
00385 typedef typename packet_traits<Scalar>::type Packet;
00386 inline Packet packetOp(const Packet& a) const { return internal::pexp(a); }
00387 };
00388 template<typename Scalar>
00389 struct functor_traits<scalar_exp_op<Scalar> >
00390 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasExp }; };
00391
00398 template<typename Scalar> struct scalar_log_op {
00399 EIGEN_EMPTY_STRUCT_CTOR(scalar_log_op)
00400 inline const Scalar operator() (const Scalar& a) const { return log(a); }
00401 typedef typename packet_traits<Scalar>::type Packet;
00402 inline Packet packetOp(const Packet& a) const { return internal::plog(a); }
00403 };
00404 template<typename Scalar>
00405 struct functor_traits<scalar_log_op<Scalar> >
00406 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasLog }; };
00407
00413
00414
00415
00416
00417
00418
00419
00420
00421 template<typename Scalar>
00422 struct scalar_multiple_op {
00423 typedef typename packet_traits<Scalar>::type Packet;
00424
00425 EIGEN_STRONG_INLINE scalar_multiple_op(const scalar_multiple_op& other) : m_other(other.m_other) { }
00426 EIGEN_STRONG_INLINE scalar_multiple_op(const Scalar& other) : m_other(other) { }
00427 EIGEN_STRONG_INLINE Scalar operator() (const Scalar& a) const { return a * m_other; }
00428 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
00429 { return internal::pmul(a, pset1<Packet>(m_other)); }
00430 typename add_const_on_value_type<typename NumTraits<Scalar>::Nested>::type m_other;
00431 };
00432 template<typename Scalar>
00433 struct functor_traits<scalar_multiple_op<Scalar> >
00434 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
00435
00436 template<typename Scalar1, typename Scalar2>
00437 struct scalar_multiple2_op {
00438 typedef typename scalar_product_traits<Scalar1,Scalar2>::ReturnType result_type;
00439 EIGEN_STRONG_INLINE scalar_multiple2_op(const scalar_multiple2_op& other) : m_other(other.m_other) { }
00440 EIGEN_STRONG_INLINE scalar_multiple2_op(const Scalar2& other) : m_other(other) { }
00441 EIGEN_STRONG_INLINE result_type operator() (const Scalar1& a) const { return a * m_other; }
00442 typename add_const_on_value_type<typename NumTraits<Scalar2>::Nested>::type m_other;
00443 };
00444 template<typename Scalar1,typename Scalar2>
00445 struct functor_traits<scalar_multiple2_op<Scalar1,Scalar2> >
00446 { enum { Cost = NumTraits<Scalar1>::MulCost, PacketAccess = false }; };
00447
00448 template<typename Scalar, bool IsInteger>
00449 struct scalar_quotient1_impl {
00450 typedef typename packet_traits<Scalar>::type Packet;
00451
00452 EIGEN_STRONG_INLINE scalar_quotient1_impl(const scalar_quotient1_impl& other) : m_other(other.m_other) { }
00453 EIGEN_STRONG_INLINE scalar_quotient1_impl(const Scalar& other) : m_other(static_cast<Scalar>(1) / other) {}
00454 EIGEN_STRONG_INLINE Scalar operator() (const Scalar& a) const { return a * m_other; }
00455 EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const
00456 { return internal::pmul(a, pset1<Packet>(m_other)); }
00457 const Scalar m_other;
00458 };
00459 template<typename Scalar>
00460 struct functor_traits<scalar_quotient1_impl<Scalar,false> >
00461 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
00462
00463 template<typename Scalar>
00464 struct scalar_quotient1_impl<Scalar,true> {
00465
00466 EIGEN_STRONG_INLINE scalar_quotient1_impl(const scalar_quotient1_impl& other) : m_other(other.m_other) { }
00467 EIGEN_STRONG_INLINE scalar_quotient1_impl(const Scalar& other) : m_other(other) {}
00468 EIGEN_STRONG_INLINE Scalar operator() (const Scalar& a) const { return a / m_other; }
00469 typename add_const_on_value_type<typename NumTraits<Scalar>::Nested>::type m_other;
00470 };
00471 template<typename Scalar>
00472 struct functor_traits<scalar_quotient1_impl<Scalar,true> >
00473 { enum { Cost = 2 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };
00474
00483 template<typename Scalar>
00484 struct scalar_quotient1_op : scalar_quotient1_impl<Scalar, NumTraits<Scalar>::IsInteger > {
00485 EIGEN_STRONG_INLINE scalar_quotient1_op(const Scalar& other)
00486 : scalar_quotient1_impl<Scalar, NumTraits<Scalar>::IsInteger >(other) {}
00487 };
00488 template<typename Scalar>
00489 struct functor_traits<scalar_quotient1_op<Scalar> >
00490 : functor_traits<scalar_quotient1_impl<Scalar, NumTraits<Scalar>::IsInteger> >
00491 {};
00492
00493
00494
00495 template<typename Scalar>
00496 struct scalar_constant_op {
00497 typedef typename packet_traits<Scalar>::type Packet;
00498 EIGEN_STRONG_INLINE scalar_constant_op(const scalar_constant_op& other) : m_other(other.m_other) { }
00499 EIGEN_STRONG_INLINE scalar_constant_op(const Scalar& other) : m_other(other) { }
00500 template<typename Index>
00501 EIGEN_STRONG_INLINE const Scalar operator() (Index, Index = 0) const { return m_other; }
00502 template<typename Index>
00503 EIGEN_STRONG_INLINE const Packet packetOp(Index, Index = 0) const { return internal::pset1<Packet>(m_other); }
00504 const Scalar m_other;
00505 };
00506 template<typename Scalar>
00507 struct functor_traits<scalar_constant_op<Scalar> >
00508
00509 { enum { Cost = 1, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = true }; };
00510
00511 template<typename Scalar> struct scalar_identity_op {
00512 EIGEN_EMPTY_STRUCT_CTOR(scalar_identity_op)
00513 template<typename Index>
00514 EIGEN_STRONG_INLINE const Scalar operator() (Index row, Index col) const { return row==col ? Scalar(1) : Scalar(0); }
00515 };
00516 template<typename Scalar>
00517 struct functor_traits<scalar_identity_op<Scalar> >
00518 { enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = false, IsRepeatable = true }; };
00519
00520 template <typename Scalar, bool RandomAccess> struct linspaced_op_impl;
00521
00522
00523
00524
00525
00526
00527 template <typename Scalar>
00528 struct linspaced_op_impl<Scalar,false>
00529 {
00530 typedef typename packet_traits<Scalar>::type Packet;
00531
00532 linspaced_op_impl(Scalar low, Scalar step) :
00533 m_low(low), m_step(step),
00534 m_packetStep(pset1<Packet>(packet_traits<Scalar>::size*step)),
00535 m_base(padd(pset1<Packet>(low),pmul(pset1<Packet>(step),plset<Scalar>(-packet_traits<Scalar>::size)))) {}
00536
00537 template<typename Index>
00538 EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return m_low+i*m_step; }
00539 template<typename Index>
00540 EIGEN_STRONG_INLINE const Packet packetOp(Index) const { return m_base = padd(m_base,m_packetStep); }
00541
00542 const Scalar m_low;
00543 const Scalar m_step;
00544 const Packet m_packetStep;
00545 mutable Packet m_base;
00546 };
00547
00548
00549
00550
00551 template <typename Scalar>
00552 struct linspaced_op_impl<Scalar,true>
00553 {
00554 typedef typename packet_traits<Scalar>::type Packet;
00555
00556 linspaced_op_impl(Scalar low, Scalar step) :
00557 m_low(low), m_step(step),
00558 m_lowPacket(pset1<Packet>(m_low)), m_stepPacket(pset1<Packet>(m_step)), m_interPacket(plset<Scalar>(0)) {}
00559
00560 template<typename Index>
00561 EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return m_low+i*m_step; }
00562
00563 template<typename Index>
00564 EIGEN_STRONG_INLINE const Packet packetOp(Index i) const
00565 { return internal::padd(m_lowPacket, pmul(m_stepPacket, padd(pset1<Packet>(i),m_interPacket))); }
00566
00567 const Scalar m_low;
00568 const Scalar m_step;
00569 const Packet m_lowPacket;
00570 const Packet m_stepPacket;
00571 const Packet m_interPacket;
00572 };
00573
00574
00575
00576
00577
00578
00579 template <typename Scalar, bool RandomAccess = true> struct linspaced_op;
00580 template <typename Scalar, bool RandomAccess> struct functor_traits< linspaced_op<Scalar,RandomAccess> >
00581 { enum { Cost = 1, PacketAccess = packet_traits<Scalar>::HasSetLinear, IsRepeatable = true }; };
00582 template <typename Scalar, bool RandomAccess> struct linspaced_op
00583 {
00584 typedef typename packet_traits<Scalar>::type Packet;
00585 linspaced_op(Scalar low, Scalar high, int num_steps) : impl(low, (high-low)/(num_steps-1)) {}
00586
00587 template<typename Index>
00588 EIGEN_STRONG_INLINE const Scalar operator() (Index i) const { return impl(i); }
00589
00590
00591
00592 template<typename Index>
00593 EIGEN_STRONG_INLINE const Scalar operator() (Index row, Index col) const
00594 {
00595 eigen_assert(col==0 || row==0);
00596 return impl(col + row);
00597 }
00598
00599 template<typename Index>
00600 EIGEN_STRONG_INLINE const Packet packetOp(Index i) const { return impl.packetOp(i); }
00601
00602
00603
00604 template<typename Index>
00605 EIGEN_STRONG_INLINE const Packet packetOp(Index row, Index col) const
00606 {
00607 eigen_assert(col==0 || row==0);
00608 return impl(col + row);
00609 }
00610
00611
00612
00613
00614 const linspaced_op_impl<Scalar,RandomAccess> impl;
00615 };
00616
00617
00618
00619
00620
00621 template<typename Functor> struct functor_has_linear_access { enum { ret = 1 }; };
00622 template<typename Scalar> struct functor_has_linear_access<scalar_identity_op<Scalar> > { enum { ret = 0 }; };
00623
00624
00625
00626
00627 template<typename Functor> struct functor_allows_mixing_real_and_complex { enum { ret = 0 }; };
00628 template<typename LhsScalar,typename RhsScalar> struct functor_allows_mixing_real_and_complex<scalar_product_op<LhsScalar,RhsScalar> > { enum { ret = 1 }; };
00629 template<typename LhsScalar,typename RhsScalar> struct functor_allows_mixing_real_and_complex<scalar_conj_product_op<LhsScalar,RhsScalar> > { enum { ret = 1 }; };
00630
00631
00636
00637 template<typename Scalar>
00638 struct scalar_add_op {
00639 typedef typename packet_traits<Scalar>::type Packet;
00640
00641 inline scalar_add_op(const scalar_add_op& other) : m_other(other.m_other) { }
00642 inline scalar_add_op(const Scalar& other) : m_other(other) { }
00643 inline Scalar operator() (const Scalar& a) const { return a + m_other; }
00644 inline const Packet packetOp(const Packet& a) const
00645 { return internal::padd(a, pset1<Packet>(m_other)); }
00646 const Scalar m_other;
00647 };
00648 template<typename Scalar>
00649 struct functor_traits<scalar_add_op<Scalar> >
00650 { enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = packet_traits<Scalar>::HasAdd }; };
00651
00656 template<typename Scalar> struct scalar_sqrt_op {
00657 EIGEN_EMPTY_STRUCT_CTOR(scalar_sqrt_op)
00658 inline const Scalar operator() (const Scalar& a) const { return sqrt(a); }
00659 typedef typename packet_traits<Scalar>::type Packet;
00660 inline Packet packetOp(const Packet& a) const { return internal::psqrt(a); }
00661 };
00662 template<typename Scalar>
00663 struct functor_traits<scalar_sqrt_op<Scalar> >
00664 { enum {
00665 Cost = 5 * NumTraits<Scalar>::MulCost,
00666 PacketAccess = packet_traits<Scalar>::HasSqrt
00667 };
00668 };
00669
00674 template<typename Scalar> struct scalar_cos_op {
00675 EIGEN_EMPTY_STRUCT_CTOR(scalar_cos_op)
00676 inline Scalar operator() (const Scalar& a) const { return cos(a); }
00677 typedef typename packet_traits<Scalar>::type Packet;
00678 inline Packet packetOp(const Packet& a) const { return internal::pcos(a); }
00679 };
00680 template<typename Scalar>
00681 struct functor_traits<scalar_cos_op<Scalar> >
00682 {
00683 enum {
00684 Cost = 5 * NumTraits<Scalar>::MulCost,
00685 PacketAccess = packet_traits<Scalar>::HasCos
00686 };
00687 };
00688
00693 template<typename Scalar> struct scalar_sin_op {
00694 EIGEN_EMPTY_STRUCT_CTOR(scalar_sin_op)
00695 inline const Scalar operator() (const Scalar& a) const { return sin(a); }
00696 typedef typename packet_traits<Scalar>::type Packet;
00697 inline Packet packetOp(const Packet& a) const { return internal::psin(a); }
00698 };
00699 template<typename Scalar>
00700 struct functor_traits<scalar_sin_op<Scalar> >
00701 {
00702 enum {
00703 Cost = 5 * NumTraits<Scalar>::MulCost,
00704 PacketAccess = packet_traits<Scalar>::HasSin
00705 };
00706 };
00707
00708
00713 template<typename Scalar> struct scalar_tan_op {
00714 EIGEN_EMPTY_STRUCT_CTOR(scalar_tan_op)
00715 inline const Scalar operator() (const Scalar& a) const { return tan(a); }
00716 typedef typename packet_traits<Scalar>::type Packet;
00717 inline Packet packetOp(const Packet& a) const { return internal::ptan(a); }
00718 };
00719 template<typename Scalar>
00720 struct functor_traits<scalar_tan_op<Scalar> >
00721 {
00722 enum {
00723 Cost = 5 * NumTraits<Scalar>::MulCost,
00724 PacketAccess = packet_traits<Scalar>::HasTan
00725 };
00726 };
00727
00732 template<typename Scalar> struct scalar_acos_op {
00733 EIGEN_EMPTY_STRUCT_CTOR(scalar_acos_op)
00734 inline const Scalar operator() (const Scalar& a) const { return acos(a); }
00735 typedef typename packet_traits<Scalar>::type Packet;
00736 inline Packet packetOp(const Packet& a) const { return internal::pacos(a); }
00737 };
00738 template<typename Scalar>
00739 struct functor_traits<scalar_acos_op<Scalar> >
00740 {
00741 enum {
00742 Cost = 5 * NumTraits<Scalar>::MulCost,
00743 PacketAccess = packet_traits<Scalar>::HasACos
00744 };
00745 };
00746
00751 template<typename Scalar> struct scalar_asin_op {
00752 EIGEN_EMPTY_STRUCT_CTOR(scalar_asin_op)
00753 inline const Scalar operator() (const Scalar& a) const { return acos(a); }
00754 typedef typename packet_traits<Scalar>::type Packet;
00755 inline Packet packetOp(const Packet& a) const { return internal::pacos(a); }
00756 };
00757 template<typename Scalar>
00758 struct functor_traits<scalar_asin_op<Scalar> >
00759 {
00760 enum {
00761 Cost = 5 * NumTraits<Scalar>::MulCost,
00762 PacketAccess = packet_traits<Scalar>::HasASin
00763 };
00764 };
00765
00770 template<typename Scalar>
00771 struct scalar_pow_op {
00772
00773 inline scalar_pow_op(const scalar_pow_op& other) : m_exponent(other.m_exponent) { }
00774 inline scalar_pow_op(const Scalar& exponent) : m_exponent(exponent) {}
00775 inline Scalar operator() (const Scalar& a) const { return internal::pow(a, m_exponent); }
00776 const Scalar m_exponent;
00777 };
00778 template<typename Scalar>
00779 struct functor_traits<scalar_pow_op<Scalar> >
00780 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };
00781
00786 template<typename Scalar>
00787 struct scalar_inverse_op {
00788 EIGEN_EMPTY_STRUCT_CTOR(scalar_inverse_op)
00789 inline Scalar operator() (const Scalar& a) const { return Scalar(1)/a; }
00790 template<typename Packet>
00791 inline const Packet packetOp(const Packet& a) const
00792 { return internal::pdiv(pset1<Packet>(Scalar(1)),a); }
00793 };
00794 template<typename Scalar>
00795 struct functor_traits<scalar_inverse_op<Scalar> >
00796 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasDiv }; };
00797
00802 template<typename Scalar>
00803 struct scalar_square_op {
00804 EIGEN_EMPTY_STRUCT_CTOR(scalar_square_op)
00805 inline Scalar operator() (const Scalar& a) const { return a*a; }
00806 template<typename Packet>
00807 inline const Packet packetOp(const Packet& a) const
00808 { return internal::pmul(a,a); }
00809 };
00810 template<typename Scalar>
00811 struct functor_traits<scalar_square_op<Scalar> >
00812 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
00813
00818 template<typename Scalar>
00819 struct scalar_cube_op {
00820 EIGEN_EMPTY_STRUCT_CTOR(scalar_cube_op)
00821 inline Scalar operator() (const Scalar& a) const { return a*a*a; }
00822 template<typename Packet>
00823 inline const Packet packetOp(const Packet& a) const
00824 { return internal::pmul(a,pmul(a,a)); }
00825 };
00826 template<typename Scalar>
00827 struct functor_traits<scalar_cube_op<Scalar> >
00828 { enum { Cost = 2*NumTraits<Scalar>::MulCost, PacketAccess = packet_traits<Scalar>::HasMul }; };
00829
00830
00831
00832 template<typename T>
00833 struct functor_traits<std::multiplies<T> >
00834 { enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
00835
00836 template<typename T>
00837 struct functor_traits<std::divides<T> >
00838 { enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
00839
00840 template<typename T>
00841 struct functor_traits<std::plus<T> >
00842 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
00843
00844 template<typename T>
00845 struct functor_traits<std::minus<T> >
00846 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
00847
00848 template<typename T>
00849 struct functor_traits<std::negate<T> >
00850 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
00851
00852 template<typename T>
00853 struct functor_traits<std::logical_or<T> >
00854 { enum { Cost = 1, PacketAccess = false }; };
00855
00856 template<typename T>
00857 struct functor_traits<std::logical_and<T> >
00858 { enum { Cost = 1, PacketAccess = false }; };
00859
00860 template<typename T>
00861 struct functor_traits<std::logical_not<T> >
00862 { enum { Cost = 1, PacketAccess = false }; };
00863
00864 template<typename T>
00865 struct functor_traits<std::greater<T> >
00866 { enum { Cost = 1, PacketAccess = false }; };
00867
00868 template<typename T>
00869 struct functor_traits<std::less<T> >
00870 { enum { Cost = 1, PacketAccess = false }; };
00871
00872 template<typename T>
00873 struct functor_traits<std::greater_equal<T> >
00874 { enum { Cost = 1, PacketAccess = false }; };
00875
00876 template<typename T>
00877 struct functor_traits<std::less_equal<T> >
00878 { enum { Cost = 1, PacketAccess = false }; };
00879
00880 template<typename T>
00881 struct functor_traits<std::equal_to<T> >
00882 { enum { Cost = 1, PacketAccess = false }; };
00883
00884 template<typename T>
00885 struct functor_traits<std::not_equal_to<T> >
00886 { enum { Cost = 1, PacketAccess = false }; };
00887
00888 template<typename T>
00889 struct functor_traits<std::binder2nd<T> >
00890 { enum { Cost = functor_traits<T>::Cost, PacketAccess = false }; };
00891
00892 template<typename T>
00893 struct functor_traits<std::binder1st<T> >
00894 { enum { Cost = functor_traits<T>::Cost, PacketAccess = false }; };
00895
00896 template<typename T>
00897 struct functor_traits<std::unary_negate<T> >
00898 { enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; };
00899
00900 template<typename T>
00901 struct functor_traits<std::binary_negate<T> >
00902 { enum { Cost = 1 + functor_traits<T>::Cost, PacketAccess = false }; };
00903
00904 #ifdef EIGEN_STDEXT_SUPPORT
00905
00906 template<typename T0,typename T1>
00907 struct functor_traits<std::project1st<T0,T1> >
00908 { enum { Cost = 0, PacketAccess = false }; };
00909
00910 template<typename T0,typename T1>
00911 struct functor_traits<std::project2nd<T0,T1> >
00912 { enum { Cost = 0, PacketAccess = false }; };
00913
00914 template<typename T0,typename T1>
00915 struct functor_traits<std::select2nd<std::pair<T0,T1> > >
00916 { enum { Cost = 0, PacketAccess = false }; };
00917
00918 template<typename T0,typename T1>
00919 struct functor_traits<std::select1st<std::pair<T0,T1> > >
00920 { enum { Cost = 0, PacketAccess = false }; };
00921
00922 template<typename T0,typename T1>
00923 struct functor_traits<std::unary_compose<T0,T1> >
00924 { enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost, PacketAccess = false }; };
00925
00926 template<typename T0,typename T1,typename T2>
00927 struct functor_traits<std::binary_compose<T0,T1,T2> >
00928 { enum { Cost = functor_traits<T0>::Cost + functor_traits<T1>::Cost + functor_traits<T2>::Cost, PacketAccess = false }; };
00929
00930 #endif // EIGEN_STDEXT_SUPPORT
00931
00932
00933
00934 #ifdef EIGEN_FUNCTORS_PLUGIN
00935 #include EIGEN_FUNCTORS_PLUGIN
00936 #endif
00937
00938 }
00939
00940 #endif // EIGEN_FUNCTORS_H