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_ARRAY_FUNCTORS_H
00026 #define EIGEN_ARRAY_FUNCTORS_H
00027
00035
00036 template<typename Scalar>
00037 struct ei_scalar_add_op {
00038 typedef typename ei_packet_traits<Scalar>::type PacketScalar;
00039
00040 inline ei_scalar_add_op(const ei_scalar_add_op& other) : m_other(other.m_other) { }
00041 inline ei_scalar_add_op(const Scalar& other) : m_other(other) { }
00042 inline Scalar operator() (const Scalar& a) const { return a + m_other; }
00043 inline const PacketScalar packetOp(const PacketScalar& a) const
00044 { return ei_padd(a, ei_pset1(m_other)); }
00045 const Scalar m_other;
00046 private:
00047 ei_scalar_add_op& operator=(const ei_scalar_add_op&);
00048 };
00049 template<typename Scalar>
00050 struct ei_functor_traits<ei_scalar_add_op<Scalar> >
00051 { enum { Cost = NumTraits<Scalar>::AddCost, PacketAccess = ei_packet_traits<Scalar>::size>1 }; };
00052
00061 template<typename Scalar> struct ei_scalar_sqrt_op EIGEN_EMPTY_STRUCT {
00062 inline const Scalar operator() (const Scalar& a) const { return ei_sqrt(a); }
00063 };
00064 template<typename Scalar>
00065 struct ei_functor_traits<ei_scalar_sqrt_op<Scalar> >
00066 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };
00067
00076 template<typename Scalar> struct ei_scalar_exp_op EIGEN_EMPTY_STRUCT {
00077 inline const Scalar operator() (const Scalar& a) const { return ei_exp(a); }
00078 };
00079 template<typename Scalar>
00080 struct ei_functor_traits<ei_scalar_exp_op<Scalar> >
00081 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };
00082
00091 template<typename Scalar> struct ei_scalar_log_op EIGEN_EMPTY_STRUCT {
00092 inline const Scalar operator() (const Scalar& a) const { return ei_log(a); }
00093 };
00094 template<typename Scalar>
00095 struct ei_functor_traits<ei_scalar_log_op<Scalar> >
00096 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };
00097
00106 template<typename Scalar> struct ei_scalar_cos_op EIGEN_EMPTY_STRUCT {
00107 inline const Scalar operator() (const Scalar& a) const { return ei_cos(a); }
00108 };
00109 template<typename Scalar>
00110 struct ei_functor_traits<ei_scalar_cos_op<Scalar> >
00111 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };
00112
00121 template<typename Scalar> struct ei_scalar_sin_op EIGEN_EMPTY_STRUCT {
00122 inline const Scalar operator() (const Scalar& a) const { return ei_sin(a); }
00123 };
00124 template<typename Scalar>
00125 struct ei_functor_traits<ei_scalar_sin_op<Scalar> >
00126 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };
00127
00136 template<typename Scalar>
00137 struct ei_scalar_pow_op {
00138
00139 inline ei_scalar_pow_op(const ei_scalar_pow_op& other) : m_exponent(other.m_exponent) { }
00140 inline ei_scalar_pow_op(const Scalar& exponent) : m_exponent(exponent) {}
00141 inline Scalar operator() (const Scalar& a) const { return ei_pow(a, m_exponent); }
00142 const Scalar m_exponent;
00143 private:
00144 ei_scalar_pow_op& operator=(const ei_scalar_pow_op&);
00145 };
00146 template<typename Scalar>
00147 struct ei_functor_traits<ei_scalar_pow_op<Scalar> >
00148 { enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };
00149
00158 template<typename Scalar>
00159 struct ei_scalar_inverse_op {
00160 inline Scalar operator() (const Scalar& a) const { return Scalar(1)/a; }
00161 template<typename PacketScalar>
00162 inline const PacketScalar packetOp(const PacketScalar& a) const
00163 { return ei_pdiv(ei_pset1(Scalar(1)),a); }
00164 };
00165 template<typename Scalar>
00166 struct ei_functor_traits<ei_scalar_inverse_op<Scalar> >
00167 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = int(ei_packet_traits<Scalar>::size)>1 }; };
00168
00177 template<typename Scalar>
00178 struct ei_scalar_square_op {
00179 inline Scalar operator() (const Scalar& a) const { return a*a; }
00180 template<typename PacketScalar>
00181 inline const PacketScalar packetOp(const PacketScalar& a) const
00182 { return ei_pmul(a,a); }
00183 };
00184 template<typename Scalar>
00185 struct ei_functor_traits<ei_scalar_square_op<Scalar> >
00186 { enum { Cost = NumTraits<Scalar>::MulCost, PacketAccess = int(ei_packet_traits<Scalar>::size)>1 }; };
00187
00196 template<typename Scalar>
00197 struct ei_scalar_cube_op {
00198 inline Scalar operator() (const Scalar& a) const { return a*a*a; }
00199 template<typename PacketScalar>
00200 inline const PacketScalar packetOp(const PacketScalar& a) const
00201 { return ei_pmul(a,ei_pmul(a,a)); }
00202 };
00203 template<typename Scalar>
00204 struct ei_functor_traits<ei_scalar_cube_op<Scalar> >
00205 { enum { Cost = 2*NumTraits<Scalar>::MulCost, PacketAccess = int(ei_packet_traits<Scalar>::size)>1 }; };
00206
00207
00208
00209 template<typename T>
00210 struct ei_functor_traits<std::multiplies<T> >
00211 { enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
00212
00213 template<typename T>
00214 struct ei_functor_traits<std::divides<T> >
00215 { enum { Cost = NumTraits<T>::MulCost, PacketAccess = false }; };
00216
00217 template<typename T>
00218 struct ei_functor_traits<std::plus<T> >
00219 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
00220
00221 template<typename T>
00222 struct ei_functor_traits<std::minus<T> >
00223 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
00224
00225 template<typename T>
00226 struct ei_functor_traits<std::negate<T> >
00227 { enum { Cost = NumTraits<T>::AddCost, PacketAccess = false }; };
00228
00229 template<typename T>
00230 struct ei_functor_traits<std::logical_or<T> >
00231 { enum { Cost = 1, PacketAccess = false }; };
00232
00233 template<typename T>
00234 struct ei_functor_traits<std::logical_and<T> >
00235 { enum { Cost = 1, PacketAccess = false }; };
00236
00237 template<typename T>
00238 struct ei_functor_traits<std::logical_not<T> >
00239 { enum { Cost = 1, PacketAccess = false }; };
00240
00241 template<typename T>
00242 struct ei_functor_traits<std::greater<T> >
00243 { enum { Cost = 1, PacketAccess = false }; };
00244
00245 template<typename T>
00246 struct ei_functor_traits<std::less<T> >
00247 { enum { Cost = 1, PacketAccess = false }; };
00248
00249 template<typename T>
00250 struct ei_functor_traits<std::greater_equal<T> >
00251 { enum { Cost = 1, PacketAccess = false }; };
00252
00253 template<typename T>
00254 struct ei_functor_traits<std::less_equal<T> >
00255 { enum { Cost = 1, PacketAccess = false }; };
00256
00257 template<typename T>
00258 struct ei_functor_traits<std::equal_to<T> >
00259 { enum { Cost = 1, PacketAccess = false }; };
00260
00261 template<typename T>
00262 struct ei_functor_traits<std::not_equal_to<T> >
00263 { enum { Cost = 1, PacketAccess = false }; };
00264
00265 template<typename T>
00266 struct ei_functor_traits<std::binder2nd<T> >
00267 { enum { Cost = ei_functor_traits<T>::Cost, PacketAccess = false }; };
00268
00269 template<typename T>
00270 struct ei_functor_traits<std::binder1st<T> >
00271 { enum { Cost = ei_functor_traits<T>::Cost, PacketAccess = false }; };
00272
00273 template<typename T>
00274 struct ei_functor_traits<std::unary_negate<T> >
00275 { enum { Cost = 1 + ei_functor_traits<T>::Cost, PacketAccess = false }; };
00276
00277 template<typename T>
00278 struct ei_functor_traits<std::binary_negate<T> >
00279 { enum { Cost = 1 + ei_functor_traits<T>::Cost, PacketAccess = false }; };
00280
00281 #ifdef EIGEN_STDEXT_SUPPORT
00282
00283 template<typename T0,typename T1>
00284 struct ei_functor_traits<std::project1st<T0,T1> >
00285 { enum { Cost = 0, PacketAccess = false }; };
00286
00287 template<typename T0,typename T1>
00288 struct ei_functor_traits<std::project2nd<T0,T1> >
00289 { enum { Cost = 0, PacketAccess = false }; };
00290
00291 template<typename T0,typename T1>
00292 struct ei_functor_traits<std::select2nd<std::pair<T0,T1> > >
00293 { enum { Cost = 0, PacketAccess = false }; };
00294
00295 template<typename T0,typename T1>
00296 struct ei_functor_traits<std::select1st<std::pair<T0,T1> > >
00297 { enum { Cost = 0, PacketAccess = false }; };
00298
00299 template<typename T0,typename T1>
00300 struct ei_functor_traits<std::unary_compose<T0,T1> >
00301 { enum { Cost = ei_functor_traits<T0>::Cost + ei_functor_traits<T1>::Cost, PacketAccess = false }; };
00302
00303 template<typename T0,typename T1,typename T2>
00304 struct ei_functor_traits<std::binary_compose<T0,T1,T2> >
00305 { enum { Cost = ei_functor_traits<T0>::Cost + ei_functor_traits<T1>::Cost + ei_functor_traits<T2>::Cost, PacketAccess = false }; };
00306
00307 #endif // EIGEN_STDEXT_SUPPORT
00308
00309 #endif // EIGEN_ARRAY_FUNCTORS_H