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