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