bessel_functions.cpp File Reference
#include "main.h"
#include "../Eigen/SpecialFunctions"

Functions

template<typename X , typename Y >
void verify_component_wise (const X &x, const Y &y)
 
template<typename ArrayType >
void array_bessel_functions ()
 
 EIGEN_DECLARE_TEST (bessel_functions)
 

Function Documentation

◆ array_bessel_functions()

template<typename ArrayType >
void array_bessel_functions ( )
26  {
27  // Test Bessel function i0. Reference results obtained with SciPy.
28  {
29  ArrayType x(21);
30  ArrayType expected(21);
31  ArrayType res(21);
32 
33  x << -20.0, -18.0, -16.0, -14.0, -12.0, -10.0, -8.0, -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0,
34  16.0, 18.0, 20.0;
35 
36  expected << 4.35582826e+07, 6.21841242e+06, 8.93446228e+05, 1.29418563e+05, 1.89489253e+04, 2.81571663e+03,
37  4.27564116e+02, 6.72344070e+01, 1.13019220e+01, 2.27958530e+00, 1.00000000e+00, 2.27958530e+00, 1.13019220e+01,
38  6.72344070e+01, 4.27564116e+02, 2.81571663e+03, 1.89489253e+04, 1.29418563e+05, 8.93446228e+05, 6.21841242e+06,
39  4.35582826e+07;
40 
42  }
43 
44  // Test Bessel function i0e. Reference results obtained with SciPy.
45  {
46  ArrayType x(21);
47  ArrayType expected(21);
48  ArrayType res(21);
49 
50  x << -20.0, -18.0, -16.0, -14.0, -12.0, -10.0, -8.0, -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0,
51  16.0, 18.0, 20.0;
52 
53  expected << 0.0897803118848, 0.0947062952128, 0.100544127361, 0.107615251671, 0.116426221213, 0.127833337163,
54  0.143431781857, 0.16665743264, 0.207001921224, 0.308508322554, 1.0, 0.308508322554, 0.207001921224,
55  0.16665743264, 0.143431781857, 0.127833337163, 0.116426221213, 0.107615251671, 0.100544127361, 0.0947062952128,
56  0.0897803118848;
57 
59  }
60 
61  // Test Bessel function i1. Reference results obtained with SciPy.
62  {
63  ArrayType x(21);
64  ArrayType expected(21);
65  ArrayType res(21);
66 
67  x << -20.0, -18.0, -16.0, -14.0, -12.0, -10.0, -8.0, -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0,
68  16.0, 18.0, 20.0;
69 
70  expected << -4.24549734e+07, -6.04313324e+06, -8.65059436e+05, -1.24707259e+05, -1.81413488e+04, -2.67098830e+03,
71  -3.99873137e+02, -6.13419368e+01, -9.75946515e+00, -1.59063685e+00, 0.00000000e+00, 1.59063685e+00,
72  9.75946515e+00, 6.13419368e+01, 3.99873137e+02, 2.67098830e+03, 1.81413488e+04, 1.24707259e+05, 8.65059436e+05,
73  6.04313324e+06, 4.24549734e+07;
74 
76  }
77 
78  // Test Bessel function i1e. Reference results obtained with SciPy.
79  {
80  ArrayType x(21);
81  ArrayType expected(21);
82  ArrayType res(21);
83 
84  x << -20.0, -18.0, -16.0, -14.0, -12.0, -10.0, -8.0, -6.0, -4.0, -2.0, 0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0,
85  16.0, 18.0, 20.0;
86 
87  expected << -0.0875062221833, -0.092036796872, -0.0973496147565, -0.103697667463, -0.11146429929, -0.121262681384,
88  -0.134142493293, -0.152051459309, -0.178750839502, -0.215269289249, 0.0, 0.215269289249, 0.178750839502,
89  0.152051459309, 0.134142493293, 0.121262681384, 0.11146429929, 0.103697667463, 0.0973496147565, 0.092036796872,
90  0.0875062221833;
91 
93  }
94 
95  // Test Bessel function j0. Reference results obtained with SciPy.
96  {
97  ArrayType x(77);
98  ArrayType expected(77);
99  ArrayType res(77);
100 
101  x << -38., -37., -36., -35., -34., -33., -32., -31., -30., -29., -28., -27., -26., -25., -24., -23., -22., -21.,
102  -20., -19., -18., -17., -16., -15., -14., -13., -12., -11., -10., -9., -8., -7., -6., -5., -4., -3., -2., -1.,
103  0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23.,
104  24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38.;
105 
106  expected << 0.11433274, 0.01086237, -0.10556738, -0.12684568, -0.03042119, 0.09727067, 0.13807901, 0.05120815,
107  -0.08636798, -0.14784876, -0.07315701, 0.07274192, 0.15599932, 0.09626678, -0.05623027, -0.16241278,
108  -0.12065148, 0.03657907, 0.16702466, 0.14662944, -0.01335581, -0.16985425, -0.17489907, -0.01422447, 0.17107348,
109  0.2069261, 0.04768931, -0.1711903, -0.24593576, -0.09033361, 0.17165081, 0.30007927, 0.15064526, -0.17759677,
110  -0.39714981, -0.26005195, 0.22389078, 0.76519769, 1., 0.76519769, 0.22389078, -0.26005195, -0.39714981,
111  -0.17759677, 0.15064526, 0.30007927, 0.17165081, -0.09033361, -0.24593576, -0.1711903, 0.04768931, 0.2069261,
112  0.17107348, -0.01422447, -0.17489907, -0.16985425, -0.01335581, 0.14662944, 0.16702466, 0.03657907, -0.12065148,
113  -0.16241278, -0.05623027, 0.09626678, 0.15599932, 0.07274192, -0.07315701, -0.14784876, -0.08636798, 0.05120815,
114  0.13807901, 0.09727067, -0.03042119, -0.12684568, -0.10556738, 0.01086237, 0.11433274;
115 
117  }
118 
119  // Test Bessel function j1. Reference results obtained with SciPy.
120  {
121  ArrayType x(81);
122  ArrayType expected(81);
123  ArrayType res(81);
124 
125  x << -40., -39., -38., -37., -36., -35., -34., -33., -32., -31., -30., -29., -28., -27., -26., -25., -24., -23.,
126  -22., -21., -20., -19., -18., -17., -16., -15., -14., -13., -12., -11., -10., -9., -8., -7., -6., -5., -4., -3.,
127  -2., -1., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21.,
128  22., 23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40.;
129 
130  expected << -0.12603832, -0.0640561, 0.05916189, 0.13058004, 0.08232981, -0.04399094, -0.13297118, -0.10061965,
131  0.02658903, 0.13302432, 0.11875106, -0.0069342, -0.13055149, -0.13658472, -0.01504573, 0.12535025, 0.15403807,
132  0.03951932, -0.11717779, -0.17112027, -0.06683312, 0.10570143, 0.18799489, 0.09766849, -0.09039718, -0.20510404,
133  -0.13337515, 0.07031805, 0.2234471, 0.1767853, -0.04347275, -0.24531179, -0.23463635, 0.00468282, 0.27668386,
134  0.32757914, 0.06604333, -0.33905896, -0.57672481, -0.44005059, 0., 0.44005059, 0.57672481, 0.33905896,
135  -0.06604333, -0.32757914, -0.27668386, -0.00468282, 0.23463635, 0.24531179, 0.04347275, -0.1767853, -0.2234471,
136  -0.07031805, 0.13337515, 0.20510404, 0.09039718, -0.09766849, -0.18799489, -0.10570143, 0.06683312, 0.17112027,
137  0.11717779, -0.03951932, -0.15403807, -0.12535025, 0.01504573, 0.13658472, 0.13055149, 0.0069342, -0.11875106,
138  -0.13302432, -0.02658903, 0.10061965, 0.13297118, 0.04399094, -0.08232981, -0.13058004, -0.05916189, 0.0640561,
139  0.12603832;
140 
142  }
143  // Test Bessel function k0e. Reference results obtained with SciPy.
144  {
145  ArrayType x(42);
146  ArrayType expected(42);
147  ArrayType res(42);
148 
149  x << 0.25, 0.5, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22.,
150  23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40.;
151 
152  expected << 1.97933385, 1.52410939, 1.14446308, 0.84156822, 0.6977616, 0.60929767, 0.54780756, 0.50186313,
153  0.4658451, 0.43662302, 0.41229555, 0.39163193, 0.3737955, 0.35819488, 0.34439865, 0.33208364, 0.32100235,
154  0.31096159, 0.30180802, 0.29341821, 0.28569149, 0.27854488, 0.2719092, 0.26572635, 0.25994703, 0.25452917,
155  0.2494366, 0.24463801, 0.24010616, 0.23581722, 0.23175022, 0.22788667, 0.22421014, 0.22070602, 0.21736123,
156  0.21416406, 0.21110397, 0.20817141, 0.20535778, 0.20265524, 0.20005668, 0.19755558;
157 
159  }
160 
161  // Test Bessel function k0. Reference results obtained with SciPy.
162  {
163  ArrayType x(42);
164  ArrayType expected(42);
165  ArrayType res(42);
166 
167  x << 0.25, 0.5, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22.,
168  23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40.;
169 
170  expected << 1.54150675, 0.92441907, 4.21024438e-01, 1.13893873e-01, 3.47395044e-02, 1.11596761e-02, 3.69109833e-03,
171  1.24399433e-03, 4.24795742e-04, 1.46470705e-04, 5.08813130e-05, 1.77800623e-05, 6.24302055e-06, 2.20082540e-06,
172  7.78454386e-07, 2.76137082e-07, 9.81953648e-08, 3.49941166e-08, 1.24946640e-08, 4.46875334e-09, 1.60067129e-09,
173  5.74123782e-10, 2.06176797e-10, 7.41235161e-11, 2.66754511e-11, 9.60881878e-12, 3.46416156e-12, 1.24987740e-12,
174  4.51286453e-13, 1.63053459e-13, 5.89495073e-14, 2.13247750e-14, 7.71838266e-15, 2.79505752e-15, 1.01266123e-15,
175  3.67057597e-16, 1.33103515e-16, 4.82858338e-17, 1.75232770e-17, 6.36161716e-18, 2.31029936e-18, 8.39286110e-19;
176 
178  }
179 
180  // Test Bessel function k0e. Reference results obtained with SciPy.
181  {
182  ArrayType x(42);
183  ArrayType expected(42);
184  ArrayType res(42);
185 
186  x << 0.25, 0.5, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22.,
187  23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40.;
188 
189  expected << 1.97933385, 1.52410939, 1.14446308, 0.84156822, 0.6977616, 0.60929767, 0.54780756, 0.50186313,
190  0.4658451, 0.43662302, 0.41229555, 0.39163193, 0.3737955, 0.35819488, 0.34439865, 0.33208364, 0.32100235,
191  0.31096159, 0.30180802, 0.29341821, 0.28569149, 0.27854488, 0.2719092, 0.26572635, 0.25994703, 0.25452917,
192  0.2494366, 0.24463801, 0.24010616, 0.23581722, 0.23175022, 0.22788667, 0.22421014, 0.22070602, 0.21736123,
193  0.21416406, 0.21110397, 0.20817141, 0.20535778, 0.20265524, 0.20005668, 0.19755558;
194 
196  }
197 
198  // Test Bessel function k1. Reference results obtained with SciPy.
199  {
200  ArrayType x(42);
201  ArrayType expected(42);
202  ArrayType res(42);
203 
204  x << 0.25, 0.5, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22.,
205  23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40.;
206 
207  expected << 3.74702597, 1.65644112, 6.01907230e-01, 1.39865882e-01, 4.01564311e-02, 1.24834989e-02, 4.04461345e-03,
208  1.34391972e-03, 4.54182487e-04, 1.55369212e-04, 5.36370164e-05, 1.86487735e-05, 6.52086067e-06, 2.29075746e-06,
209  8.07858841e-07, 2.85834365e-07, 1.01417294e-07, 3.60715712e-08, 1.28570417e-08, 4.59124963e-09, 1.64226697e-09,
210  5.88305797e-10, 2.11029922e-10, 7.57898116e-11, 2.72493059e-11, 9.80699893e-12, 3.53277807e-12, 1.27369078e-12,
211  4.59568940e-13, 1.65940011e-13, 5.99574032e-14, 2.16773200e-14, 7.84189960e-15, 2.83839927e-15, 1.02789171e-15,
212  3.72416929e-16, 1.34991783e-16, 4.89519373e-17, 1.77585196e-17, 6.44478588e-18, 2.33973340e-18, 8.49713195e-19;
213 
215  }
216 
217  // Test Bessel function k1e. Reference results obtained with SciPy.
218  {
219  ArrayType x(42);
220  ArrayType expected(42);
221  ArrayType res(42);
222 
223  x << 0.25, 0.5, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22.,
224  23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40.;
225 
226  expected << 4.81127659, 2.73100971, 1.63615349, 1.03347685, 0.80656348, 0.68157595, 0.60027386, 0.54217591,
227  0.49807158, 0.46314909, 0.43462525, 0.41076657, 0.39043094, 0.37283175, 0.35740757, 0.34374563, 0.33153489,
228  0.32053597, 0.31056123, 0.30146131, 0.29311559, 0.2854255, 0.27830958, 0.27169987, 0.26553913, 0.25977879,
229  0.25437733, 0.249299, 0.24451285, 0.23999191, 0.2357126, 0.23165413, 0.22779816, 0.22412841, 0.22063036,
230  0.21729103, 0.21409878, 0.21104314, 0.20811462, 0.20530466, 0.20260547, 0.20000997;
231 
233  }
234 
235  // Test Bessel function y0. Reference results obtained with SciPy.
236  {
237  ArrayType x(42);
238  ArrayType expected(42);
239  ArrayType res(42);
240 
241  x << 0.25, 0.5, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22.,
242  23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40.;
243 
244  expected << -0.93157302, -0.44451873, 0.08825696, 0.51037567, 0.37685001, -0.01694074, -0.30851763, -0.28819468,
245  -0.02594974, 0.22352149, 0.2499367, 0.05567117, -0.16884732, -0.22523731, -0.07820786, 0.12719257, 0.2054643,
246  0.095811, -0.0926372, -0.18755216, -0.10951969, 0.0626406, 0.17020176, 0.1198876, -0.03598179, -0.15283403,
247  -0.12724943, 0.01204463, 0.13521498, 0.13183647, 0.00948116, -0.11729573, -0.13383266, -0.02874248, 0.09913483,
248  0.13340405, 0.04579799, -0.08085609, -0.13071488, -0.06066076, 0.06262353, 0.12593642;
249 
251  }
252 
253  // Test Bessel function y1. Reference results obtained with SciPy.
254  {
255  ArrayType x(42);
256  ArrayType expected(42);
257  ArrayType res(42);
258 
259  x << 0.25, 0.5, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22.,
260  23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40.;
261 
262  expected << -2.70410523, -1.47147239, -0.78121282, -0.10703243, 0.32467442, 0.39792571, 0.14786314, -0.17501034,
263  -0.30266724, -0.15806046, 0.10431458, 0.24901542, 0.16370554, -0.05709922, -0.21008141, -0.16664484, 0.02107363,
264  0.17797517, 0.16720504, 0.00815513, -0.14956011, -0.16551161, -0.03253926, 0.12340586, 0.1616692, 0.05305978,
265  -0.09882996, -0.15579655, -0.07025124, 0.07552213, 0.14803412, 0.08442557, -0.05337283, -0.13854483,
266  -0.09578012, 0.03238588, 0.12751273, 0.10445477, -0.01262946, -0.11514066, -0.11056411, -0.00579351;
267 
269  }
270 }
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
void verify_component_wise(const X &x, const Y &y)
Definition: bessel_functions.cpp:14
#define CALL_SUBTEST(FUNC)
Definition: main.h:382
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
EIGEN_STRONG_INLINE 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
list x
Definition: plotDoE.py:28

