Eigen-Contrib  5.0.1-dev+master
 
Loading...
Searching...
No Matches
BesselFunctionsImpl.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2015 Eugene Brevdo <ebrevdo@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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_BESSEL_FUNCTIONS_H
12#define EIGEN_BESSEL_FUNCTIONS_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18namespace internal {
19
20// Parts of this code are based on the Cephes Math Library.
21//
22// Cephes Math Library Release 2.8: June, 2000
23// Copyright 1984, 1987, 1992, 2000 by Stephen L. Moshier
24//
25// Permission has been kindly provided by the original author
26// to incorporate the Cephes software into the Eigen codebase:
27//
28// From: Stephen Moshier
29// To: Eugene Brevdo
30// Subject: Re: Permission to wrap several cephes functions in Eigen
31//
32// Hello Eugene,
33//
34// Thank you for writing.
35//
36// If your licensing is similar to BSD, the formal way that has been
37// handled is simply to add a statement to the effect that you are incorporating
38// the Cephes software by permission of the author.
39//
40// Good luck with your project,
41// Steve
42
43/****************************************************************************
44 * Implementation of Bessel function, based on Cephes *
45 ****************************************************************************/
46
47template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
48struct generic_i0e {
49 EIGEN_STATIC_ASSERT((std::is_same<T, T>::value == false), THIS_TYPE_IS_NOT_SUPPORTED)
50
51 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T&) { return ScalarType(0); }
52};
53
54template <typename T>
55struct generic_i0e<T, float> {
56 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
57 /* i0ef.c
58 *
59 * Modified Bessel function of order zero,
60 * exponentially scaled
61 *
62 *
63 *
64 * SYNOPSIS:
65 *
66 * float x, y, i0ef();
67 *
68 * y = i0ef( x );
69 *
70 *
71 *
72 * DESCRIPTION:
73 *
74 * Returns exponentially scaled modified Bessel function
75 * of order zero of the argument.
76 *
77 * The function is defined as i0e(x) = exp(-|x|) j0( ix ).
78 *
79 *
80 *
81 * ACCURACY:
82 *
83 * Relative error:
84 * arithmetic domain # trials peak rms
85 * IEEE 0,30 100000 3.7e-7 7.0e-8
86 * See i0f().
87 *
88 */
89
90 const float A[] = {-1.30002500998624804212E-8f, 6.04699502254191894932E-8f, -2.67079385394061173391E-7f,
91 1.11738753912010371815E-6f, -4.41673835845875056359E-6f, 1.64484480707288970893E-5f,
92 -5.75419501008210370398E-5f, 1.88502885095841655729E-4f, -5.76375574538582365885E-4f,
93 1.63947561694133579842E-3f, -4.32430999505057594430E-3f, 1.05464603945949983183E-2f,
94 -2.37374148058994688156E-2f, 4.93052842396707084878E-2f, -9.49010970480476444210E-2f,
95 1.71620901522208775349E-1f, -3.04682672343198398683E-1f, 6.76795274409476084995E-1f};
96
97 const float B[] = {3.39623202570838634515E-9f, 2.26666899049817806459E-8f, 2.04891858946906374183E-7f,
98 2.89137052083475648297E-6f, 6.88975834691682398426E-5f, 3.36911647825569408990E-3f,
99 8.04490411014108831608E-1f};
100 T y = pabs(x);
101 T y_le_eight = internal::pchebevl<T, 18>::run(pmadd(pset1<T>(0.5f), y, pset1<T>(-2.0f)), A);
102 T y_gt_eight = pmul(internal::pchebevl<T, 7>::run(psub(pdiv(pset1<T>(32.0f), y), pset1<T>(2.0f)), B), prsqrt(y));
103 // TODO: Perhaps instead check whether all packet elements are in
104 // [-8, 8] and evaluate a branch based off of that. It's possible
105 // in practice most elements are in this region.
106 return pselect(pcmp_le(y, pset1<T>(8.0f)), y_le_eight, y_gt_eight);
107 }
108};
109
110template <typename T>
111struct generic_i0e<T, double> {
112 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
113 /* i0e.c
114 *
115 * Modified Bessel function of order zero,
116 * exponentially scaled
117 *
118 *
119 *
120 * SYNOPSIS:
121 *
122 * double x, y, i0e();
123 *
124 * y = i0e( x );
125 *
126 *
127 *
128 * DESCRIPTION:
129 *
130 * Returns exponentially scaled modified Bessel function
131 * of order zero of the argument.
132 *
133 * The function is defined as i0e(x) = exp(-|x|) j0( ix ).
134 *
135 *
136 *
137 * ACCURACY:
138 *
139 * Relative error:
140 * arithmetic domain # trials peak rms
141 * IEEE 0,30 30000 5.4e-16 1.2e-16
142 * See i0().
143 *
144 */
145
146 const double A[] = {-4.41534164647933937950E-18, 3.33079451882223809783E-17, -2.43127984654795469359E-16,
147 1.71539128555513303061E-15, -1.16853328779934516808E-14, 7.67618549860493561688E-14,
148 -4.85644678311192946090E-13, 2.95505266312963983461E-12, -1.72682629144155570723E-11,
149 9.67580903537323691224E-11, -5.18979560163526290666E-10, 2.65982372468238665035E-9,
150 -1.30002500998624804212E-8, 6.04699502254191894932E-8, -2.67079385394061173391E-7,
151 1.11738753912010371815E-6, -4.41673835845875056359E-6, 1.64484480707288970893E-5,
152 -5.75419501008210370398E-5, 1.88502885095841655729E-4, -5.76375574538582365885E-4,
153 1.63947561694133579842E-3, -4.32430999505057594430E-3, 1.05464603945949983183E-2,
154 -2.37374148058994688156E-2, 4.93052842396707084878E-2, -9.49010970480476444210E-2,
155 1.71620901522208775349E-1, -3.04682672343198398683E-1, 6.76795274409476084995E-1};
156 const double B[] = {-7.23318048787475395456E-18, -4.83050448594418207126E-18, 4.46562142029675999901E-17,
157 3.46122286769746109310E-17, -2.82762398051658348494E-16, -3.42548561967721913462E-16,
158 1.77256013305652638360E-15, 3.81168066935262242075E-15, -9.55484669882830764870E-15,
159 -4.15056934728722208663E-14, 1.54008621752140982691E-14, 3.85277838274214270114E-13,
160 7.18012445138366623367E-13, -1.79417853150680611778E-12, -1.32158118404477131188E-11,
161 -3.14991652796324136454E-11, 1.18891471078464383424E-11, 4.94060238822496958910E-10,
162 3.39623202570838634515E-9, 2.26666899049817806459E-8, 2.04891858946906374183E-7,
163 2.89137052083475648297E-6, 6.88975834691682398426E-5, 3.36911647825569408990E-3,
164 8.04490411014108831608E-1};
165 T y = pabs(x);
166 T y_le_eight = internal::pchebevl<T, 30>::run(pmadd(pset1<T>(0.5), y, pset1<T>(-2.0)), A);
167 T y_gt_eight = pmul(internal::pchebevl<T, 25>::run(psub(pdiv(pset1<T>(32.0), y), pset1<T>(2.0)), B), prsqrt(y));
168 // TODO: Perhaps instead check whether all packet elements are in
169 // [-8, 8] and evaluate a branch based off of that. It's possible
170 // in practice most elements are in this region.
171 return pselect(pcmp_le(y, pset1<T>(8.0)), y_le_eight, y_gt_eight);
172 }
173};
174
175template <typename T>
176struct bessel_i0e_impl {
177 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_i0e<T>::run(x); }
178};
179
180template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
181struct generic_i0 {
182 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
183 // Evaluating i0(x) = exp(|x|) * i0e(x) can prematurely cause intermediate overflow for large |x|
184 // i.e. 88.7228 < |x| <= 91.9008 for float
185 // 709.7827 < |x| <= 713.9869 for double
186 // Instead, use i0(x) = exp(|x|/2) * (exp(|x|/2) * i0e(x)). Cutting |x| in half keeps the intermediate result
187 // finite for all finite results.
188 const T ax = pabs(x);
189 const T i0e = generic_i0e<T, ScalarType>::run(x);
190 const T half_exp = pexp(pmul(pset1<T>(ScalarType(0.5)), ax));
191 T scaled = pmul(half_exp, i0e);
192#if defined(__FAST_MATH__) || defined(__ASSOCIATIVE_MATH__) || EIGEN_COMP_NVHPC
193 // Unfortunately fast-math reassociates (exp(|x|/2) * exp(|x|/2)) * i0e(x) which reintroduces the overflow,
194 // so we need to tell it not to.
195 pbarrier(scaled);
196#endif
197 // i0e(inf) = 0 would turn exp(inf) * i0e(inf) into NaN; i0(+-inf) = +inf.
198 const T inf = pinf<T>();
199 return pselect(pcmp_eq(ax, inf), inf, pmul(half_exp, scaled));
200 }
201};
202
203template <typename T>
204struct bessel_i0_impl {
205 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_i0<T>::run(x); }
206};
207
208template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
209struct generic_i1e {
210 EIGEN_STATIC_ASSERT((std::is_same<T, T>::value == false), THIS_TYPE_IS_NOT_SUPPORTED)
211
212 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T&) { return ScalarType(0); }
213};
214
215template <typename T>
216struct generic_i1e<T, float> {
217 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
218 /* i1ef.c
219 *
220 * Modified Bessel function of order one,
221 * exponentially scaled
222 *
223 *
224 *
225 * SYNOPSIS:
226 *
227 * float x, y, i1ef();
228 *
229 * y = i1ef( x );
230 *
231 *
232 *
233 * DESCRIPTION:
234 *
235 * Returns exponentially scaled modified Bessel function
236 * of order one of the argument.
237 *
238 * The function is defined as i1(x) = -i exp(-|x|) j1( ix ).
239 *
240 *
241 *
242 * ACCURACY:
243 *
244 * Relative error:
245 * arithmetic domain # trials peak rms
246 * IEEE 0, 30 30000 1.5e-6 1.5e-7
247 * See i1().
248 *
249 */
250 const float A[] = {9.38153738649577178388E-9f, -4.44505912879632808065E-8f, 2.00329475355213526229E-7f,
251 -8.56872026469545474066E-7f, 3.47025130813767847674E-6f, -1.32731636560394358279E-5f,
252 4.78156510755005422638E-5f, -1.61760815825896745588E-4f, 5.12285956168575772895E-4f,
253 -1.51357245063125314899E-3f, 4.15642294431288815669E-3f, -1.05640848946261981558E-2f,
254 2.47264490306265168283E-2f, -5.29459812080949914269E-2f, 1.02643658689847095384E-1f,
255 -1.76416518357834055153E-1f, 2.52587186443633654823E-1f};
256
257 const float B[] = {-3.83538038596423702205E-9f, -2.63146884688951950684E-8f, -2.51223623787020892529E-7f,
258 -3.88256480887769039346E-6f, -1.10588938762623716291E-4f, -9.76109749136146840777E-3f,
259 7.78576235018280120474E-1f};
260
261 T y = pabs(x);
262 T y_le_eight = pmul(y, internal::pchebevl<T, 17>::run(pmadd(pset1<T>(0.5f), y, pset1<T>(-2.0f)), A));
263 T y_gt_eight = pmul(internal::pchebevl<T, 7>::run(psub(pdiv(pset1<T>(32.0f), y), pset1<T>(2.0f)), B), prsqrt(y));
264 // TODO: Perhaps instead check whether all packet elements are in
265 // [-8, 8] and evaluate a branch based off of that. It's possible
266 // in practice most elements are in this region.
267 y = pselect(pcmp_le(y, pset1<T>(8.0f)), y_le_eight, y_gt_eight);
268 return pselect(pcmp_lt(x, pset1<T>(0.0f)), pnegate(y), y);
269 }
270};
271
272template <typename T>
273struct generic_i1e<T, double> {
274 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
275 /* i1e.c
276 *
277 * Modified Bessel function of order one,
278 * exponentially scaled
279 *
280 *
281 *
282 * SYNOPSIS:
283 *
284 * double x, y, i1e();
285 *
286 * y = i1e( x );
287 *
288 *
289 *
290 * DESCRIPTION:
291 *
292 * Returns exponentially scaled modified Bessel function
293 * of order one of the argument.
294 *
295 * The function is defined as i1(x) = -i exp(-|x|) j1( ix ).
296 *
297 *
298 *
299 * ACCURACY:
300 *
301 * Relative error:
302 * arithmetic domain # trials peak rms
303 * IEEE 0, 30 30000 2.0e-15 2.0e-16
304 * See i1().
305 *
306 */
307 const double A[] = {2.77791411276104639959E-18, -2.11142121435816608115E-17, 1.55363195773620046921E-16,
308 -1.10559694773538630805E-15, 7.60068429473540693410E-15, -5.04218550472791168711E-14,
309 3.22379336594557470981E-13, -1.98397439776494371520E-12, 1.17361862988909016308E-11,
310 -6.66348972350202774223E-11, 3.62559028155211703701E-10, -1.88724975172282928790E-9,
311 9.38153738649577178388E-9, -4.44505912879632808065E-8, 2.00329475355213526229E-7,
312 -8.56872026469545474066E-7, 3.47025130813767847674E-6, -1.32731636560394358279E-5,
313 4.78156510755005422638E-5, -1.61760815825896745588E-4, 5.12285956168575772895E-4,
314 -1.51357245063125314899E-3, 4.15642294431288815669E-3, -1.05640848946261981558E-2,
315 2.47264490306265168283E-2, -5.29459812080949914269E-2, 1.02643658689847095384E-1,
316 -1.76416518357834055153E-1, 2.52587186443633654823E-1};
317 const double B[] = {7.51729631084210481353E-18, 4.41434832307170791151E-18, -4.65030536848935832153E-17,
318 -3.20952592199342395980E-17, 2.96262899764595013876E-16, 3.30820231092092828324E-16,
319 -1.88035477551078244854E-15, -3.81440307243700780478E-15, 1.04202769841288027642E-14,
320 4.27244001671195135429E-14, -2.10154184277266431302E-14, -4.08355111109219731823E-13,
321 -7.19855177624590851209E-13, 2.03562854414708950722E-12, 1.41258074366137813316E-11,
322 3.25260358301548823856E-11, -1.89749581235054123450E-11, -5.58974346219658380687E-10,
323 -3.83538038596423702205E-9, -2.63146884688951950684E-8, -2.51223623787020892529E-7,
324 -3.88256480887769039346E-6, -1.10588938762623716291E-4, -9.76109749136146840777E-3,
325 7.78576235018280120474E-1};
326 T y = pabs(x);
327 T y_le_eight = pmul(y, internal::pchebevl<T, 29>::run(pmadd(pset1<T>(0.5), y, pset1<T>(-2.0)), A));
328 T y_gt_eight = pmul(internal::pchebevl<T, 25>::run(psub(pdiv(pset1<T>(32.0), y), pset1<T>(2.0)), B), prsqrt(y));
329 // TODO: Perhaps instead check whether all packet elements are in
330 // [-8, 8] and evaluate a branch based off of that. It's possible
331 // in practice most elements are in this region.
332 y = pselect(pcmp_le(y, pset1<T>(8.0)), y_le_eight, y_gt_eight);
333 return pselect(pcmp_lt(x, pset1<T>(0.0)), pnegate(y), y);
334 }
335};
336
337template <typename T>
338struct bessel_i1e_impl {
339 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_i1e<T>::run(x); }
340};
341
342template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
343struct generic_i1 {
344 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
345 // Evaluating i1(x) = exp(|x|) * i1e(x) can prematurely cause intermediate overflow for large |x|
346 // i.e. 88.7228 < |x| <= 91.9063 for float
347 // 709.7827 < |x| <= 713.9876 for double
348 // Instead, use i1(x) = exp(|x|/2) * (exp(|x|/2) * i1e(x)). Cutting |x| in half keeps the intermediate result
349 // finite for all finite results.
350 const T ax = pabs(x);
351 const T i1e = generic_i1e<T, ScalarType>::run(x);
352 const T half_exp = pexp(pmul(pset1<T>(ScalarType(0.5)), ax));
353 T scaled = pmul(half_exp, i1e);
354#if defined(__FAST_MATH__) || defined(__ASSOCIATIVE_MATH__) || EIGEN_COMP_NVHPC
355 // Reassociating back to (exp(|x|/2) * exp(|x|/2)) * i1e(x) would reintroduce the overflow.
356 pbarrier(scaled);
357#endif
358 // i1(+-inf) = +-inf; the scaled product would be inf * 0 = NaN.
359 return pselect(pcmp_eq(ax, pinf<T>()), x, pmul(half_exp, scaled));
360 }
361};
362
363template <typename T>
364struct bessel_i1_impl {
365 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_i1<T>::run(x); }
366};
367
368template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
369struct generic_k0e {
370 EIGEN_STATIC_ASSERT((std::is_same<T, T>::value == false), THIS_TYPE_IS_NOT_SUPPORTED)
371
372 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T&) { return ScalarType(0); }
373};
374
375template <typename T>
376struct generic_k0e<T, float> {
377 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
378 /* k0ef.c
379 * Modified Bessel function, third kind, order zero,
380 * exponentially scaled
381 *
382 *
383 *
384 * SYNOPSIS:
385 *
386 * float x, y, k0ef();
387 *
388 * y = k0ef( x );
389 *
390 *
391 *
392 * DESCRIPTION:
393 *
394 * Returns exponentially scaled modified Bessel function
395 * of the third kind of order zero of the argument.
396 *
397 *
398 *
399 * ACCURACY:
400 *
401 * Relative error:
402 * arithmetic domain # trials peak rms
403 * IEEE 0, 30 30000 8.1e-7 7.8e-8
404 * See k0().
405 *
406 */
407
408 const float A[] = {1.90451637722020886025E-9f, 2.53479107902614945675E-7f, 2.28621210311945178607E-5f,
409 1.26461541144692592338E-3f, 3.59799365153615016266E-2f, 3.44289899924628486886E-1f,
410 -5.35327393233902768720E-1f};
411
412 const float B[] = {-1.69753450938905987466E-9f, 8.57403401741422608519E-9f, -4.66048989768794782956E-8f,
413 2.76681363944501510342E-7f, -1.83175552271911948767E-6f, 1.39498137188764993662E-5f,
414 -1.28495495816278026384E-4f, 1.56988388573005337491E-3f, -3.14481013119645005427E-2f,
415 2.44030308206595545468E0f};
416 const T MAXNUM = pset1<T>(NumTraits<float>::infinity());
417 const T two = pset1<T>(2.0);
418 T x_le_two = internal::pchebevl<T, 7>::run(pmadd(x, x, pset1<T>(-2.0)), A);
419 x_le_two = pmadd(generic_i0<T, float>::run(x), pnegate(plog(pmul(pset1<T>(0.5), x))), x_le_two);
420 x_le_two = pmul(pexp(x), x_le_two);
421 T x_gt_two = pmul(internal::pchebevl<T, 10>::run(psub(pdiv(pset1<T>(8.0), x), two), B), prsqrt(x));
422 return pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, pselect(pcmp_le(x, two), x_le_two, x_gt_two));
423 }
424};
425
426template <typename T>
427struct generic_k0e<T, double> {
428 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
429 /* k0e.c
430 * Modified Bessel function, third kind, order zero,
431 * exponentially scaled
432 *
433 *
434 *
435 * SYNOPSIS:
436 *
437 * double x, y, k0e();
438 *
439 * y = k0e( x );
440 *
441 *
442 *
443 * DESCRIPTION:
444 *
445 * Returns exponentially scaled modified Bessel function
446 * of the third kind of order zero of the argument.
447 *
448 *
449 *
450 * ACCURACY:
451 *
452 * Relative error:
453 * arithmetic domain # trials peak rms
454 * IEEE 0, 30 30000 1.4e-15 1.4e-16
455 * See k0().
456 *
457 */
458
459 const double A[] = {1.37446543561352307156E-16, 4.25981614279661018399E-14, 1.03496952576338420167E-11,
460 1.90451637722020886025E-9, 2.53479107902614945675E-7, 2.28621210311945178607E-5,
461 1.26461541144692592338E-3, 3.59799365153615016266E-2, 3.44289899924628486886E-1,
462 -5.35327393233902768720E-1};
463 const double B[] = {5.30043377268626276149E-18, -1.64758043015242134646E-17, 5.21039150503902756861E-17,
464 -1.67823109680541210385E-16, 5.51205597852431940784E-16, -1.84859337734377901440E-15,
465 6.34007647740507060557E-15, -2.22751332699166985548E-14, 8.03289077536357521100E-14,
466 -2.98009692317273043925E-13, 1.14034058820847496303E-12, -4.51459788337394416547E-12,
467 1.85594911495471785253E-11, -7.95748924447710747776E-11, 3.57739728140030116597E-10,
468 -1.69753450938905987466E-9, 8.57403401741422608519E-9, -4.66048989768794782956E-8,
469 2.76681363944501510342E-7, -1.83175552271911948767E-6, 1.39498137188764993662E-5,
470 -1.28495495816278026384E-4, 1.56988388573005337491E-3, -3.14481013119645005427E-2,
471 2.44030308206595545468E0};
472 const T MAXNUM = pset1<T>(NumTraits<double>::infinity());
473 const T two = pset1<T>(2.0);
474 T x_le_two = internal::pchebevl<T, 10>::run(pmadd(x, x, pset1<T>(-2.0)), A);
475 x_le_two = pmadd(generic_i0<T, double>::run(x), pmul(pset1<T>(-1.0), plog(pmul(pset1<T>(0.5), x))), x_le_two);
476 x_le_two = pmul(pexp(x), x_le_two);
477 x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two);
478 T x_gt_two = pmul(internal::pchebevl<T, 25>::run(psub(pdiv(pset1<T>(8.0), x), two), B), prsqrt(x));
479 return pselect(pcmp_le(x, two), x_le_two, x_gt_two);
480 }
481};
482
483template <typename T>
484struct bessel_k0e_impl {
485 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_k0e<T>::run(x); }
486};
487
488template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
489struct generic_k0 {
490 EIGEN_STATIC_ASSERT((std::is_same<T, T>::value == false), THIS_TYPE_IS_NOT_SUPPORTED)
491
492 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T&) { return ScalarType(0); }
493};
494
495template <typename T>
496struct generic_k0<T, float> {
497 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
498 /* k0f.c
499 * Modified Bessel function, third kind, order zero
500 *
501 *
502 *
503 * SYNOPSIS:
504 *
505 * float x, y, k0f();
506 *
507 * y = k0f( x );
508 *
509 *
510 *
511 * DESCRIPTION:
512 *
513 * Returns modified Bessel function of the third kind
514 * of order zero of the argument.
515 *
516 * The range is partitioned into the two intervals [0,8] and
517 * (8, infinity). Chebyshev polynomial expansions are employed
518 * in each interval.
519 *
520 *
521 *
522 * ACCURACY:
523 *
524 * Tested at 2000 random points between 0 and 8. Peak absolute
525 * error (relative when K0 > 1) was 1.46e-14; rms, 4.26e-15.
526 * Relative error:
527 * arithmetic domain # trials peak rms
528 * IEEE 0, 30 30000 7.8e-7 8.5e-8
529 *
530 * ERROR MESSAGES:
531 *
532 * message condition value returned
533 * K0 domain x <= 0 MAXNUM
534 *
535 */
536
537 const float A[] = {1.90451637722020886025E-9f, 2.53479107902614945675E-7f, 2.28621210311945178607E-5f,
538 1.26461541144692592338E-3f, 3.59799365153615016266E-2f, 3.44289899924628486886E-1f,
539 -5.35327393233902768720E-1f};
540
541 const float B[] = {-1.69753450938905987466E-9f, 8.57403401741422608519E-9f, -4.66048989768794782956E-8f,
542 2.76681363944501510342E-7f, -1.83175552271911948767E-6f, 1.39498137188764993662E-5f,
543 -1.28495495816278026384E-4f, 1.56988388573005337491E-3f, -3.14481013119645005427E-2f,
544 2.44030308206595545468E0f};
545 const T MAXNUM = pset1<T>(NumTraits<float>::infinity());
546 const T two = pset1<T>(2.0);
547 T x_le_two = internal::pchebevl<T, 7>::run(pmadd(x, x, pset1<T>(-2.0)), A);
548 x_le_two = pmadd(generic_i0<T, float>::run(x), pnegate(plog(pmul(pset1<T>(0.5), x))), x_le_two);
549 x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two);
550 T x_gt_two =
551 pmul(pmul(pexp(pnegate(x)), internal::pchebevl<T, 10>::run(psub(pdiv(pset1<T>(8.0), x), two), B)), prsqrt(x));
552 return pselect(pcmp_le(x, two), x_le_two, x_gt_two);
553 }
554};
555
556template <typename T>
557struct generic_k0<T, double> {
558 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
559 /*
560 *
561 * Modified Bessel function, third kind, order zero,
562 * exponentially scaled
563 *
564 *
565 *
566 * SYNOPSIS:
567 *
568 * double x, y, k0();
569 *
570 * y = k0( x );
571 *
572 *
573 *
574 * DESCRIPTION:
575 *
576 * Returns exponentially scaled modified Bessel function
577 * of the third kind of order zero of the argument.
578 *
579 *
580 *
581 * ACCURACY:
582 *
583 * Relative error:
584 * arithmetic domain # trials peak rms
585 * IEEE 0, 30 30000 1.4e-15 1.4e-16
586 * See k0().
587 *
588 */
589 const double A[] = {1.37446543561352307156E-16, 4.25981614279661018399E-14, 1.03496952576338420167E-11,
590 1.90451637722020886025E-9, 2.53479107902614945675E-7, 2.28621210311945178607E-5,
591 1.26461541144692592338E-3, 3.59799365153615016266E-2, 3.44289899924628486886E-1,
592 -5.35327393233902768720E-1};
593 const double B[] = {5.30043377268626276149E-18, -1.64758043015242134646E-17, 5.21039150503902756861E-17,
594 -1.67823109680541210385E-16, 5.51205597852431940784E-16, -1.84859337734377901440E-15,
595 6.34007647740507060557E-15, -2.22751332699166985548E-14, 8.03289077536357521100E-14,
596 -2.98009692317273043925E-13, 1.14034058820847496303E-12, -4.51459788337394416547E-12,
597 1.85594911495471785253E-11, -7.95748924447710747776E-11, 3.57739728140030116597E-10,
598 -1.69753450938905987466E-9, 8.57403401741422608519E-9, -4.66048989768794782956E-8,
599 2.76681363944501510342E-7, -1.83175552271911948767E-6, 1.39498137188764993662E-5,
600 -1.28495495816278026384E-4, 1.56988388573005337491E-3, -3.14481013119645005427E-2,
601 2.44030308206595545468E0};
602 const T MAXNUM = pset1<T>(NumTraits<double>::infinity());
603 const T two = pset1<T>(2.0);
604 T x_le_two = internal::pchebevl<T, 10>::run(pmadd(x, x, pset1<T>(-2.0)), A);
605 x_le_two = pmadd(generic_i0<T, double>::run(x), pnegate(plog(pmul(pset1<T>(0.5), x))), x_le_two);
606 x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two);
607 T x_gt_two = pmul(pmul(pexp(-x), internal::pchebevl<T, 25>::run(psub(pdiv(pset1<T>(8.0), x), two), B)), prsqrt(x));
608 return pselect(pcmp_le(x, two), x_le_two, x_gt_two);
609 }
610};
611
612template <typename T>
613struct bessel_k0_impl {
614 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_k0<T>::run(x); }
615};
616
617template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
618struct generic_k1e {
619 EIGEN_STATIC_ASSERT((std::is_same<T, T>::value == false), THIS_TYPE_IS_NOT_SUPPORTED)
620
621 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T&) { return ScalarType(0); }
622};
623
624template <typename T>
625struct generic_k1e<T, float> {
626 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
627 /* k1ef.c
628 *
629 * Modified Bessel function, third kind, order one,
630 * exponentially scaled
631 *
632 *
633 *
634 * SYNOPSIS:
635 *
636 * float x, y, k1ef();
637 *
638 * y = k1ef( x );
639 *
640 *
641 *
642 * DESCRIPTION:
643 *
644 * Returns exponentially scaled modified Bessel function
645 * of the third kind of order one of the argument:
646 *
647 * k1e(x) = exp(x) * k1(x).
648 *
649 *
650 *
651 * ACCURACY:
652 *
653 * Relative error:
654 * arithmetic domain # trials peak rms
655 * IEEE 0, 30 30000 4.9e-7 6.7e-8
656 * See k1().
657 *
658 */
659
660 const float A[] = {-2.21338763073472585583E-8f, -2.43340614156596823496E-6f, -1.73028895751305206302E-4f,
661 -6.97572385963986435018E-3f, -1.22611180822657148235E-1f, -3.53155960776544875667E-1f,
662 1.52530022733894777053E0f};
663 const float B[] = {2.01504975519703286596E-9f, -1.03457624656780970260E-8f, 5.74108412545004946722E-8f,
664 -3.50196060308781257119E-7f, 2.40648494783721712015E-6f, -1.93619797416608296024E-5f,
665 1.95215518471351631108E-4f, -2.85781685962277938680E-3f, 1.03923736576817238437E-1f,
666 2.72062619048444266945E0f};
667 const T MAXNUM = pset1<T>(NumTraits<float>::infinity());
668 const T two = pset1<T>(2.0);
669 T x_le_two = pdiv(internal::pchebevl<T, 7>::run(pmadd(x, x, pset1<T>(-2.0)), A), x);
670 x_le_two = pmadd(generic_i1<T, float>::run(x), plog(pmul(pset1<T>(0.5), x)), x_le_two);
671 x_le_two = pmul(x_le_two, pexp(x));
672 x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two);
673 T x_gt_two = pmul(internal::pchebevl<T, 10>::run(psub(pdiv(pset1<T>(8.0), x), two), B), prsqrt(x));
674 return pselect(pcmp_le(x, two), x_le_two, x_gt_two);
675 }
676};
677
678template <typename T>
679struct generic_k1e<T, double> {
680 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
681 /* k1e.c
682 *
683 * Modified Bessel function, third kind, order one,
684 * exponentially scaled
685 *
686 *
687 *
688 * SYNOPSIS:
689 *
690 * double x, y, k1e();
691 *
692 * y = k1e( x );
693 *
694 *
695 *
696 * DESCRIPTION:
697 *
698 * Returns exponentially scaled modified Bessel function
699 * of the third kind of order one of the argument:
700 *
701 * k1e(x) = exp(x) * k1(x).
702 *
703 *
704 *
705 * ACCURACY:
706 *
707 * Relative error:
708 * arithmetic domain # trials peak rms
709 * IEEE 0, 30 30000 7.8e-16 1.2e-16
710 * See k1().
711 *
712 */
713 const double A[] = {-7.02386347938628759343E-18, -2.42744985051936593393E-15, -6.66690169419932900609E-13,
714 -1.41148839263352776110E-10, -2.21338763073472585583E-8, -2.43340614156596823496E-6,
715 -1.73028895751305206302E-4, -6.97572385963986435018E-3, -1.22611180822657148235E-1,
716 -3.53155960776544875667E-1, 1.52530022733894777053E0};
717 const double B[] = {-5.75674448366501715755E-18, 1.79405087314755922667E-17, -5.68946255844285935196E-17,
718 1.83809354436663880070E-16, -6.05704724837331885336E-16, 2.03870316562433424052E-15,
719 -7.01983709041831346144E-15, 2.47715442448130437068E-14, -8.97670518232499435011E-14,
720 3.34841966607842919884E-13, -1.28917396095102890680E-12, 5.13963967348173025100E-12,
721 -2.12996783842756842877E-11, 9.21831518760500529508E-11, -4.19035475934189648750E-10,
722 2.01504975519703286596E-9, -1.03457624656780970260E-8, 5.74108412545004946722E-8,
723 -3.50196060308781257119E-7, 2.40648494783721712015E-6, -1.93619797416608296024E-5,
724 1.95215518471351631108E-4, -2.85781685962277938680E-3, 1.03923736576817238437E-1,
725 2.72062619048444266945E0};
726 const T MAXNUM = pset1<T>(NumTraits<double>::infinity());
727 const T two = pset1<T>(2.0);
728 T x_le_two = pdiv(internal::pchebevl<T, 11>::run(pmadd(x, x, pset1<T>(-2.0)), A), x);
729 x_le_two = pmadd(generic_i1<T, double>::run(x), plog(pmul(pset1<T>(0.5), x)), x_le_two);
730 x_le_two = pmul(x_le_two, pexp(x));
731 x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two);
732 T x_gt_two = pmul(internal::pchebevl<T, 25>::run(psub(pdiv(pset1<T>(8.0), x), two), B), prsqrt(x));
733 return pselect(pcmp_le(x, two), x_le_two, x_gt_two);
734 }
735};
736
737template <typename T>
738struct bessel_k1e_impl {
739 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_k1e<T>::run(x); }
740};
741
742template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
743struct generic_k1 {
744 EIGEN_STATIC_ASSERT((std::is_same<T, T>::value == false), THIS_TYPE_IS_NOT_SUPPORTED)
745
746 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T&) { return ScalarType(0); }
747};
748
749template <typename T>
750struct generic_k1<T, float> {
751 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
752 /* k1f.c
753 * Modified Bessel function, third kind, order one
754 *
755 *
756 *
757 * SYNOPSIS:
758 *
759 * float x, y, k1f();
760 *
761 * y = k1f( x );
762 *
763 *
764 *
765 * DESCRIPTION:
766 *
767 * Computes the modified Bessel function of the third kind
768 * of order one of the argument.
769 *
770 * The range is partitioned into the two intervals [0,2] and
771 * (2, infinity). Chebyshev polynomial expansions are employed
772 * in each interval.
773 *
774 *
775 *
776 * ACCURACY:
777 *
778 * Relative error:
779 * arithmetic domain # trials peak rms
780 * IEEE 0, 30 30000 4.6e-7 7.6e-8
781 *
782 * ERROR MESSAGES:
783 *
784 * message condition value returned
785 * k1 domain x <= 0 MAXNUM
786 *
787 */
788
789 const float A[] = {-2.21338763073472585583E-8f, -2.43340614156596823496E-6f, -1.73028895751305206302E-4f,
790 -6.97572385963986435018E-3f, -1.22611180822657148235E-1f, -3.53155960776544875667E-1f,
791 1.52530022733894777053E0f};
792 const float B[] = {2.01504975519703286596E-9f, -1.03457624656780970260E-8f, 5.74108412545004946722E-8f,
793 -3.50196060308781257119E-7f, 2.40648494783721712015E-6f, -1.93619797416608296024E-5f,
794 1.95215518471351631108E-4f, -2.85781685962277938680E-3f, 1.03923736576817238437E-1f,
795 2.72062619048444266945E0f};
796 const T MAXNUM = pset1<T>(NumTraits<float>::infinity());
797 const T two = pset1<T>(2.0);
798 T x_le_two = pdiv(internal::pchebevl<T, 7>::run(pmadd(x, x, pset1<T>(-2.0)), A), x);
799 x_le_two = pmadd(generic_i1<T, float>::run(x), plog(pmul(pset1<T>(0.5), x)), x_le_two);
800 x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two);
801 T x_gt_two =
802 pmul(pexp(pnegate(x)), pmul(internal::pchebevl<T, 10>::run(psub(pdiv(pset1<T>(8.0), x), two), B), prsqrt(x)));
803 return pselect(pcmp_le(x, two), x_le_two, x_gt_two);
804 }
805};
806
807template <typename T>
808struct generic_k1<T, double> {
809 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
810 /* k1.c
811 * Modified Bessel function, third kind, order one
812 *
813 *
814 *
815 * SYNOPSIS:
816 *
817 * float x, y, k1f();
818 *
819 * y = k1f( x );
820 *
821 *
822 *
823 * DESCRIPTION:
824 *
825 * Computes the modified Bessel function of the third kind
826 * of order one of the argument.
827 *
828 * The range is partitioned into the two intervals [0,2] and
829 * (2, infinity). Chebyshev polynomial expansions are employed
830 * in each interval.
831 *
832 *
833 *
834 * ACCURACY:
835 *
836 * Relative error:
837 * arithmetic domain # trials peak rms
838 * IEEE 0, 30 30000 4.6e-7 7.6e-8
839 *
840 * ERROR MESSAGES:
841 *
842 * message condition value returned
843 * k1 domain x <= 0 MAXNUM
844 *
845 */
846 const double A[] = {-7.02386347938628759343E-18, -2.42744985051936593393E-15, -6.66690169419932900609E-13,
847 -1.41148839263352776110E-10, -2.21338763073472585583E-8, -2.43340614156596823496E-6,
848 -1.73028895751305206302E-4, -6.97572385963986435018E-3, -1.22611180822657148235E-1,
849 -3.53155960776544875667E-1, 1.52530022733894777053E0};
850 const double B[] = {-5.75674448366501715755E-18, 1.79405087314755922667E-17, -5.68946255844285935196E-17,
851 1.83809354436663880070E-16, -6.05704724837331885336E-16, 2.03870316562433424052E-15,
852 -7.01983709041831346144E-15, 2.47715442448130437068E-14, -8.97670518232499435011E-14,
853 3.34841966607842919884E-13, -1.28917396095102890680E-12, 5.13963967348173025100E-12,
854 -2.12996783842756842877E-11, 9.21831518760500529508E-11, -4.19035475934189648750E-10,
855 2.01504975519703286596E-9, -1.03457624656780970260E-8, 5.74108412545004946722E-8,
856 -3.50196060308781257119E-7, 2.40648494783721712015E-6, -1.93619797416608296024E-5,
857 1.95215518471351631108E-4, -2.85781685962277938680E-3, 1.03923736576817238437E-1,
858 2.72062619048444266945E0};
859 const T MAXNUM = pset1<T>(NumTraits<double>::infinity());
860 const T two = pset1<T>(2.0);
861 T x_le_two = pdiv(internal::pchebevl<T, 11>::run(pmadd(x, x, pset1<T>(-2.0)), A), x);
862 x_le_two = pmadd(generic_i1<T, double>::run(x), plog(pmul(pset1<T>(0.5), x)), x_le_two);
863 x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), MAXNUM, x_le_two);
864 T x_gt_two = pmul(pexp(-x), pmul(internal::pchebevl<T, 25>::run(psub(pdiv(pset1<T>(8.0), x), two), B), prsqrt(x)));
865 return pselect(pcmp_le(x, two), x_le_two, x_gt_two);
866 }
867};
868
869template <typename T>
870struct bessel_k1_impl {
871 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_k1<T>::run(x); }
872};
873
874template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
875struct generic_j0 {
876 EIGEN_STATIC_ASSERT((std::is_same<T, T>::value == false), THIS_TYPE_IS_NOT_SUPPORTED)
877
878 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T&) { return ScalarType(0); }
879};
880
881template <typename T>
882struct generic_j0<T, float> {
883 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
884 /* j0f.c
885 * Bessel function of order zero
886 *
887 *
888 *
889 * SYNOPSIS:
890 *
891 * float x, y, j0f();
892 *
893 * y = j0f( x );
894 *
895 *
896 *
897 * DESCRIPTION:
898 *
899 * Returns Bessel function of order zero of the argument.
900 *
901 * The domain is divided into the intervals [0, 2] and
902 * (2, infinity). In the first interval the following polynomial
903 * approximation is used:
904 *
905 *
906 * 2 2 2
907 * (w - r ) (w - r ) (w - r ) P(w)
908 * 1 2 3
909 *
910 * 2
911 * where w = x and the three r's are zeros of the function.
912 *
913 * In the second interval, the modulus and phase are approximated
914 * by polynomials of the form Modulus(x) = sqrt(1/x) Q(1/x)
915 * and Phase(x) = x + 1/x R(1/x^2) - pi/4. The function is
916 *
917 * j0(x) = Modulus(x) cos( Phase(x) ).
918 *
919 *
920 *
921 * ACCURACY:
922 *
923 * Absolute error:
924 * arithmetic domain # trials peak rms
925 * IEEE 0, 2 100000 1.3e-7 3.6e-8
926 * IEEE 2, 32 100000 1.9e-7 5.4e-8
927 *
928 */
929
930 const float JP[] = {-6.068350350393235E-008f, 6.388945720783375E-006f, -3.969646342510940E-004f,
931 1.332913422519003E-002f, -1.729150680240724E-001f};
932 const float MO[] = {-6.838999669318810E-002f, 1.864949361379502E-001f, -2.145007480346739E-001f,
933 1.197549369473540E-001f, -3.560281861530129E-003f, -4.969382655296620E-002f,
934 -3.355424622293709E-006f, 7.978845717621440E-001f};
935 const float PH[] = {3.242077816988247E+001f, -3.630592630518434E+001f, 1.756221482109099E+001f,
936 -4.974978466280903E+000f, 1.001973420681837E+000f, -1.939906941791308E-001f,
937 6.490598792654666E-002f, -1.249992184872738E-001f};
938 const T DR1 = pset1<T>(5.78318596294678452118f);
939 const T NEG_PIO4F = pset1<T>(-0.7853981633974483096f); /* -pi / 4 */
940 T y = pabs(x);
941 T z = pmul(y, y);
942 T y_le_two = pselect(pcmp_lt(y, pset1<T>(1.0e-3f)), pmadd(z, pset1<T>(-0.25f), pset1<T>(1.0f)),
943 pmul(psub(z, DR1), internal::ppolevl<T, 4>::run(z, JP)));
944 T q = pdiv(pset1<T>(1.0f), y);
945 T w = prsqrt(y);
946 T p = pmul(w, internal::ppolevl<T, 7>::run(q, MO));
947 w = pmul(q, q);
948 T yn = pmadd(q, internal::ppolevl<T, 7>::run(w, PH), NEG_PIO4F);
949 T y_gt_two = pmul(p, pcos(padd(yn, y)));
950 return pselect(pcmp_le(y, pset1<T>(2.0)), y_le_two, y_gt_two);
951 }
952};
953
954template <typename T>
955struct generic_j0<T, double> {
956 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
957 /* j0.c
958 * Bessel function of order zero
959 *
960 *
961 *
962 * SYNOPSIS:
963 *
964 * double x, y, j0();
965 *
966 * y = j0( x );
967 *
968 *
969 *
970 * DESCRIPTION:
971 *
972 * Returns Bessel function of order zero of the argument.
973 *
974 * The domain is divided into the intervals [0, 5] and
975 * (5, infinity). In the first interval the following rational
976 * approximation is used:
977 *
978 *
979 * 2 2
980 * (w - r ) (w - r ) P (w) / Q (w)
981 * 1 2 3 8
982 *
983 * 2
984 * where w = x and the two r's are zeros of the function.
985 *
986 * In the second interval, the Hankel asymptotic expansion
987 * is employed with two rational functions of degree 6/6
988 * and 7/7.
989 *
990 *
991 *
992 * ACCURACY:
993 *
994 * Absolute error:
995 * arithmetic domain # trials peak rms
996 * DEC 0, 30 10000 4.4e-17 6.3e-18
997 * IEEE 0, 30 60000 4.2e-16 1.1e-16
998 *
999 */
1000 const double PP[] = {7.96936729297347051624E-4, 8.28352392107440799803E-2, 1.23953371646414299388E0,
1001 5.44725003058768775090E0, 8.74716500199817011941E0, 5.30324038235394892183E0,
1002 9.99999999999999997821E-1};
1003 const double PQ[] = {9.24408810558863637013E-4, 8.56288474354474431428E-2, 1.25352743901058953537E0,
1004 5.47097740330417105182E0, 8.76190883237069594232E0, 5.30605288235394617618E0,
1005 1.00000000000000000218E0};
1006 const double QP[] = {-1.13663838898469149931E-2, -1.28252718670509318512E0, -1.95539544257735972385E1,
1007 -9.32060152123768231369E1, -1.77681167980488050595E2, -1.47077505154951170175E2,
1008 -5.14105326766599330220E1, -6.05014350600728481186E0};
1009 const double QQ[] = {1.00000000000000000000E0, 6.43178256118178023184E1, 8.56430025976980587198E2,
1010 3.88240183605401609683E3, 7.24046774195652478189E3, 5.93072701187316984827E3,
1011 2.06209331660327847417E3, 2.42005740240291393179E2};
1012 const double RP[] = {-4.79443220978201773821E9, 1.95617491946556577543E12, -2.49248344360967716204E14,
1013 9.70862251047306323952E15};
1014 const double RQ[] = {1.00000000000000000000E0, 4.99563147152651017219E2, 1.73785401676374683123E5,
1015 4.84409658339962045305E7, 1.11855537045356834862E10, 2.11277520115489217587E12,
1016 3.10518229857422583814E14, 3.18121955943204943306E16, 1.71086294081043136091E18};
1017 const T DR1 = pset1<T>(5.78318596294678452118E0);
1018 const T DR2 = pset1<T>(3.04712623436620863991E1);
1019 const T SQ2OPI = pset1<T>(7.9788456080286535587989E-1); /* sqrt(2 / pi) */
1020 const T NEG_PIO4 = pset1<T>(-0.7853981633974483096); /* -pi / 4 */
1021
1022 T y = pabs(x);
1023 T z = pmul(y, y);
1024 T y_le_five = pselect(pcmp_lt(y, pset1<T>(1.0e-5)), pmadd(z, pset1<T>(-0.25), pset1<T>(1.0)),
1025 pmul(pmul(psub(z, DR1), psub(z, DR2)),
1026 pdiv(internal::ppolevl<T, 3>::run(z, RP), internal::ppolevl<T, 8>::run(z, RQ))));
1027 T s = pdiv(pset1<T>(25.0), z);
1028 T p = pdiv(internal::ppolevl<T, 6>::run(s, PP), internal::ppolevl<T, 6>::run(s, PQ));
1029 T q = pdiv(internal::ppolevl<T, 7>::run(s, QP), internal::ppolevl<T, 7>::run(s, QQ));
1030 T yn = padd(y, NEG_PIO4);
1031 T w = pdiv(pset1<T>(-5.0), y);
1032 p = pmadd(p, pcos(yn), pmul(w, pmul(q, psin(yn))));
1033 T y_gt_five = pmul(p, pmul(SQ2OPI, prsqrt(y)));
1034 return pselect(pcmp_le(y, pset1<T>(5.0)), y_le_five, y_gt_five);
1035 }
1036};
1037
1038template <typename T>
1039struct bessel_j0_impl {
1040 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_j0<T>::run(x); }
1041};
1042
1043template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
1044struct generic_y0 {
1045 EIGEN_STATIC_ASSERT((std::is_same<T, T>::value == false), THIS_TYPE_IS_NOT_SUPPORTED)
1046
1047 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T&) { return ScalarType(0); }
1048};
1049
1050template <typename T>
1051struct generic_y0<T, float> {
1052 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
1053 /* j0f.c
1054 * Bessel function of the second kind, order zero
1055 *
1056 *
1057 *
1058 * SYNOPSIS:
1059 *
1060 * float x, y, y0f();
1061 *
1062 * y = y0f( x );
1063 *
1064 *
1065 *
1066 * DESCRIPTION:
1067 *
1068 * Returns Bessel function of the second kind, of order
1069 * zero, of the argument.
1070 *
1071 * The domain is divided into the intervals [0, 2] and
1072 * (2, infinity). In the first interval a rational approximation
1073 * R(x) is employed to compute
1074 *
1075 * 2 2 2
1076 * y0(x) = (w - r ) (w - r ) (w - r ) R(x) + 2/pi ln(x) j0(x).
1077 * 1 2 3
1078 *
1079 * Thus a call to j0() is required. The three zeros are removed
1080 * from R(x) to improve its numerical stability.
1081 *
1082 * In the second interval, the modulus and phase are approximated
1083 * by polynomials of the form Modulus(x) = sqrt(1/x) Q(1/x)
1084 * and Phase(x) = x + 1/x S(1/x^2) - pi/4. Then the function is
1085 *
1086 * y0(x) = Modulus(x) sin( Phase(x) ).
1087 *
1088 *
1089 *
1090 *
1091 * ACCURACY:
1092 *
1093 * Absolute error, when y0(x) < 1; else relative error:
1094 *
1095 * arithmetic domain # trials peak rms
1096 * IEEE 0, 2 100000 2.4e-7 3.4e-8
1097 * IEEE 2, 32 100000 1.8e-7 5.3e-8
1098 *
1099 */
1100
1101 const float YP[] = {9.454583683980369E-008f, -9.413212653797057E-006f, 5.344486707214273E-004f,
1102 -1.584289289821316E-002f, 1.707584643733568E-001f};
1103 const float MO[] = {-6.838999669318810E-002f, 1.864949361379502E-001f, -2.145007480346739E-001f,
1104 1.197549369473540E-001f, -3.560281861530129E-003f, -4.969382655296620E-002f,
1105 -3.355424622293709E-006f, 7.978845717621440E-001f};
1106 const float PH[] = {3.242077816988247E+001f, -3.630592630518434E+001f, 1.756221482109099E+001f,
1107 -4.974978466280903E+000f, 1.001973420681837E+000f, -1.939906941791308E-001f,
1108 6.490598792654666E-002f, -1.249992184872738E-001f};
1109 const T YZ1 = pset1<T>(0.43221455686510834878f);
1110 const T TWOOPI = pset1<T>(0.636619772367581343075535f); /* 2 / pi */
1111 const T NEG_PIO4F = pset1<T>(-0.7853981633974483096f); /* -pi / 4 */
1112 const T NEG_MAXNUM = pset1<T>(-NumTraits<float>::infinity());
1113 T z = pmul(x, x);
1114 T x_le_two = pmul(TWOOPI, pmul(plog(x), generic_j0<T, float>::run(x)));
1115 x_le_two = pmadd(psub(z, YZ1), internal::ppolevl<T, 4>::run(z, YP), x_le_two);
1116 x_le_two = pselect(pcmp_le(x, pset1<T>(0.0)), NEG_MAXNUM, x_le_two);
1117 T q = pdiv(pset1<T>(1.0), x);
1118 T w = prsqrt(x);
1119 T p = pmul(w, internal::ppolevl<T, 7>::run(q, MO));
1120 T u = pmul(q, q);
1121 T xn = pmadd(q, internal::ppolevl<T, 7>::run(u, PH), NEG_PIO4F);
1122 T x_gt_two = pmul(p, psin(padd(xn, x)));
1123 return pselect(pcmp_le(x, pset1<T>(2.0)), x_le_two, x_gt_two);
1124 }
1125};
1126
1127template <typename T>
1128struct generic_y0<T, double> {
1129 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
1130 /* j0.c
1131 * Bessel function of the second kind, order zero
1132 *
1133 *
1134 *
1135 * SYNOPSIS:
1136 *
1137 * double x, y, y0();
1138 *
1139 * y = y0( x );
1140 *
1141 *
1142 *
1143 * DESCRIPTION:
1144 *
1145 * Returns Bessel function of the second kind, of order
1146 * zero, of the argument.
1147 *
1148 * The domain is divided into the intervals [0, 5] and
1149 * (5, infinity). In the first interval a rational approximation
1150 * R(x) is employed to compute
1151 * y0(x) = R(x) + 2 * log(x) * j0(x) / PI.
1152 * Thus a call to j0() is required.
1153 *
1154 * In the second interval, the Hankel asymptotic expansion
1155 * is employed with two rational functions of degree 6/6
1156 * and 7/7.
1157 *
1158 *
1159 *
1160 * ACCURACY:
1161 *
1162 * Absolute error, when y0(x) < 1; else relative error:
1163 *
1164 * arithmetic domain # trials peak rms
1165 * DEC 0, 30 9400 7.0e-17 7.9e-18
1166 * IEEE 0, 30 30000 1.3e-15 1.6e-16
1167 *
1168 */
1169 const double PP[] = {7.96936729297347051624E-4, 8.28352392107440799803E-2, 1.23953371646414299388E0,
1170 5.44725003058768775090E0, 8.74716500199817011941E0, 5.30324038235394892183E0,
1171 9.99999999999999997821E-1};
1172 const double PQ[] = {9.24408810558863637013E-4, 8.56288474354474431428E-2, 1.25352743901058953537E0,
1173 5.47097740330417105182E0, 8.76190883237069594232E0, 5.30605288235394617618E0,
1174 1.00000000000000000218E0};
1175 const double QP[] = {-1.13663838898469149931E-2, -1.28252718670509318512E0, -1.95539544257735972385E1,
1176 -9.32060152123768231369E1, -1.77681167980488050595E2, -1.47077505154951170175E2,
1177 -5.14105326766599330220E1, -6.05014350600728481186E0};
1178 const double QQ[] = {1.00000000000000000000E0, 6.43178256118178023184E1, 8.56430025976980587198E2,
1179 3.88240183605401609683E3, 7.24046774195652478189E3, 5.93072701187316984827E3,
1180 2.06209331660327847417E3, 2.42005740240291393179E2};
1181 const double YP[] = {1.55924367855235737965E4, -1.46639295903971606143E7, 5.43526477051876500413E9,
1182 -9.82136065717911466409E11, 8.75906394395366999549E13, -3.46628303384729719441E15,
1183 4.42733268572569800351E16, -1.84950800436986690637E16};
1184 const double YQ[] = {1.00000000000000000000E0, 1.04128353664259848412E3, 6.26107330137134956842E5,
1185 2.68919633393814121987E8, 8.64002487103935000337E10, 2.02979612750105546709E13,
1186 3.17157752842975028269E15, 2.50596256172653059228E17};
1187 const T SQ2OPI = pset1<T>(7.9788456080286535587989E-1); /* sqrt(2 / pi) */
1188 const T TWOOPI = pset1<T>(0.636619772367581343075535); /* 2 / pi */
1189 const T NEG_PIO4 = pset1<T>(-0.7853981633974483096); /* -pi / 4 */
1190 const T NEG_MAXNUM = pset1<T>(-NumTraits<double>::infinity());
1191
1192 T z = pmul(x, x);
1193 T x_le_five = pdiv(internal::ppolevl<T, 7>::run(z, YP), internal::ppolevl<T, 7>::run(z, YQ));
1194 x_le_five = pmadd(pmul(TWOOPI, plog(x)), generic_j0<T, double>::run(x), x_le_five);
1195 x_le_five = pselect(pcmp_le(x, pset1<T>(0.0)), NEG_MAXNUM, x_le_five);
1196 T s = pdiv(pset1<T>(25.0), z);
1197 T p = pdiv(internal::ppolevl<T, 6>::run(s, PP), internal::ppolevl<T, 6>::run(s, PQ));
1198 T q = pdiv(internal::ppolevl<T, 7>::run(s, QP), internal::ppolevl<T, 7>::run(s, QQ));
1199 T xn = padd(x, NEG_PIO4);
1200 T w = pdiv(pset1<T>(5.0), x);
1201 p = pmadd(p, psin(xn), pmul(w, pmul(q, pcos(xn))));
1202 T x_gt_five = pmul(p, pmul(SQ2OPI, prsqrt(x)));
1203 return pselect(pcmp_le(x, pset1<T>(5.0)), x_le_five, x_gt_five);
1204 }
1205};
1206
1207template <typename T>
1208struct bessel_y0_impl {
1209 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_y0<T>::run(x); }
1210};
1211
1212template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
1213struct generic_j1 {
1214 EIGEN_STATIC_ASSERT((std::is_same<T, T>::value == false), THIS_TYPE_IS_NOT_SUPPORTED)
1215
1216 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T&) { return ScalarType(0); }
1217};
1218
1219template <typename T>
1220struct generic_j1<T, float> {
1221 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
1222 /* j1f.c
1223 * Bessel function of order one
1224 *
1225 *
1226 *
1227 * SYNOPSIS:
1228 *
1229 * float x, y, j1f();
1230 *
1231 * y = j1f( x );
1232 *
1233 *
1234 *
1235 * DESCRIPTION:
1236 *
1237 * Returns Bessel function of order one of the argument.
1238 *
1239 * The domain is divided into the intervals [0, 2] and
1240 * (2, infinity). In the first interval a polynomial approximation
1241 * 2
1242 * (w - r ) x P(w)
1243 * 1
1244 * 2
1245 * is used, where w = x and r is the first zero of the function.
1246 *
1247 * In the second interval, the modulus and phase are approximated
1248 * by polynomials of the form Modulus(x) = sqrt(1/x) Q(1/x)
1249 * and Phase(x) = x + 1/x R(1/x^2) - 3pi/4. The function is
1250 *
1251 * j0(x) = Modulus(x) cos( Phase(x) ).
1252 *
1253 *
1254 *
1255 * ACCURACY:
1256 *
1257 * Absolute error:
1258 * arithmetic domain # trials peak rms
1259 * IEEE 0, 2 100000 1.2e-7 2.5e-8
1260 * IEEE 2, 32 100000 2.0e-7 5.3e-8
1261 *
1262 *
1263 */
1264
1265 const float JP[] = {-4.878788132172128E-009f, 6.009061827883699E-007f, -4.541343896997497E-005f,
1266 1.937383947804541E-003f, -3.405537384615824E-002f};
1267 const float MO1[] = {6.913942741265801E-002f, -2.284801500053359E-001f, 3.138238455499697E-001f,
1268 -2.102302420403875E-001f, 5.435364690523026E-003f, 1.493389585089498E-001f,
1269 4.976029650847191E-006f, 7.978845453073848E-001f};
1270 const float PH1[] = {-4.497014141919556E+001f, 5.073465654089319E+001f, -2.485774108720340E+001f,
1271 7.222973196770240E+000f, -1.544842782180211E+000f, 3.503787691653334E-001f,
1272 -1.637986776941202E-001f, 3.749989509080821E-001f};
1273 const T Z1 = pset1<T>(1.46819706421238932572E1f);
1274 const T NEG_THPIO4F = pset1<T>(-2.35619449019234492885f); /* -3*pi/4 */
1275
1276 T y = pabs(x);
1277 T z = pmul(y, y);
1278 T y_le_two = pmul(psub(z, Z1), pmul(x, internal::ppolevl<T, 4>::run(z, JP)));
1279 T q = pdiv(pset1<T>(1.0f), y);
1280 T w = prsqrt(y);
1281 T p = pmul(w, internal::ppolevl<T, 7>::run(q, MO1));
1282 w = pmul(q, q);
1283 T yn = pmadd(q, internal::ppolevl<T, 7>::run(w, PH1), NEG_THPIO4F);
1284 T y_gt_two = pmul(p, pcos(padd(yn, y)));
1285 // j1 is an odd function. This implementation differs from cephes to
1286 // take this fact into account. Cephes returns -j1(x) for y > 2 range.
1287 y_gt_two = pselect(pcmp_lt(x, pset1<T>(0.0f)), pnegate(y_gt_two), y_gt_two);
1288 return pselect(pcmp_le(y, pset1<T>(2.0f)), y_le_two, y_gt_two);
1289 }
1290};
1291
1292template <typename T>
1293struct generic_j1<T, double> {
1294 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
1295 /* j1.c
1296 * Bessel function of order one
1297 *
1298 *
1299 *
1300 * SYNOPSIS:
1301 *
1302 * double x, y, j1();
1303 *
1304 * y = j1( x );
1305 *
1306 *
1307 *
1308 * DESCRIPTION:
1309 *
1310 * Returns Bessel function of order one of the argument.
1311 *
1312 * The domain is divided into the intervals [0, 8] and
1313 * (8, infinity). In the first interval a 24 term Chebyshev
1314 * expansion is used. In the second, the asymptotic
1315 * trigonometric representation is employed using two
1316 * rational functions of degree 5/5.
1317 *
1318 *
1319 *
1320 * ACCURACY:
1321 *
1322 * Absolute error:
1323 * arithmetic domain # trials peak rms
1324 * DEC 0, 30 10000 4.0e-17 1.1e-17
1325 * IEEE 0, 30 30000 2.6e-16 1.1e-16
1326 *
1327 */
1328 const double PP[] = {7.62125616208173112003E-4, 7.31397056940917570436E-2, 1.12719608129684925192E0,
1329 5.11207951146807644818E0, 8.42404590141772420927E0, 5.21451598682361504063E0,
1330 1.00000000000000000254E0};
1331 const double PQ[] = {5.71323128072548699714E-4, 6.88455908754495404082E-2, 1.10514232634061696926E0,
1332 5.07386386128601488557E0, 8.39985554327604159757E0, 5.20982848682361821619E0,
1333 9.99999999999999997461E-1};
1334 const double QP[] = {5.10862594750176621635E-2, 4.98213872951233449420E0, 7.58238284132545283818E1,
1335 3.66779609360150777800E2, 7.10856304998926107277E2, 5.97489612400613639965E2,
1336 2.11688757100572135698E2, 2.52070205858023719784E1};
1337 const double QQ[] = {1.00000000000000000000E0, 7.42373277035675149943E1, 1.05644886038262816351E3,
1338 4.98641058337653607651E3, 9.56231892404756170795E3, 7.99704160447350683650E3,
1339 2.82619278517639096600E3, 3.36093607810698293419E2};
1340 const double RP[] = {-8.99971225705559398224E8, 4.52228297998194034323E11, -7.27494245221818276015E13,
1341 3.68295732863852883286E15};
1342 const double RQ[] = {1.00000000000000000000E0, 6.20836478118054335476E2, 2.56987256757748830383E5,
1343 8.35146791431949253037E7, 2.21511595479792499675E10, 4.74914122079991414898E12,
1344 7.84369607876235854894E14, 8.95222336184627338078E16, 5.32278620332680085395E18};
1345 const T Z1 = pset1<T>(1.46819706421238932572E1);
1346 const T Z2 = pset1<T>(4.92184563216946036703E1);
1347 const T NEG_THPIO4 = pset1<T>(-2.35619449019234492885); /* -3*pi/4 */
1348 const T SQ2OPI = pset1<T>(7.9788456080286535587989E-1); /* sqrt(2 / pi) */
1349 T y = pabs(x);
1350 T z = pmul(y, y);
1351 T y_le_five = pdiv(internal::ppolevl<T, 3>::run(z, RP), internal::ppolevl<T, 8>::run(z, RQ));
1352 y_le_five = pmul(pmul(pmul(y_le_five, x), psub(z, Z1)), psub(z, Z2));
1353 T s = pdiv(pset1<T>(25.0), z);
1354 T p = pdiv(internal::ppolevl<T, 6>::run(s, PP), internal::ppolevl<T, 6>::run(s, PQ));
1355 T q = pdiv(internal::ppolevl<T, 7>::run(s, QP), internal::ppolevl<T, 7>::run(s, QQ));
1356 T yn = padd(y, NEG_THPIO4);
1357 T w = pdiv(pset1<T>(-5.0), y);
1358 p = pmadd(p, pcos(yn), pmul(w, pmul(q, psin(yn))));
1359 T y_gt_five = pmul(p, pmul(SQ2OPI, prsqrt(y)));
1360 // j1 is an odd function. This implementation differs from cephes to
1361 // take this fact into account. Cephes returns -j1(x) for y > 5 range.
1362 y_gt_five = pselect(pcmp_lt(x, pset1<T>(0.0)), pnegate(y_gt_five), y_gt_five);
1363 return pselect(pcmp_le(y, pset1<T>(5.0)), y_le_five, y_gt_five);
1364 }
1365};
1366
1367template <typename T>
1368struct bessel_j1_impl {
1369 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_j1<T>::run(x); }
1370};
1371
1372template <typename T, typename ScalarType = typename unpacket_traits<T>::type>
1373struct generic_y1 {
1374 EIGEN_STATIC_ASSERT((std::is_same<T, T>::value == false), THIS_TYPE_IS_NOT_SUPPORTED)
1375
1376 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T&) { return ScalarType(0); }
1377};
1378
1379template <typename T>
1380struct generic_y1<T, float> {
1381 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
1382 /* j1f.c
1383 * Bessel function of second kind of order one
1384 *
1385 *
1386 *
1387 * SYNOPSIS:
1388 *
1389 * double x, y, y1();
1390 *
1391 * y = y1( x );
1392 *
1393 *
1394 *
1395 * DESCRIPTION:
1396 *
1397 * Returns Bessel function of the second kind of order one
1398 * of the argument.
1399 *
1400 * The domain is divided into the intervals [0, 2] and
1401 * (2, infinity). In the first interval a rational approximation
1402 * R(x) is employed to compute
1403 *
1404 * 2
1405 * y0(x) = (w - r ) x R(x^2) + 2/pi (ln(x) j1(x) - 1/x) .
1406 * 1
1407 *
1408 * Thus a call to j1() is required.
1409 *
1410 * In the second interval, the modulus and phase are approximated
1411 * by polynomials of the form Modulus(x) = sqrt(1/x) Q(1/x)
1412 * and Phase(x) = x + 1/x S(1/x^2) - 3pi/4. Then the function is
1413 *
1414 * y0(x) = Modulus(x) sin( Phase(x) ).
1415 *
1416 *
1417 *
1418 *
1419 * ACCURACY:
1420 *
1421 * Absolute error:
1422 * arithmetic domain # trials peak rms
1423 * IEEE 0, 2 100000 2.2e-7 4.6e-8
1424 * IEEE 2, 32 100000 1.9e-7 5.3e-8
1425 *
1426 * (error criterion relative when |y1| > 1).
1427 *
1428 */
1429
1430 const float YP[] = {8.061978323326852E-009f, -9.496460629917016E-007f, 6.719543806674249E-005f,
1431 -2.641785726447862E-003f, 4.202369946500099E-002f};
1432 const float MO1[] = {6.913942741265801E-002f, -2.284801500053359E-001f, 3.138238455499697E-001f,
1433 -2.102302420403875E-001f, 5.435364690523026E-003f, 1.493389585089498E-001f,
1434 4.976029650847191E-006f, 7.978845453073848E-001f};
1435 const float PH1[] = {-4.497014141919556E+001f, 5.073465654089319E+001f, -2.485774108720340E+001f,
1436 7.222973196770240E+000f, -1.544842782180211E+000f, 3.503787691653334E-001f,
1437 -1.637986776941202E-001f, 3.749989509080821E-001f};
1438 const T YO1 = pset1<T>(4.66539330185668857532f);
1439 const T NEG_THPIO4F = pset1<T>(-2.35619449019234492885f); /* -3*pi/4 */
1440 const T TWOOPI = pset1<T>(0.636619772367581343075535f); /* 2/pi */
1441 const T NEG_MAXNUM = pset1<T>(-NumTraits<float>::infinity());
1442
1443 T z = pmul(x, x);
1444 T x_le_two = pmul(psub(z, YO1), internal::ppolevl<T, 4>::run(z, YP));
1445 x_le_two = pmadd(x_le_two, x, pmul(TWOOPI, pmadd(generic_j1<T, float>::run(x), plog(x), pdiv(pset1<T>(-1.0f), x))));
1446 x_le_two = pselect(pcmp_le(x, pset1<T>(0.0f)), NEG_MAXNUM, x_le_two);
1447
1448 T q = pdiv(pset1<T>(1.0), x);
1449 T w = prsqrt(x);
1450 T p = pmul(w, internal::ppolevl<T, 7>::run(q, MO1));
1451 w = pmul(q, q);
1452 T xn = pmadd(q, internal::ppolevl<T, 7>::run(w, PH1), NEG_THPIO4F);
1453 T x_gt_two = pmul(p, psin(padd(xn, x)));
1454 return pselect(pcmp_le(x, pset1<T>(2.0)), x_le_two, x_gt_two);
1455 }
1456};
1457
1458template <typename T>
1459struct generic_y1<T, double> {
1460 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T& x) {
1461 /* j1.c
1462 * Bessel function of second kind of order one
1463 *
1464 *
1465 *
1466 * SYNOPSIS:
1467 *
1468 * double x, y, y1();
1469 *
1470 * y = y1( x );
1471 *
1472 *
1473 *
1474 * DESCRIPTION:
1475 *
1476 * Returns Bessel function of the second kind of order one
1477 * of the argument.
1478 *
1479 * The domain is divided into the intervals [0, 8] and
1480 * (8, infinity). In the first interval a 25 term Chebyshev
1481 * expansion is used, and a call to j1() is required.
1482 * In the second, the asymptotic trigonometric representation
1483 * is employed using two rational functions of degree 5/5.
1484 *
1485 *
1486 *
1487 * ACCURACY:
1488 *
1489 * Absolute error:
1490 * arithmetic domain # trials peak rms
1491 * DEC 0, 30 10000 8.6e-17 1.3e-17
1492 * IEEE 0, 30 30000 1.0e-15 1.3e-16
1493 *
1494 * (error criterion relative when |y1| > 1).
1495 *
1496 */
1497 const double PP[] = {7.62125616208173112003E-4, 7.31397056940917570436E-2, 1.12719608129684925192E0,
1498 5.11207951146807644818E0, 8.42404590141772420927E0, 5.21451598682361504063E0,
1499 1.00000000000000000254E0};
1500 const double PQ[] = {5.71323128072548699714E-4, 6.88455908754495404082E-2, 1.10514232634061696926E0,
1501 5.07386386128601488557E0, 8.39985554327604159757E0, 5.20982848682361821619E0,
1502 9.99999999999999997461E-1};
1503 const double QP[] = {5.10862594750176621635E-2, 4.98213872951233449420E0, 7.58238284132545283818E1,
1504 3.66779609360150777800E2, 7.10856304998926107277E2, 5.97489612400613639965E2,
1505 2.11688757100572135698E2, 2.52070205858023719784E1};
1506 const double QQ[] = {1.00000000000000000000E0, 7.42373277035675149943E1, 1.05644886038262816351E3,
1507 4.98641058337653607651E3, 9.56231892404756170795E3, 7.99704160447350683650E3,
1508 2.82619278517639096600E3, 3.36093607810698293419E2};
1509 const double YP[] = {1.26320474790178026440E9, -6.47355876379160291031E11, 1.14509511541823727583E14,
1510 -8.12770255501325109621E15, 2.02439475713594898196E17, -7.78877196265950026825E17};
1511 const double YQ[] = {1.00000000000000000000E0, 5.94301592346128195359E2, 2.35564092943068577943E5,
1512 7.34811944459721705660E7, 1.87601316108706159478E10, 3.88231277496238566008E12,
1513 6.20557727146953693363E14, 6.87141087355300489866E16, 3.97270608116560655612E18};
1514 const T SQ2OPI = pset1<T>(.79788456080286535588);
1515 const T NEG_THPIO4 = pset1<T>(-2.35619449019234492885); /* -3*pi/4 */
1516 const T TWOOPI = pset1<T>(0.636619772367581343075535); /* 2/pi */
1517 const T NEG_MAXNUM = pset1<T>(-NumTraits<double>::infinity());
1518
1519 T z = pmul(x, x);
1520 T x_le_five = pdiv(internal::ppolevl<T, 5>::run(z, YP), internal::ppolevl<T, 8>::run(z, YQ));
1521 x_le_five =
1522 pmadd(x_le_five, x, pmul(TWOOPI, pmadd(generic_j1<T, double>::run(x), plog(x), pdiv(pset1<T>(-1.0), x))));
1523
1524 x_le_five = pselect(pcmp_le(x, pset1<T>(0.0)), NEG_MAXNUM, x_le_five);
1525 T s = pdiv(pset1<T>(25.0), z);
1526 T p = pdiv(internal::ppolevl<T, 6>::run(s, PP), internal::ppolevl<T, 6>::run(s, PQ));
1527 T q = pdiv(internal::ppolevl<T, 7>::run(s, QP), internal::ppolevl<T, 7>::run(s, QQ));
1528 T xn = padd(x, NEG_THPIO4);
1529 T w = pdiv(pset1<T>(5.0), x);
1530 p = pmadd(p, psin(xn), pmul(w, pmul(q, pcos(xn))));
1531 T x_gt_five = pmul(p, pmul(SQ2OPI, prsqrt(x)));
1532 return pselect(pcmp_le(x, pset1<T>(5.0)), x_le_five, x_gt_five);
1533 }
1534};
1535
1536template <typename T>
1537struct bessel_y1_impl {
1538 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE T run(const T x) { return generic_y1<T>::run(x); }
1539};
1540
1541} // end namespace internal
1542
1543namespace numext {
1544
1545template <typename Scalar>
1546EIGEN_DEVICE_FUNC inline auto bessel_i0(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_i0, Scalar)::run(x)) {
1547 return EIGEN_MATHFUNC_IMPL(bessel_i0, Scalar)::run(x);
1548}
1549
1550template <typename Scalar>
1551EIGEN_DEVICE_FUNC inline auto bessel_i0e(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_i0e, Scalar)::run(x)) {
1552 return EIGEN_MATHFUNC_IMPL(bessel_i0e, Scalar)::run(x);
1553}
1554
1555template <typename Scalar>
1556EIGEN_DEVICE_FUNC inline auto bessel_i1(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_i1, Scalar)::run(x)) {
1557 return EIGEN_MATHFUNC_IMPL(bessel_i1, Scalar)::run(x);
1558}
1559
1560template <typename Scalar>
1561EIGEN_DEVICE_FUNC inline auto bessel_i1e(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_i1e, Scalar)::run(x)) {
1562 return EIGEN_MATHFUNC_IMPL(bessel_i1e, Scalar)::run(x);
1563}
1564
1565template <typename Scalar>
1566EIGEN_DEVICE_FUNC inline auto bessel_k0(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_k0, Scalar)::run(x)) {
1567 return EIGEN_MATHFUNC_IMPL(bessel_k0, Scalar)::run(x);
1568}
1569
1570template <typename Scalar>
1571EIGEN_DEVICE_FUNC inline auto bessel_k0e(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_k0e, Scalar)::run(x)) {
1572 return EIGEN_MATHFUNC_IMPL(bessel_k0e, Scalar)::run(x);
1573}
1574
1575template <typename Scalar>
1576EIGEN_DEVICE_FUNC inline auto bessel_k1(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_k1, Scalar)::run(x)) {
1577 return EIGEN_MATHFUNC_IMPL(bessel_k1, Scalar)::run(x);
1578}
1579
1580template <typename Scalar>
1581EIGEN_DEVICE_FUNC inline auto bessel_k1e(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_k1e, Scalar)::run(x)) {
1582 return EIGEN_MATHFUNC_IMPL(bessel_k1e, Scalar)::run(x);
1583}
1584
1585template <typename Scalar>
1586EIGEN_DEVICE_FUNC inline auto bessel_j0(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_j0, Scalar)::run(x)) {
1587 return EIGEN_MATHFUNC_IMPL(bessel_j0, Scalar)::run(x);
1588}
1589
1590template <typename Scalar>
1591EIGEN_DEVICE_FUNC inline auto bessel_y0(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_y0, Scalar)::run(x)) {
1592 return EIGEN_MATHFUNC_IMPL(bessel_y0, Scalar)::run(x);
1593}
1594
1595template <typename Scalar>
1596EIGEN_DEVICE_FUNC inline auto bessel_j1(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_j1, Scalar)::run(x)) {
1597 return EIGEN_MATHFUNC_IMPL(bessel_j1, Scalar)::run(x);
1598}
1599
1600template <typename Scalar>
1601EIGEN_DEVICE_FUNC inline auto bessel_y1(const Scalar& x) -> decltype(EIGEN_MATHFUNC_IMPL(bessel_y1, Scalar)::run(x)) {
1602 return EIGEN_MATHFUNC_IMPL(bessel_y1, Scalar)::run(x);
1603}
1604
1605} // end namespace numext
1606
1607} // end namespace Eigen
1608
1609#endif // EIGEN_BESSEL_FUNCTIONS_H
Namespace containing all symbols from the Eigen library.