GPU/SpecialFunctions.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) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
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_GPU_SPECIALFUNCTIONS_H
11 #define EIGEN_GPU_SPECIALFUNCTIONS_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 // Make sure this is only available when targeting a GPU: we don't want to
18 // introduce conflicts between these packet_traits definitions and the ones
19 // we'll use on the host side (SSE, AVX, ...)
20 #if defined(EIGEN_GPUCC) && defined(EIGEN_USE_GPU)
21 
22 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
23 float4 plgamma<float4>(const float4& a)
24 {
25  return make_float4(lgammaf(a.x), lgammaf(a.y), lgammaf(a.z), lgammaf(a.w));
26 }
27 
28 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
29 double2 plgamma<double2>(const double2& a)
30 {
31  using numext::lgamma;
32  return make_double2(lgamma(a.x), lgamma(a.y));
33 }
34 
35 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
36 float4 pdigamma<float4>(const float4& a)
37 {
38  using numext::digamma;
39  return make_float4(digamma(a.x), digamma(a.y), digamma(a.z), digamma(a.w));
40 }
41 
42 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
43 double2 pdigamma<double2>(const double2& a)
44 {
45  using numext::digamma;
46  return make_double2(digamma(a.x), digamma(a.y));
47 }
48 
49 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
50 float4 pzeta<float4>(const float4& x, const float4& q)
51 {
52  using numext::zeta;
53  return make_float4(zeta(x.x, q.x), zeta(x.y, q.y), zeta(x.z, q.z), zeta(x.w, q.w));
54 }
55 
56 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
57 double2 pzeta<double2>(const double2& x, const double2& q)
58 {
59  using numext::zeta;
60  return make_double2(zeta(x.x, q.x), zeta(x.y, q.y));
61 }
62 
63 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
64 float4 ppolygamma<float4>(const float4& n, const float4& x)
65 {
66  using numext::polygamma;
67  return make_float4(polygamma(n.x, x.x), polygamma(n.y, x.y), polygamma(n.z, x.z), polygamma(n.w, x.w));
68 }
69 
70 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
71 double2 ppolygamma<double2>(const double2& n, const double2& x)
72 {
73  using numext::polygamma;
74  return make_double2(polygamma(n.x, x.x), polygamma(n.y, x.y));
75 }
76 
77 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
78 float4 perf<float4>(const float4& a)
79 {
80  return make_float4(erff(a.x), erff(a.y), erff(a.z), erff(a.w));
81 }
82 
83 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
84 double2 perf<double2>(const double2& a)
85 {
86  using numext::erf;
87  return make_double2(erf(a.x), erf(a.y));
88 }
89 
90 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
91 float4 perfc<float4>(const float4& a)
92 {
93  using numext::erfc;
94  return make_float4(erfc(a.x), erfc(a.y), erfc(a.z), erfc(a.w));
95 }
96 
97 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
98 double2 perfc<double2>(const double2& a)
99 {
100  using numext::erfc;
101  return make_double2(erfc(a.x), erfc(a.y));
102 }
103 
104 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
105 float4 pndtri<float4>(const float4& a)
106 {
107  using numext::ndtri;
108  return make_float4(ndtri(a.x), ndtri(a.y), ndtri(a.z), ndtri(a.w));
109 }
110 
111 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
112 double2 pndtri<double2>(const double2& a)
113 {
114  using numext::ndtri;
115  return make_double2(ndtri(a.x), ndtri(a.y));
116 }
117 
118 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
119 float4 pigamma<float4>(const float4& a, const float4& x)
120 {
121  using numext::igamma;
122  return make_float4(
123  igamma(a.x, x.x),
124  igamma(a.y, x.y),
125  igamma(a.z, x.z),
126  igamma(a.w, x.w));
127 }
128 
129 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
130 double2 pigamma<double2>(const double2& a, const double2& x)
131 {
132  using numext::igamma;
133  return make_double2(igamma(a.x, x.x), igamma(a.y, x.y));
134 }
135 
136 template <>
137 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pigamma_der_a<float4>(
138  const float4& a, const float4& x) {
139  using numext::igamma_der_a;
140  return make_float4(igamma_der_a(a.x, x.x), igamma_der_a(a.y, x.y),
141  igamma_der_a(a.z, x.z), igamma_der_a(a.w, x.w));
142 }
143 
144 template <>
145 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
146 pigamma_der_a<double2>(const double2& a, const double2& x) {
147  using numext::igamma_der_a;
148  return make_double2(igamma_der_a(a.x, x.x), igamma_der_a(a.y, x.y));
149 }
150 
151 template <>
152 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pgamma_sample_der_alpha<float4>(
153  const float4& alpha, const float4& sample) {
155  return make_float4(
156  gamma_sample_der_alpha(alpha.x, sample.x),
157  gamma_sample_der_alpha(alpha.y, sample.y),
158  gamma_sample_der_alpha(alpha.z, sample.z),
159  gamma_sample_der_alpha(alpha.w, sample.w));
160 }
161 
162 template <>
163 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
164 pgamma_sample_der_alpha<double2>(const double2& alpha, const double2& sample) {
166  return make_double2(
167  gamma_sample_der_alpha(alpha.x, sample.x),
168  gamma_sample_der_alpha(alpha.y, sample.y));
169 }
170 
171 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
172 float4 pigammac<float4>(const float4& a, const float4& x)
173 {
174  using numext::igammac;
175  return make_float4(
176  igammac(a.x, x.x),
177  igammac(a.y, x.y),
178  igammac(a.z, x.z),
179  igammac(a.w, x.w));
180 }
181 
182 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
183 double2 pigammac<double2>(const double2& a, const double2& x)
184 {
185  using numext::igammac;
186  return make_double2(igammac(a.x, x.x), igammac(a.y, x.y));
187 }
188 
189 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
190 float4 pbetainc<float4>(const float4& a, const float4& b, const float4& x)
191 {
192  using numext::betainc;
193  return make_float4(
194  betainc(a.x, b.x, x.x),
195  betainc(a.y, b.y, x.y),
196  betainc(a.z, b.z, x.z),
197  betainc(a.w, b.w, x.w));
198 }
199 
200 template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
201 double2 pbetainc<double2>(const double2& a, const double2& b, const double2& x)
202 {
203  using numext::betainc;
204  return make_double2(betainc(a.x, b.x, x.x), betainc(a.y, b.y, x.y));
205 }
206 
207 template <>
208 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_i0e<float4>(const float4& x) {
209  using numext::bessel_i0e;
210  return make_float4(bessel_i0e(x.x), bessel_i0e(x.y), bessel_i0e(x.z), bessel_i0e(x.w));
211 }
212 
213 template <>
214 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
215 pbessel_i0e<double2>(const double2& x) {
216  using numext::bessel_i0e;
217  return make_double2(bessel_i0e(x.x), bessel_i0e(x.y));
218 }
219 
220 template <>
221 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_i0<float4>(const float4& x) {
222  using numext::bessel_i0;
223  return make_float4(bessel_i0(x.x), bessel_i0(x.y), bessel_i0(x.z), bessel_i0(x.w));
224 }
225 
226 template <>
227 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
228 pbessel_i0<double2>(const double2& x) {
229  using numext::bessel_i0;
230  return make_double2(bessel_i0(x.x), bessel_i0(x.y));
231 }
232 
233 template <>
234 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_i1e<float4>(const float4& x) {
235  using numext::bessel_i1e;
236  return make_float4(bessel_i1e(x.x), bessel_i1e(x.y), bessel_i1e(x.z), bessel_i1e(x.w));
237 }
238 
239 template <>
240 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
241 pbessel_i1e<double2>(const double2& x) {
242  using numext::bessel_i1e;
243  return make_double2(bessel_i1e(x.x), bessel_i1e(x.y));
244 }
245 
246 template <>
247 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_i1<float4>(const float4& x) {
248  using numext::bessel_i1;
249  return make_float4(bessel_i1(x.x), bessel_i1(x.y), bessel_i1(x.z), bessel_i1(x.w));
250 }
251 
252 template <>
253 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
254 pbessel_i1<double2>(const double2& x) {
255  using numext::bessel_i1;
256  return make_double2(bessel_i1(x.x), bessel_i1(x.y));
257 }
258 
259 template <>
260 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_k0e<float4>(const float4& x) {
261  using numext::bessel_k0e;
262  return make_float4(bessel_k0e(x.x), bessel_k0e(x.y), bessel_k0e(x.z), bessel_k0e(x.w));
263 }
264 
265 template <>
266 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
267 pbessel_k0e<double2>(const double2& x) {
268  using numext::bessel_k0e;
269  return make_double2(bessel_k0e(x.x), bessel_k0e(x.y));
270 }
271 
272 template <>
273 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_k0<float4>(const float4& x) {
274  using numext::bessel_k0;
275  return make_float4(bessel_k0(x.x), bessel_k0(x.y), bessel_k0(x.z), bessel_k0(x.w));
276 }
277 
278 template <>
279 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
280 pbessel_k0<double2>(const double2& x) {
281  using numext::bessel_k0;
282  return make_double2(bessel_k0(x.x), bessel_k0(x.y));
283 }
284 
285 template <>
286 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_k1e<float4>(const float4& x) {
287  using numext::bessel_k1e;
288  return make_float4(bessel_k1e(x.x), bessel_k1e(x.y), bessel_k1e(x.z), bessel_k1e(x.w));
289 }
290 
291 template <>
292 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
293 pbessel_k1e<double2>(const double2& x) {
294  using numext::bessel_k1e;
295  return make_double2(bessel_k1e(x.x), bessel_k1e(x.y));
296 }
297 
298 template <>
299 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_k1<float4>(const float4& x) {
300  using numext::bessel_k1;
301  return make_float4(bessel_k1(x.x), bessel_k1(x.y), bessel_k1(x.z), bessel_k1(x.w));
302 }
303 
304 template <>
305 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
306 pbessel_k1<double2>(const double2& x) {
307  using numext::bessel_k1;
308  return make_double2(bessel_k1(x.x), bessel_k1(x.y));
309 }
310 
311 template <>
312 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_j0<float4>(const float4& x) {
313  using numext::bessel_j0;
314  return make_float4(bessel_j0(x.x), bessel_j0(x.y), bessel_j0(x.z), bessel_j0(x.w));
315 }
316 
317 template <>
318 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
319 pbessel_j0<double2>(const double2& x) {
320  using numext::bessel_j0;
321  return make_double2(bessel_j0(x.x), bessel_j0(x.y));
322 }
323 
324 template <>
325 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_j1<float4>(const float4& x) {
326  using numext::bessel_j1;
327  return make_float4(bessel_j1(x.x), bessel_j1(x.y), bessel_j1(x.z), bessel_j1(x.w));
328 }
329 
330 template <>
331 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
332 pbessel_j1<double2>(const double2& x) {
333  using numext::bessel_j1;
334  return make_double2(bessel_j1(x.x), bessel_j1(x.y));
335 }
336 
337 template <>
338 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_y0<float4>(const float4& x) {
339  using numext::bessel_y0;
340  return make_float4(bessel_y0(x.x), bessel_y0(x.y), bessel_y0(x.z), bessel_y0(x.w));
341 }
342 
343 template <>
344 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
345 pbessel_y0<double2>(const double2& x) {
346  using numext::bessel_y0;
347  return make_double2(bessel_y0(x.x), bessel_y0(x.y));
348 }
349 
350 template <>
351 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pbessel_y1<float4>(const float4& x) {
352  using numext::bessel_y1;
353  return make_float4(bessel_y1(x.x), bessel_y1(x.y), bessel_y1(x.z), bessel_y1(x.w));
354 }
355 
356 template <>
357 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
358 pbessel_y1<double2>(const double2& x) {
359  using numext::bessel_y1;
360  return make_double2(bessel_y1(x.x), bessel_y1(x.y));
361 }
362 
363 #endif
364 
365 } // end namespace internal
366 
367 } // end namespace Eigen
368 
369 #endif // EIGEN_GPU_SPECIALFUNCTIONS_H
ArrayXXi a
int n
#define EIGEN_DEVICE_FUNC
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_erfc_op< typename Derived::Scalar >, const Derived > erfc(const Eigen::ArrayBase< Derived > &x)
const 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)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_j1_op< typename Derived::Scalar >, const Derived > bessel_j1(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k0_op< typename Derived::Scalar >, const Derived > bessel_k0(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_y1_op< typename Derived::Scalar >, const Derived > bessel_y1(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_j0_op< typename Derived::Scalar >, const Derived > bessel_j0(const Eigen::ArrayBase< Derived > &x)
const TensorCwiseTernaryOp< internal::scalar_betainc_op< typename XDerived::Scalar >, const ADerived, const BDerived, const XDerived > betainc(const ADerived &a, const BDerived &b, const XDerived &x)
const 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)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k1_op< typename Derived::Scalar >, const Derived > bessel_k1(const Eigen::ArrayBase< Derived > &x)
const 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)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k0e_op< typename Derived::Scalar >, const Derived > bessel_k0e(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_y0_op< typename Derived::Scalar >, const Derived > bessel_y0(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i0_op< typename Derived::Scalar >, const Derived > bessel_i0(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_ndtri_op< typename Derived::Scalar >, const Derived > ndtri(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_lgamma_op< typename Derived::Scalar >, const Derived > lgamma(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_erf_op< typename Derived::Scalar >, const Derived > erf(const Eigen::ArrayBase< Derived > &x)
const 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)
const 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)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i1_op< typename Derived::Scalar >, const Derived > bessel_i1(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i1e_op< typename Derived::Scalar >, const Derived > bessel_i1e(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i0e_op< typename Derived::Scalar >, const Derived > bessel_i0e(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_digamma_op< typename Derived::Scalar >, const Derived > digamma(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k1e_op< typename Derived::Scalar >, const Derived > bessel_k1e(const Eigen::ArrayBase< Derived > &x)
const 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)