BesselFunctionsFunctors.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com>
5 // Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_BESSELFUNCTIONS_FUNCTORS_H
12 #define EIGEN_BESSELFUNCTIONS_FUNCTORS_H
13 
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
25 template <typename Scalar>
26 struct scalar_bessel_i0_op {
27  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
28  using numext::bessel_i0;
29  return bessel_i0(x);
30  }
31  typedef typename packet_traits<Scalar>::type Packet;
32  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
33  return internal::pbessel_i0(x);
34  }
35 };
36 template <typename Scalar>
37 struct functor_traits<scalar_bessel_i0_op<Scalar> > {
38  enum {
39  // On average, a Chebyshev polynomial of order N=20 is computed.
40  // The cost is N multiplications and 2N additions. We also add
41  // the cost of an additional exp over i0e.
43  PacketAccess = packet_traits<Scalar>::HasBessel
44  };
45 };
46 
52 template <typename Scalar>
53 struct scalar_bessel_i0e_op {
54  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
55  using numext::bessel_i0e;
56  return bessel_i0e(x);
57  }
58  typedef typename packet_traits<Scalar>::type Packet;
59  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
60  return internal::pbessel_i0e(x);
61  }
62 };
63 template <typename Scalar>
64 struct functor_traits<scalar_bessel_i0e_op<Scalar> > {
65  enum {
66  // On average, a Chebyshev polynomial of order N=20 is computed.
67  // The cost is N multiplications and 2N additions.
69  PacketAccess = packet_traits<Scalar>::HasBessel
70  };
71 };
72 
78 template <typename Scalar>
79 struct scalar_bessel_i1_op {
80  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
81  using numext::bessel_i1;
82  return bessel_i1(x);
83  }
84  typedef typename packet_traits<Scalar>::type Packet;
85  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
86  return internal::pbessel_i1(x);
87  }
88 };
89 template <typename Scalar>
90 struct functor_traits<scalar_bessel_i1_op<Scalar> > {
91  enum {
92  // On average, a Chebyshev polynomial of order N=20 is computed.
93  // The cost is N multiplications and 2N additions. We also add
94  // the cost of an additional exp over i1e.
96  PacketAccess = packet_traits<Scalar>::HasBessel
97  };
98 };
99 
105 template <typename Scalar>
106 struct scalar_bessel_i1e_op {
107  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
108  using numext::bessel_i1e;
109  return bessel_i1e(x);
110  }
111  typedef typename packet_traits<Scalar>::type Packet;
112  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
113  return internal::pbessel_i1e(x);
114  }
115 };
116 template <typename Scalar>
117 struct functor_traits<scalar_bessel_i1e_op<Scalar> > {
118  enum {
119  // On average, a Chebyshev polynomial of order N=20 is computed.
120  // The cost is N multiplications and 2N additions.
122  PacketAccess = packet_traits<Scalar>::HasBessel
123  };
124 };
125 
131 template <typename Scalar>
132 struct scalar_bessel_j0_op {
133  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
134  using numext::bessel_j0;
135  return bessel_j0(x);
136  }
137  typedef typename packet_traits<Scalar>::type Packet;
138  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
139  return internal::pbessel_j0(x);
140  }
141 };
142 template <typename Scalar>
143 struct functor_traits<scalar_bessel_j0_op<Scalar> > {
144  enum {
145  // 6 polynomial of order ~N=8 is computed.
146  // The cost is N multiplications and N additions each, along with a
147  // sine, cosine and rsqrt cost.
149  PacketAccess = packet_traits<Scalar>::HasBessel
150  };
151 };
152 
158 template <typename Scalar>
159 struct scalar_bessel_y0_op {
160  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
161  using numext::bessel_y0;
162  return bessel_y0(x);
163  }
164  typedef typename packet_traits<Scalar>::type Packet;
165  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
166  return internal::pbessel_y0(x);
167  }
168 };
169 template <typename Scalar>
170 struct functor_traits<scalar_bessel_y0_op<Scalar> > {
171  enum {
172  // 6 polynomial of order ~N=8 is computed.
173  // The cost is N multiplications and N additions each, along with a
174  // sine, cosine, rsqrt and j0 cost.
176  PacketAccess = packet_traits<Scalar>::HasBessel
177  };
178 };
179 
185 template <typename Scalar>
186 struct scalar_bessel_j1_op {
187  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
188  using numext::bessel_j1;
189  return bessel_j1(x);
190  }
191  typedef typename packet_traits<Scalar>::type Packet;
192  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
193  return internal::pbessel_j1(x);
194  }
195 };
196 template <typename Scalar>
197 struct functor_traits<scalar_bessel_j1_op<Scalar> > {
198  enum {
199  // 6 polynomial of order ~N=8 is computed.
200  // The cost is N multiplications and N additions each, along with a
201  // sine, cosine and rsqrt cost.
203  PacketAccess = packet_traits<Scalar>::HasBessel
204  };
205 };
206 
212 template <typename Scalar>
213 struct scalar_bessel_y1_op {
214  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
215  using numext::bessel_y1;
216  return bessel_y1(x);
217  }
218  typedef typename packet_traits<Scalar>::type Packet;
219  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
220  return internal::pbessel_y1(x);
221  }
222 };
223 template <typename Scalar>
224 struct functor_traits<scalar_bessel_y1_op<Scalar> > {
225  enum {
226  // 6 polynomial of order ~N=8 is computed.
227  // The cost is N multiplications and N additions each, along with a
228  // sine, cosine, rsqrt and j1 cost.
230  PacketAccess = packet_traits<Scalar>::HasBessel
231  };
232 };
233 
239 template <typename Scalar>
240 struct scalar_bessel_k0_op {
241  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
242  using numext::bessel_k0;
243  return bessel_k0(x);
244  }
245  typedef typename packet_traits<Scalar>::type Packet;
246  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
247  return internal::pbessel_k0(x);
248  }
249 };
250 template <typename Scalar>
251 struct functor_traits<scalar_bessel_k0_op<Scalar> > {
252  enum {
253  // On average, a Chebyshev polynomial of order N=10 is computed.
254  // The cost is N multiplications and 2N additions. In addition we compute
255  // i0, a log, exp and prsqrt and sin and cos.
257  PacketAccess = packet_traits<Scalar>::HasBessel
258  };
259 };
260 
266 template <typename Scalar>
267 struct scalar_bessel_k0e_op {
268  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
269  using numext::bessel_k0e;
270  return bessel_k0e(x);
271  }
272  typedef typename packet_traits<Scalar>::type Packet;
273  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
274  return internal::pbessel_k0e(x);
275  }
276 };
277 template <typename Scalar>
278 struct functor_traits<scalar_bessel_k0e_op<Scalar> > {
279  enum {
280  // On average, a Chebyshev polynomial of order N=10 is computed.
281  // The cost is N multiplications and 2N additions. In addition we compute
282  // i0, a log, exp and prsqrt and sin and cos.
284  PacketAccess = packet_traits<Scalar>::HasBessel
285  };
286 };
287 
293 template <typename Scalar>
294 struct scalar_bessel_k1_op {
295  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
296  using numext::bessel_k1;
297  return bessel_k1(x);
298  }
299  typedef typename packet_traits<Scalar>::type Packet;
300  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
301  return internal::pbessel_k1(x);
302  }
303 };
304 template <typename Scalar>
305 struct functor_traits<scalar_bessel_k1_op<Scalar> > {
306  enum {
307  // On average, a Chebyshev polynomial of order N=10 is computed.
308  // The cost is N multiplications and 2N additions. In addition we compute
309  // i1, a log, exp and prsqrt and sin and cos.
311  PacketAccess = packet_traits<Scalar>::HasBessel
312  };
313 };
314 
320 template <typename Scalar>
321 struct scalar_bessel_k1e_op {
322  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
323  using numext::bessel_k1e;
324  return bessel_k1e(x);
325  }
326  typedef typename packet_traits<Scalar>::type Packet;
327  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
328  return internal::pbessel_k1e(x);
329  }
330 };
331 template <typename Scalar>
332 struct functor_traits<scalar_bessel_k1e_op<Scalar> > {
333  enum {
334  // On average, a Chebyshev polynomial of order N=10 is computed.
335  // The cost is N multiplications and 2N additions. In addition we compute
336  // i1, a log, exp and prsqrt and sin and cos.
338  PacketAccess = packet_traits<Scalar>::HasBessel
339  };
340 };
341 
342 
343 } // end namespace internal
344 
345 } // end namespace Eigen
346 
347 #endif // EIGEN_BESSELFUNCTIONS_FUNCTORS_H
IndexedView_or_VectorBlock operator()(const Indices &indices)
#define EIGEN_DEVICE_FUNC
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_i1e(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_y1(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_y0(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_i0(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_i0e(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_k0(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_i1(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_k0e(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_j0(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_j1(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_k1(const Packet &x)
EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet pbessel_k1e(const Packet &x)
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_j1_op< typename Derived::Scalar >, const Derived > bessel_j1(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k0_op< typename Derived::Scalar >, const Derived > bessel_k0(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_y1_op< typename Derived::Scalar >, const Derived > bessel_y1(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_j0_op< typename Derived::Scalar >, const Derived > bessel_j0(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k1_op< typename Derived::Scalar >, const Derived > bessel_k1(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k0e_op< typename Derived::Scalar >, const Derived > bessel_k0e(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_y0_op< typename Derived::Scalar >, const Derived > bessel_y0(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i0_op< typename Derived::Scalar >, const Derived > bessel_i0(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i1_op< typename Derived::Scalar >, const Derived > bessel_i1(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i1e_op< typename Derived::Scalar >, const Derived > bessel_i1e(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i0e_op< typename Derived::Scalar >, const Derived > bessel_i0e(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k1e_op< typename Derived::Scalar >, const Derived > bessel_k1e(const Eigen::ArrayBase< Derived > &x)