References Eigen::bessel_i0(), Eigen::bessel_i0e(), Eigen::bessel_i1(), Eigen::bessel_i1e(), Eigen::bessel_j0(), Eigen::bessel_j1(), Eigen::bessel_k0(), Eigen::bessel_k0e(), Eigen::bessel_k1(), Eigen::bessel_k1e(), Eigen::bessel_y0(), Eigen::bessel_y1(), CALL_SUBTEST, res, verify_component_wise(), and plotDoE::x.

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( bessel_functions  )
272  {
273  CALL_SUBTEST_1(array_bessel_functions<ArrayXf>());
274  CALL_SUBTEST_2(array_bessel_functions<ArrayXd>());
275 }
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10

References CALL_SUBTEST_1, and CALL_SUBTEST_2.

◆ verify_component_wise()

template<typename X , typename Y >
void verify_component_wise ( const X x,
const Y y 
)
14  {
15  for (Index i = 0; i < x.size(); ++i) {
16  if ((numext::isfinite)(y(i))) {
17  VERIFY_IS_APPROX(x(i), y(i));
18  } else if ((numext::isnan)(y(i)))
19  VERIFY((numext::isnan)(x(i)));
20  else
21  VERIFY_IS_EQUAL(x(i), y(i));
22  }
23 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
Scalar * y
Definition: level1_cplx_impl.h:128
#define isfinite(X)
Definition: main.h:111
#define VERIFY(a)
Definition: main.h:362
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
#define isnan(X)
Definition: main.h:109
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83

References i, isfinite, isnan, VERIFY, VERIFY_IS_APPROX, VERIFY_IS_EQUAL, plotDoE::x, and y.

Referenced by array_bessel_functions().