SpecialFunctionsFunctors.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) 2016 Eugene Brevdo <ebrevdo@gmail.com>
5 // Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_SPECIALFUNCTIONS_FUNCTORS_H
12 #define EIGEN_SPECIALFUNCTIONS_FUNCTORS_H
13 
14 namespace Eigen {
15 
16 namespace internal {
17 
18 
24 template<typename Scalar> struct scalar_igamma_op : binary_op_base<Scalar,Scalar>
25 {
26  EIGEN_EMPTY_STRUCT_CTOR(scalar_igamma_op)
27  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& x) const {
28  using numext::igamma; return igamma(a, x);
29  }
30  template<typename Packet>
32  return internal::pigamma(a, x);
33  }
34 };
35 template<typename Scalar>
37  enum {
38  // Guesstimate
41  };
42 };
43 
50 template <typename Scalar>
53  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& a, const Scalar& x) const {
55  return igamma_der_a(a, x);
56  }
57  template <typename Packet>
59  return internal::pigamma_der_a(a, x);
60  }
61 };
62 template <typename Scalar>
64  enum {
65  // 2x the cost of igamma
68  };
69 };
70 
78 template <typename Scalar>
81  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& alpha, const Scalar& sample) const {
83  return gamma_sample_der_alpha(alpha, sample);
84  }
85  template <typename Packet>
88  }
89 };
90 template <typename Scalar>
92  enum {
93  // 2x the cost of igamma, minus the lgamma cost (the lgamma cancels out)
96  };
97 };
98 
104 template<typename Scalar> struct scalar_igammac_op : binary_op_base<Scalar,Scalar>
105 {
106  EIGEN_EMPTY_STRUCT_CTOR(scalar_igammac_op)
107  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a, const Scalar& x) const {
108  using numext::igammac; return igammac(a, x);
109  }
110  template<typename Packet>
112  {
113  return internal::pigammac(a, x);
114  }
115 };
116 template<typename Scalar>
118  enum {
119  // Guesstimate
122  };
123 };
124 
125 
130 template<typename Scalar> struct scalar_betainc_op {
131  EIGEN_EMPTY_STRUCT_CTOR(scalar_betainc_op)
132  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& x, const Scalar& a, const Scalar& b) const {
133  using numext::betainc; return betainc(x, a, b);
134  }
135  template<typename Packet>
137  {
138  return internal::pbetainc(x, a, b);
139  }
140 };
141 template<typename Scalar>
143  enum {
144  // Guesstimate
147  };
148 };
149 
150 
156 template<typename Scalar> struct scalar_lgamma_op {
157  EIGEN_EMPTY_STRUCT_CTOR(scalar_lgamma_op)
158  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const {
159  using numext::lgamma; return lgamma(a);
160  }
163 };
164 template<typename Scalar>
166 {
167  enum {
168  // Guesstimate
171  };
172 };
173 
178 template<typename Scalar> struct scalar_digamma_op {
179  EIGEN_EMPTY_STRUCT_CTOR(scalar_digamma_op)
180  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const {
181  using numext::digamma; return digamma(a);
182  }
185 };
186 template<typename Scalar>
188 {
189  enum {
190  // Guesstimate
193  };
194 };
195 
200 template<typename Scalar> struct scalar_zeta_op {
201  EIGEN_EMPTY_STRUCT_CTOR(scalar_zeta_op)
202  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& x, const Scalar& q) const {
203  using numext::zeta; return zeta(x, q);
204  }
207 };
208 template<typename Scalar>
210 {
211  enum {
212  // Guesstimate
215  };
216 };
217 
222 template<typename Scalar> struct scalar_polygamma_op {
224  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& n, const Scalar& x) const {
225  using numext::polygamma; return polygamma(n, x);
226  }
229 };
230 template<typename Scalar>
232 {
233  enum {
234  // Guesstimate
237  };
238 };
239 
244 template<typename Scalar> struct scalar_erf_op {
245  EIGEN_EMPTY_STRUCT_CTOR(scalar_erf_op)
247  operator()(const Scalar& a) const {
248  return numext::erf(a);
249  }
250  template <typename Packet>
252  return perf(x);
253  }
254 };
255 template <typename Scalar>
257  enum {
260  (PacketAccess
261 #ifdef EIGEN_VECTORIZE_FMA
262  // TODO(rmlarsen): Move the FMA cost model to a central location.
263  // Haswell can issue 2 add/mul/madd per cycle.
264  // 10 pmadd, 2 pmul, 1 div, 2 other
268 #else
272 #endif
273  // Assume for simplicity that this is as expensive as an exp().
275  };
276 };
277 
283 template<typename Scalar> struct scalar_erfc_op {
284  EIGEN_EMPTY_STRUCT_CTOR(scalar_erfc_op)
285  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const {
286  using numext::erfc; return erfc(a);
287  }
290 };
291 template<typename Scalar>
293 {
294  enum {
295  // Guesstimate
298  };
299 };
300 
306 template<typename Scalar> struct scalar_ndtri_op {
307  EIGEN_EMPTY_STRUCT_CTOR(scalar_ndtri_op)
308  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const {
309  using numext::ndtri; return ndtri(a);
310  }
313 };
314 template<typename Scalar>
316 {
317  enum {
318  // On average, We are evaluating rational functions with degree N=9 in the
319  // numerator and denominator. This results in 2*N additions and 2*N
320  // multiplications.
323  };
324 };
325 
326 } // end namespace internal
327 
328 } // end namespace Eigen
329 
330 #endif // EIGEN_SPECIALFUNCTIONS_FUNCTORS_H
EIGEN_EMPTY_STRUCT_CTOR
#define EIGEN_EMPTY_STRUCT_CTOR(X)
Definition: XprHelper.h:22
Eigen::internal::scalar_lgamma_op::Packet
packet_traits< Scalar >::type Packet
Definition: SpecialFunctionsFunctors.h:161
Eigen::internal::scalar_igamma_der_a_op::packetOp
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Packet packetOp(const Packet &a, const Packet &x) const
Definition: SpecialFunctionsFunctors.h:58
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::scalar_ndtri_op::packetOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &a) const
Definition: SpecialFunctionsFunctors.h:312
Eigen::internal::scalar_polygamma_op::Packet
packet_traits< Scalar >::type Packet
Definition: SpecialFunctionsFunctors.h:227
Eigen::igamma_der_a
const EIGEN_STRONG_INLINE Eigen::CwiseBinaryOp< Eigen::internal::scalar_igamma_der_a_op< typename Derived::Scalar >, const Derived, const ExponentDerived > igamma_der_a(const Eigen::ArrayBase< Derived > &a, const Eigen::ArrayBase< ExponentDerived > &x)
Definition: SpecialFunctionsArrayAPI.h:51
Eigen::internal::scalar_igamma_der_a_op
Definition: SpecialFunctionsFunctors.h:51
Eigen::internal::scalar_igammac_op
Definition: ForwardDeclarations.h:221
Eigen::betainc
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE TensorCwiseTernaryOp< internal::scalar_betainc_op< typename XDerived::Scalar >, const ADerived, const BDerived, const XDerived > betainc(const ADerived &a, const BDerived &b, const XDerived &x)
Definition: TensorGlobalFunctions.h:24
alpha
RealScalar alpha
Definition: level1_cplx_impl.h:147
Eigen::internal::scalar_gamma_sample_der_alpha_op::packetOp
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Packet packetOp(const Packet &alpha, const Packet &sample) const
Definition: SpecialFunctionsFunctors.h:86
Eigen::internal::scalar_lgamma_op
Definition: ForwardDeclarations.h:215
b
Scalar * b
Definition: benchVecAdd.cpp:17
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
Definition: gnuplot_common_settings.hh:12
Eigen::gamma_sample_der_alpha
const EIGEN_STRONG_INLINE Eigen::CwiseBinaryOp< Eigen::internal::scalar_gamma_sample_der_alpha_op< typename AlphaDerived::Scalar >, const AlphaDerived, const SampleDerived > gamma_sample_der_alpha(const Eigen::ArrayBase< AlphaDerived > &alpha, const Eigen::ArrayBase< SampleDerived > &sample)
Definition: SpecialFunctionsArrayAPI.h:72
Eigen::internal::packet_traits
Definition: GenericPacketMath.h:106
Eigen::internal::scalar_erf_op
Definition: ForwardDeclarations.h:217
Eigen::internal::pgamma_sample_der_alpha
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pgamma_sample_der_alpha(const Packet &alpha, const Packet &sample)
Definition: SpecialFunctionsPacketMath.h:63
Eigen::internal::scalar_ndtri_op
Definition: ForwardDeclarations.h:219
digamma
const EIGEN_DEVICE_FUNC DigammaReturnType digamma() const
Definition: ArrayCwiseUnaryOps.h:637
n
int n
Definition: BiCGSTAB_simple.cpp:1
Eigen::internal::ppolygamma
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet ppolygamma(const Packet &n, const Packet &x)
Definition: SpecialFunctionsPacketMath.h:31
Eigen::internal::scalar_ndtri_op::Packet
packet_traits< Scalar >::type Packet
Definition: SpecialFunctionsFunctors.h:311
Eigen::internal::scalar_polygamma_op::packetOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &n, const Packet &x) const
Definition: SpecialFunctionsFunctors.h:228
Eigen::polygamma
const EIGEN_STRONG_INLINE Eigen::CwiseBinaryOp< Eigen::internal::scalar_polygamma_op< typename DerivedX::Scalar >, const DerivedN, const DerivedX > polygamma(const Eigen::ArrayBase< DerivedN > &n, const Eigen::ArrayBase< DerivedX > &x)
Definition: SpecialFunctionsArrayAPI.h:112
lgamma
const EIGEN_DEVICE_FUNC LgammaReturnType lgamma() const
Definition: ArrayCwiseUnaryOps.h:620
Eigen::internal::pigamma
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pigamma(const Packet &a, const Packet &x)
Definition: SpecialFunctionsPacketMath.h:50
Eigen::numext::q
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:1984
Eigen::internal::pdigamma
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pdigamma(const Packet &a)
Definition: SpecialFunctionsPacketMath.h:23
Eigen::internal::scalar_erfc_op::packetOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &a) const
Definition: SpecialFunctionsFunctors.h:289
Eigen::internal::scalar_igamma_op::packetOp
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Packet packetOp(const Packet &a, const Packet &x) const
Definition: SpecialFunctionsFunctors.h:31
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::internal::pigamma_der_a
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pigamma_der_a(const Packet &a, const Packet &x)
Definition: SpecialFunctionsPacketMath.h:55
Eigen::internal::scalar_zeta_op::Packet
packet_traits< Scalar >::type Packet
Definition: SpecialFunctionsFunctors.h:205
Eigen::internal::scalar_erfc_op
Definition: ForwardDeclarations.h:218
Eigen::internal::pigammac
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pigammac(const Packet &a, const Packet &x)
Definition: SpecialFunctionsPacketMath.h:69
Eigen::internal::scalar_erf_op::packetOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &x) const
Definition: SpecialFunctionsFunctors.h:251
Eigen::internal::Packet
Definition: ZVector/PacketMath.h:47
Eigen::internal::perfc
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet perfc(const Packet &a)
Definition: SpecialFunctionsPacketMath.h:39
Eigen::internal::functor_traits::PacketAccess
@ PacketAccess
Definition: XprHelper.h:180
Eigen::internal::scalar_igammac_op::packetOp
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Packet packetOp(const Packet &a, const Packet &x) const
Definition: SpecialFunctionsFunctors.h:111
Eigen::igamma
const EIGEN_STRONG_INLINE Eigen::CwiseBinaryOp< Eigen::internal::scalar_igamma_op< typename Derived::Scalar >, const Derived, const ExponentDerived > igamma(const Eigen::ArrayBase< Derived > &a, const Eigen::ArrayBase< ExponentDerived > &x)
Definition: SpecialFunctionsArrayAPI.h:28
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
Eigen::internal::scalar_div_cost
Definition: XprHelper.h:710
Eigen::internal::scalar_digamma_op::Packet
packet_traits< Scalar >::type Packet
Definition: SpecialFunctionsFunctors.h:183
Eigen::internal::functor_traits::Cost
@ Cost
Definition: XprHelper.h:179
zeta
double zeta(double x, double q)
Definition: zeta.c:89
Eigen::internal::scalar_polygamma_op
Definition: SpecialFunctionsFunctors.h:222
Eigen::internal::plgamma
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet plgamma(const Packet &a)
Definition: SpecialFunctionsPacketMath.h:19
Eigen::internal::scalar_betainc_op
Definition: ForwardDeclarations.h:223
Eigen::zeta
const EIGEN_STRONG_INLINE Eigen::CwiseBinaryOp< Eigen::internal::scalar_zeta_op< typename DerivedX::Scalar >, const DerivedX, const DerivedQ > zeta(const Eigen::ArrayBase< DerivedX > &x, const Eigen::ArrayBase< DerivedQ > &q)
Definition: SpecialFunctionsArrayAPI.h:156
Eigen::internal::scalar_gamma_sample_der_alpha_op
Definition: SpecialFunctionsFunctors.h:79
erf
double erf(double x)
Definition: ndtr.c:285
Eigen::internal::pndtri
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pndtri(const Packet &a)
Definition: SpecialFunctionsPacketMath.h:43
Eigen::internal::pbetainc
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet pbetainc(const Packet &a, const Packet &b, const Packet &x)
Definition: SpecialFunctionsPacketMath.h:73
ndtri
double ndtri(double y0)
Definition: ndtri.c:134
Eigen::internal::pzeta
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pzeta(const Packet &x, const Packet &q)
Definition: SpecialFunctionsPacketMath.h:27
Eigen::internal::functor_traits
Definition: XprHelper.h:175
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::scalar_lgamma_op::packetOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &a) const
Definition: SpecialFunctionsFunctors.h:162
erfc
double erfc(double a)
Definition: ndtr.c:227
Eigen::internal::scalar_erf_op::operator()
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Scalar operator()(const Scalar &a) const
Definition: SpecialFunctionsFunctors.h:247
Eigen::internal::scalar_betainc_op::packetOp
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Packet packetOp(const Packet &x, const Packet &a, const Packet &b) const
Definition: SpecialFunctionsFunctors.h:136
Eigen::internal::scalar_erfc_op::Packet
packet_traits< Scalar >::type Packet
Definition: SpecialFunctionsFunctors.h:288
Eigen::internal::scalar_digamma_op::packetOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &a) const
Definition: SpecialFunctionsFunctors.h:184
Eigen::internal::scalar_zeta_op
Definition: ForwardDeclarations.h:222
Eigen::internal::scalar_igamma_op
Definition: ForwardDeclarations.h:220
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:232
test_callbacks.value
value
Definition: test_callbacks.py:160
Eigen::internal::scalar_zeta_op::packetOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet &x, const Packet &q) const
Definition: SpecialFunctionsFunctors.h:206
Eigen::internal::perf
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet perf(const Packet &a)
Definition: SpecialFunctionsPacketMath.h:35
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::igammac
const EIGEN_STRONG_INLINE Eigen::CwiseBinaryOp< Eigen::internal::scalar_igammac_op< typename Derived::Scalar >, const Derived, const ExponentDerived > igammac(const Eigen::ArrayBase< Derived > &a, const Eigen::ArrayBase< ExponentDerived > &x)
Definition: SpecialFunctionsArrayAPI.h:90
Eigen::internal::scalar_digamma_op
Definition: ForwardDeclarations.h:216


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:36:23