mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-21 07:19:46 +08:00
Add Bessel functions to SpecialFunctions.
- Split SpecialFunctions files in to a separate BesselFunctions file. In particular add: - Modified bessel functions of the second kind k0, k1, k0e, k1e - Bessel functions of the first kind j0, j1 - Bessel functions of the second kind y0, y1
This commit is contained in:
parent
facdec5aa7
commit
6e215cf109
@ -84,8 +84,7 @@ struct default_packet_traits
|
||||
HasErf = 0,
|
||||
HasErfc = 0,
|
||||
HasNdtri = 0,
|
||||
HasI0e = 0,
|
||||
HasI1e = 0,
|
||||
HasBessel = 0,
|
||||
HasIGamma = 0,
|
||||
HasIGammaDerA = 0,
|
||||
HasGammaSampleDerAlpha = 0,
|
||||
|
@ -73,8 +73,7 @@ template<> struct packet_traits<float> : default_packet_traits
|
||||
HasExpm1 = 1,
|
||||
HasExp = 1,
|
||||
HasNdtri = 1,
|
||||
HasI0e = 1,
|
||||
HasI1e = 1,
|
||||
HasBessel = 1,
|
||||
HasSqrt = 1,
|
||||
HasRsqrt = 1,
|
||||
HasTanh = EIGEN_FAST_MATH,
|
||||
|
@ -99,8 +99,7 @@ template<> struct packet_traits<float> : default_packet_traits
|
||||
HasExpm1 = 1,
|
||||
HasNdtri = 1,
|
||||
#endif
|
||||
HasI0e = 1,
|
||||
HasI1e = 1,
|
||||
HasBessel = 1,
|
||||
HasExp = 1,
|
||||
HasSqrt = EIGEN_FAST_MATH,
|
||||
HasRsqrt = EIGEN_FAST_MATH,
|
||||
|
@ -45,8 +45,7 @@ template<> struct packet_traits<float> : default_packet_traits
|
||||
HasErf = 1,
|
||||
HasErfc = 1,
|
||||
HasNdtri = 1,
|
||||
HasI0e = 1,
|
||||
HasI1e = 1,
|
||||
HasBessel = 1,
|
||||
HasIGamma = 1,
|
||||
HasIGammaDerA = 1,
|
||||
HasGammaSampleDerAlpha = 1,
|
||||
@ -80,8 +79,7 @@ template<> struct packet_traits<double> : default_packet_traits
|
||||
HasErf = 1,
|
||||
HasErfc = 1,
|
||||
HasNdtri = 1,
|
||||
HasI0e = 1,
|
||||
HasI1e = 1,
|
||||
HasBessel = 1,
|
||||
HasIGamma = 1,
|
||||
HasIGammaDerA = 1,
|
||||
HasGammaSampleDerAlpha = 1,
|
||||
|
@ -114,8 +114,7 @@ template<> struct packet_traits<float> : default_packet_traits
|
||||
HasExpm1 = 1,
|
||||
HasNdtri = 1,
|
||||
HasExp = 1,
|
||||
HasI0e = 1,
|
||||
HasI1e = 1,
|
||||
HasBessel = 1,
|
||||
HasSqrt = 1,
|
||||
HasRsqrt = 1,
|
||||
HasTanh = EIGEN_FAST_MATH,
|
||||
|
@ -215,13 +215,26 @@ template<typename Scalar> struct scalar_digamma_op;
|
||||
template<typename Scalar> struct scalar_erf_op;
|
||||
template<typename Scalar> struct scalar_erfc_op;
|
||||
template<typename Scalar> struct scalar_ndtri_op;
|
||||
template<typename Scalar> struct scalar_i0e_op;
|
||||
template<typename Scalar> struct scalar_i1e_op;
|
||||
template<typename Scalar> struct scalar_igamma_op;
|
||||
template<typename Scalar> struct scalar_igammac_op;
|
||||
template<typename Scalar> struct scalar_zeta_op;
|
||||
template<typename Scalar> struct scalar_betainc_op;
|
||||
|
||||
// Bessel functions in SpecialFunctions module
|
||||
template<typename Scalar> struct scalar_bessel_i0_op;
|
||||
template<typename Scalar> struct scalar_bessel_i0e_op;
|
||||
template<typename Scalar> struct scalar_bessel_i1_op;
|
||||
template<typename Scalar> struct scalar_bessel_i1e_op;
|
||||
template<typename Scalar> struct scalar_bessel_j0_op;
|
||||
template<typename Scalar> struct scalar_bessel_y0_op;
|
||||
template<typename Scalar> struct scalar_bessel_j1_op;
|
||||
template<typename Scalar> struct scalar_bessel_y1_op;
|
||||
template<typename Scalar> struct scalar_bessel_k0_op;
|
||||
template<typename Scalar> struct scalar_bessel_k0e_op;
|
||||
template<typename Scalar> struct scalar_bessel_k1_op;
|
||||
template<typename Scalar> struct scalar_bessel_k1e_op;
|
||||
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
struct IOFormat;
|
||||
|
@ -609,8 +609,28 @@ template<typename Scalar,typename Packet> void packetmath_real()
|
||||
CHECK_CWISE1_IF(PacketTraits::HasSqrt, std::sqrt, internal::psqrt);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasSqrt, Scalar(1)/std::sqrt, internal::prsqrt);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasLog, std::log, internal::plog);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasI0e, numext::i0e, internal::pi0e);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasI1e, numext::i1e, internal::pi1e);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::i0, internal::pi0);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::i0e, internal::pi0e);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::i1, internal::pi1);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::i1e, internal::pi1e);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::j0, internal::pj0);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::j1, internal::pj1);
|
||||
|
||||
// Use a smaller data range for the positive bessel operations as these
|
||||
// can have much more error at very small and very large values.
|
||||
for (int i=0; i<size; ++i) {
|
||||
data1[i] = internal::random<Scalar>(0.01,1) * std::pow(
|
||||
Scalar(10), internal::random<Scalar>(-1,2));
|
||||
data2[i] = internal::random<Scalar>(0.01,1) * std::pow(
|
||||
Scalar(10), internal::random<Scalar>(-1,2));
|
||||
}
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::y0, internal::py0);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::y1, internal::py1);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::k0, internal::pk0);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::k0e, internal::pk0e);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::k1, internal::pk1);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasBessel, numext::k1e, internal::pk1e);
|
||||
|
||||
#if EIGEN_HAS_C99_MATH && (__cplusplus > 199711L)
|
||||
CHECK_CWISE1_IF(internal::packet_traits<Scalar>::HasLGamma, std::lgamma, internal::plgamma);
|
||||
CHECK_CWISE1_IF(internal::packet_traits<Scalar>::HasErf, std::erf, internal::perf);
|
||||
@ -945,7 +965,7 @@ EIGEN_DECLARE_TEST(packetmath)
|
||||
{
|
||||
g_first_pass = true;
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
|
||||
|
||||
CALL_SUBTEST_1( runner<float>::run() );
|
||||
CALL_SUBTEST_2( runner<double>::run() );
|
||||
CALL_SUBTEST_3( runner<int>::run() );
|
||||
|
@ -136,15 +136,75 @@ class TensorBase<Derived, ReadOnlyAccessors>
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_i0e_op<Scalar>, const Derived>
|
||||
i0e() const {
|
||||
return unaryExpr(internal::scalar_i0e_op<Scalar>());
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_i0_op<Scalar>, const Derived>
|
||||
i0() const {
|
||||
return unaryExpr(internal::scalar_bessel_i0_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_i1e_op<Scalar>, const Derived>
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_i0e_op<Scalar>, const Derived>
|
||||
i0e() const {
|
||||
return unaryExpr(internal::scalar_bessel_i0e_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_i1_op<Scalar>, const Derived>
|
||||
i1() const {
|
||||
return unaryExpr(internal::scalar_bessel_i1_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_i1e_op<Scalar>, const Derived>
|
||||
i1e() const {
|
||||
return unaryExpr(internal::scalar_i1e_op<Scalar>());
|
||||
return unaryExpr(internal::scalar_bessel_i1e_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_j0_op<Scalar>, const Derived>
|
||||
j0() const {
|
||||
return unaryExpr(internal::scalar_bessel_j0_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_y0_op<Scalar>, const Derived>
|
||||
y0() const {
|
||||
return unaryExpr(internal::scalar_bessel_y0_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_j1_op<Scalar>, const Derived>
|
||||
j1() const {
|
||||
return unaryExpr(internal::scalar_bessel_j1_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_y1_op<Scalar>, const Derived>
|
||||
y1() const {
|
||||
return unaryExpr(internal::scalar_bessel_y1_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_k0_op<Scalar>, const Derived>
|
||||
k0() const {
|
||||
return unaryExpr(internal::scalar_bessel_k0_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_k0e_op<Scalar>, const Derived>
|
||||
k0e() const {
|
||||
return unaryExpr(internal::scalar_bessel_k0e_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_k1_op<Scalar>, const Derived>
|
||||
k1() const {
|
||||
return unaryExpr(internal::scalar_bessel_k1_op<Scalar>());
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
EIGEN_STRONG_INLINE const TensorCwiseUnaryOp<internal::scalar_bessel_k1e_op<Scalar>, const Derived>
|
||||
k1e() const {
|
||||
return unaryExpr(internal::scalar_bessel_k1e_op<Scalar>());
|
||||
}
|
||||
|
||||
// igamma(a = this, x = other)
|
||||
|
@ -37,8 +37,20 @@ namespace Eigen {
|
||||
* - polygamma
|
||||
* - zeta
|
||||
* - betainc
|
||||
*
|
||||
* Bessel Functions
|
||||
* - i0
|
||||
* - i0e
|
||||
* - i1
|
||||
* - i1e
|
||||
* - j0
|
||||
* - j1
|
||||
* - y0
|
||||
* - y1
|
||||
* - k0
|
||||
* - k0e
|
||||
* - k1
|
||||
* - k1e
|
||||
*
|
||||
* \code
|
||||
* #include <unsupported/Eigen/SpecialFunctions>
|
||||
@ -48,6 +60,11 @@ namespace Eigen {
|
||||
|
||||
}
|
||||
|
||||
#include "src/SpecialFunctions/BesselFunctionsImpl.h"
|
||||
#include "src/SpecialFunctions/BesselFunctionsPacketMath.h"
|
||||
#include "src/SpecialFunctions/BesselFunctionsHalf.h"
|
||||
#include "src/SpecialFunctions/BesselFunctionsFunctors.h"
|
||||
#include "src/SpecialFunctions/BesselFunctionsArrayAPI.h"
|
||||
#include "src/SpecialFunctions/SpecialFunctionsImpl.h"
|
||||
#include "src/SpecialFunctions/SpecialFunctionsPacketMath.h"
|
||||
#include "src/SpecialFunctions/SpecialFunctionsHalf.h"
|
||||
|
286
unsupported/Eigen/src/SpecialFunctions/BesselFunctionsArrayAPI.h
Normal file
286
unsupported/Eigen/src/SpecialFunctions/BesselFunctionsArrayAPI.h
Normal file
@ -0,0 +1,286 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra.
|
||||
//
|
||||
// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla
|
||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
|
||||
#ifndef EIGEN_BESSELFUNCTIONS_ARRAYAPI_H
|
||||
#define EIGEN_BESSELFUNCTIONS_ARRAYAPI_H
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
/** \returns an expression of the coefficient-wise i0(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the modified Bessel function of the first kind of order zero.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of i0(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::i0()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_i0_op<typename Derived::Scalar>, const Derived>
|
||||
i0(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_i0_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise i0e(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the exponentially scaled modified Bessel
|
||||
* function of the first kind of order zero.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of i0e(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::i0e()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_i0e_op<typename Derived::Scalar>, const Derived>
|
||||
i0e(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_i0e_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise i1(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the modified Bessel function of the first kind of order one.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of i1(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::i1()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_i1_op<typename Derived::Scalar>, const Derived>
|
||||
i1(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_i1_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise i1e(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the exponentially scaled modified Bessel
|
||||
* function of the first kind of order one.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of i1e(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::i1e()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_i1e_op<typename Derived::Scalar>, const Derived>
|
||||
i1e(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_i1e_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise k0(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the modified Bessel function of the second kind of order zero.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of k0(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::k0()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_k0_op<typename Derived::Scalar>, const Derived>
|
||||
k0(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_k0_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise k0e(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the exponentially scaled modified Bessel
|
||||
* function of the second kind of order zero.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of k0e(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::k0e()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_k0e_op<typename Derived::Scalar>, const Derived>
|
||||
k0e(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_k0e_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise k1(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the modified Bessel function of the second kind of order one.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of k1(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::k1()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_k1_op<typename Derived::Scalar>, const Derived>
|
||||
k1(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_k1_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise k1e(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the exponentially scaled modified Bessel
|
||||
* function of the second kind of order one.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of k1e(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::k1e()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_k1e_op<typename Derived::Scalar>, const Derived>
|
||||
k1e(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_k1e_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise j0(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the Bessel function of the first kind of order zero.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of j0(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::j0()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_j0_op<typename Derived::Scalar>, const Derived>
|
||||
j0(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_j0_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise y0(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the Bessel function of the second kind of order zero.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of y0(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::y0()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_y0_op<typename Derived::Scalar>, const Derived>
|
||||
y0(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_y0_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise j1(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the modified Bessel function of the first kind of order one.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of j1(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::j1()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_j1_op<typename Derived::Scalar>, const Derived>
|
||||
j1(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_j1_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise y1(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the Bessel function of the second kind of order one.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of y1(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::y1()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_y1_op<typename Derived::Scalar>, const Derived>
|
||||
y1(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_bessel_y1_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_BESSELFUNCTIONS_ARRAYAPI_H
|
357
unsupported/Eigen/src/SpecialFunctions/BesselFunctionsFunctors.h
Normal file
357
unsupported/Eigen/src/SpecialFunctions/BesselFunctionsFunctors.h
Normal file
@ -0,0 +1,357 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra.
|
||||
//
|
||||
// Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com>
|
||||
// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla
|
||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#ifndef EIGEN_BESSELFUNCTIONS_FUNCTORS_H
|
||||
#define EIGEN_BESSELFUNCTIONS_FUNCTORS_H
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
namespace internal {
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the modified Bessel function of the first
|
||||
* kind of order zero.
|
||||
* \sa class CwiseUnaryOp, Cwise::i0()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_i0_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_i0_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::i0;
|
||||
return i0(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pi0(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_i0_op<Scalar> > {
|
||||
enum {
|
||||
// On average, a Chebyshev polynomial of order N=20 is computed.
|
||||
// The cost is N multiplications and 2N additions. We also add
|
||||
// the cost of an additional exp over i0e.
|
||||
Cost = 28 * NumTraits<Scalar>::MulCost + 48 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the exponentially scaled modified Bessel
|
||||
* function of the first kind of order zero
|
||||
* \sa class CwiseUnaryOp, Cwise::i0e()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_i0e_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_i0e_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::i0e;
|
||||
return i0e(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pi0e(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_i0e_op<Scalar> > {
|
||||
enum {
|
||||
// On average, a Chebyshev polynomial of order N=20 is computed.
|
||||
// The cost is N multiplications and 2N additions.
|
||||
Cost = 20 * NumTraits<Scalar>::MulCost + 40 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the modified Bessel function of the first
|
||||
* kind of order one
|
||||
* \sa class CwiseUnaryOp, Cwise::i1()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_i1_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_i1_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::i1;
|
||||
return i1(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pi1(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_i1_op<Scalar> > {
|
||||
enum {
|
||||
// On average, a Chebyshev polynomial of order N=20 is computed.
|
||||
// The cost is N multiplications and 2N additions. We also add
|
||||
// the cost of an additional exp over i1e.
|
||||
Cost = 28 * NumTraits<Scalar>::MulCost + 48 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the exponentially scaled modified Bessel
|
||||
* function of the first kind of order zero
|
||||
* \sa class CwiseUnaryOp, Cwise::i1e()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_i1e_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_i1e_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::i1e;
|
||||
return i1e(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pi1e(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_i1e_op<Scalar> > {
|
||||
enum {
|
||||
// On average, a Chebyshev polynomial of order N=20 is computed.
|
||||
// The cost is N multiplications and 2N additions.
|
||||
Cost = 20 * NumTraits<Scalar>::MulCost + 40 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the Bessel function of the second kind of
|
||||
* order zero
|
||||
* \sa class CwiseUnaryOp, Cwise::j0()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_j0_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_j0_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::j0;
|
||||
return j0(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pj0(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_j0_op<Scalar> > {
|
||||
enum {
|
||||
// 6 polynomial of order ~N=8 is computed.
|
||||
// The cost is N multiplications and N additions each, along with a
|
||||
// sine, cosine and rsqrt cost.
|
||||
Cost = 63 * NumTraits<Scalar>::MulCost + 48 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the Bessel function of the second kind of
|
||||
* order zero
|
||||
* \sa class CwiseUnaryOp, Cwise::y0()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_y0_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_y0_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::y0;
|
||||
return y0(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::py0(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_y0_op<Scalar> > {
|
||||
enum {
|
||||
// 6 polynomial of order ~N=8 is computed.
|
||||
// The cost is N multiplications and N additions each, along with a
|
||||
// sine, cosine, rsqrt and j0 cost.
|
||||
Cost = 126 * NumTraits<Scalar>::MulCost + 96 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the Bessel function of the first kind of
|
||||
* order one
|
||||
* \sa class CwiseUnaryOp, Cwise::j1()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_j1_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_j1_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::j1;
|
||||
return j1(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pj1(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_j1_op<Scalar> > {
|
||||
enum {
|
||||
// 6 polynomial of order ~N=8 is computed.
|
||||
// The cost is N multiplications and N additions each, along with a
|
||||
// sine, cosine and rsqrt cost.
|
||||
Cost = 63 * NumTraits<Scalar>::MulCost + 48 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the Bessel function of the second kind of
|
||||
* order one
|
||||
* \sa class CwiseUnaryOp, Cwise::j1e()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_y1_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_y1_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::y1;
|
||||
return y1(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::py1(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_y1_op<Scalar> > {
|
||||
enum {
|
||||
// 6 polynomial of order ~N=8 is computed.
|
||||
// The cost is N multiplications and N additions each, along with a
|
||||
// sine, cosine, rsqrt and j1 cost.
|
||||
Cost = 126 * NumTraits<Scalar>::MulCost + 96 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the modified Bessel function of the second
|
||||
* kind of order zero
|
||||
* \sa class CwiseUnaryOp, Cwise::k0()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_k0_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_k0_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::k0;
|
||||
return k0(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pk0(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_k0_op<Scalar> > {
|
||||
enum {
|
||||
// On average, a Chebyshev polynomial of order N=10 is computed.
|
||||
// The cost is N multiplications and 2N additions. In addition we compute
|
||||
// i0, a log, exp and prsqrt and sin and cos.
|
||||
Cost = 68 * NumTraits<Scalar>::MulCost + 88 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the exponentially scaled modified Bessel
|
||||
* function of the second kind of order zero
|
||||
* \sa class CwiseUnaryOp, Cwise::k0e()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_k0e_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_k0e_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::k0e;
|
||||
return k0e(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pk0e(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_k0e_op<Scalar> > {
|
||||
enum {
|
||||
// On average, a Chebyshev polynomial of order N=10 is computed.
|
||||
// The cost is N multiplications and 2N additions. In addition we compute
|
||||
// i0, a log, exp and prsqrt and sin and cos.
|
||||
Cost = 68 * NumTraits<Scalar>::MulCost + 88 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the modified Bessel function of the
|
||||
* second kind of order one
|
||||
* \sa class CwiseUnaryOp, Cwise::k1()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_k1_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_k1_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::k1;
|
||||
return k1(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pk1(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_k1_op<Scalar> > {
|
||||
enum {
|
||||
// On average, a Chebyshev polynomial of order N=10 is computed.
|
||||
// The cost is N multiplications and 2N additions. In addition we compute
|
||||
// i1, a log, exp and prsqrt and sin and cos.
|
||||
Cost = 68 * NumTraits<Scalar>::MulCost + 88 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the exponentially scaled modified Bessel
|
||||
* function of the second kind of order one
|
||||
* \sa class CwiseUnaryOp, Cwise::k1e()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_bessel_k1e_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_bessel_k1e_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::k1e;
|
||||
return k1e(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pk1e(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_bessel_k1e_op<Scalar> > {
|
||||
enum {
|
||||
// On average, a Chebyshev polynomial of order N=10 is computed.
|
||||
// The cost is N multiplications and 2N additions. In addition we compute
|
||||
// i1, a log, exp and prsqrt and sin and cos.
|
||||
Cost = 68 * NumTraits<Scalar>::MulCost + 88 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasBessel
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_BESSELFUNCTIONS_FUNCTORS_H
|
66
unsupported/Eigen/src/SpecialFunctions/BesselFunctionsHalf.h
Normal file
66
unsupported/Eigen/src/SpecialFunctions/BesselFunctionsHalf.h
Normal file
@ -0,0 +1,66 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla
|
||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#ifndef EIGEN_BESSELFUNCTIONS_HALF_H
|
||||
#define EIGEN_BESSELFUNCTIONS_HALF_H
|
||||
|
||||
namespace Eigen {
|
||||
namespace numext {
|
||||
|
||||
#if EIGEN_HAS_C99_MATH
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half i0(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::i0(static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half i0e(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::i0e(static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half i1(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::i1(static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half i1e(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::i1e(static_cast<float>(x)));
|
||||
}
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half j0(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::j0(static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half j1(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::j1(static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half y0(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::y0(static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half y1(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::y1(static_cast<float>(x)));
|
||||
}
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half k0(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::k0(static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half k0e(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::k0e(static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half k1(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::k1(static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half k1e(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::k1e(static_cast<float>(x)));
|
||||
}
|
||||
#endif
|
||||
|
||||
} // end namespace numext
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_BESSELFUNCTIONS_HALF_H
|
1959
unsupported/Eigen/src/SpecialFunctions/BesselFunctionsImpl.h
Normal file
1959
unsupported/Eigen/src/SpecialFunctions/BesselFunctionsImpl.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,130 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra.
|
||||
//
|
||||
// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla
|
||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#ifndef EIGEN_BESSELFUNCTIONS_PACKETMATH_H
|
||||
#define EIGEN_BESSELFUNCTIONS_PACKETMATH_H
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
namespace internal {
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order zero i0(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pi0(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_i0; return generic_i0<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order zero i0e(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pi0e(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_i0e; return generic_i0e<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order one i1(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pi1(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_i1; return generic_i1<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order one i1e(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pi1e(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_i1e; return generic_i1e<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order zero j0(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pj0(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_j0; return generic_j0<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order zero j1(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pj1(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_j1; return generic_j1<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order one y0(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet py0(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_y0; return generic_y0<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order one y1(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet py1(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_y1; return generic_y1<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order zero k0(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pk0(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_k0; return generic_k0<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order zero k0e(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pk0e(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_k0e; return generic_k0e<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order one k1e(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pk1(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_k1; return generic_k1<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order one k1e(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pk1e(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_k1e; return generic_k1e<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_BESSELFUNCTIONS_PACKETMATH_H
|
||||
|
@ -161,51 +161,6 @@ zeta(const Eigen::ArrayBase<DerivedX>& x, const Eigen::ArrayBase<DerivedQ>& q)
|
||||
);
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise i0e(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the exponentially scaled modified Bessel
|
||||
* function of order zero.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of i0e(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::i0e()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_i0e_op<typename Derived::Scalar>, const Derived>
|
||||
i0e(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_i0e_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
/** \returns an expression of the coefficient-wise i1e(\a x) to the given
|
||||
* arrays.
|
||||
*
|
||||
* It returns the exponentially scaled modified Bessel
|
||||
* function of order one.
|
||||
*
|
||||
* \param x is the argument
|
||||
*
|
||||
* \note This function supports only float and double scalar types. To support
|
||||
* other scalar types, the user has to provide implementations of i1e(T) for
|
||||
* any scalar type T to be supported.
|
||||
*
|
||||
* \sa ArrayBase::i1e()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_STRONG_INLINE const Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_i1e_op<typename Derived::Scalar>, const Derived>
|
||||
i1e(const Eigen::ArrayBase<Derived>& x) {
|
||||
return Eigen::CwiseUnaryOp<
|
||||
Eigen::internal::scalar_i1e_op<typename Derived::Scalar>,
|
||||
const Derived>(x.derived());
|
||||
}
|
||||
|
||||
} // end namespace Eigen
|
||||
|
||||
|
@ -308,60 +308,6 @@ struct functor_traits<scalar_ndtri_op<Scalar> >
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the exponentially scaled modified Bessel
|
||||
* function of order zero
|
||||
* \sa class CwiseUnaryOp, Cwise::i0e()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_i0e_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_i0e_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::i0e;
|
||||
return i0e(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pi0e(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_i0e_op<Scalar> > {
|
||||
enum {
|
||||
// On average, a Chebyshev polynomial of order N=20 is computed.
|
||||
// The cost is N multiplications and 2N additions.
|
||||
Cost = 20 * NumTraits<Scalar>::MulCost + 40 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasI0e
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the exponentially scaled modified Bessel
|
||||
* function of order zero
|
||||
* \sa class CwiseUnaryOp, Cwise::i1e()
|
||||
*/
|
||||
template <typename Scalar>
|
||||
struct scalar_i1e_op {
|
||||
EIGEN_EMPTY_STRUCT_CTOR(scalar_i1e_op)
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator()(const Scalar& x) const {
|
||||
using numext::i1e;
|
||||
return i1e(x);
|
||||
}
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packetOp(const Packet& x) const {
|
||||
return internal::pi1e(x);
|
||||
}
|
||||
};
|
||||
template <typename Scalar>
|
||||
struct functor_traits<scalar_i1e_op<Scalar> > {
|
||||
enum {
|
||||
// On average, a Chebyshev polynomial of order N=20 is computed.
|
||||
// The cost is N multiplications and 2N additions.
|
||||
Cost = 20 * NumTraits<Scalar>::MulCost + 40 * NumTraits<Scalar>::AddCost,
|
||||
PacketAccess = packet_traits<Scalar>::HasI1e
|
||||
};
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
} // end namespace Eigen
|
||||
|
@ -50,14 +50,6 @@ template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half igammac(const Eigen
|
||||
template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half betainc(const Eigen::half& a, const Eigen::half& b, const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::betainc(static_cast<float>(a), static_cast<float>(b), static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half i0e(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::i0e(static_cast<float>(x)));
|
||||
}
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half i1e(const Eigen::half& x) {
|
||||
return Eigen::half(Eigen::numext::i1e(static_cast<float>(x)));
|
||||
}
|
||||
#endif
|
||||
|
||||
} // end namespace numext
|
||||
|
@ -1757,7 +1757,7 @@ struct betainc_helper<double> {
|
||||
if ((a + b) < maxgam && numext::abs(u) < maxlog) {
|
||||
t = gamma(a + b) / (gamma(a) * gamma(b));
|
||||
s = s * t * pow(x, a);
|
||||
} else {
|
||||
}
|
||||
*/
|
||||
t = lgamma_impl<double>::run(a + b) - lgamma_impl<double>::run(a) -
|
||||
lgamma_impl<double>::run(b) + u + numext::log(s);
|
||||
@ -1864,351 +1864,6 @@ struct betainc_impl<double> {
|
||||
|
||||
#endif // EIGEN_HAS_C99_MATH
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of Bessel function, based on Cephes *
|
||||
****************************************************************************/
|
||||
|
||||
template <typename Scalar>
|
||||
struct i0e_retval {
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template <typename T, typename ScalarType>
|
||||
struct generic_i0e {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static EIGEN_STRONG_INLINE T run(const T&) {
|
||||
EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false),
|
||||
THIS_TYPE_IS_NOT_SUPPORTED);
|
||||
return ScalarType(0);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct generic_i0e<T, float> {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static EIGEN_STRONG_INLINE T run(const T& x) {
|
||||
/* i0ef.c
|
||||
*
|
||||
* Modified Bessel function of order zero,
|
||||
* exponentially scaled
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* float x, y, i0ef();
|
||||
*
|
||||
* y = i0ef( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns exponentially scaled modified Bessel function
|
||||
* of order zero of the argument.
|
||||
*
|
||||
* The function is defined as i0e(x) = exp(-|x|) j0( ix ).
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* IEEE 0,30 100000 3.7e-7 7.0e-8
|
||||
* See i0f().
|
||||
*
|
||||
*/
|
||||
|
||||
const float A[] = {-1.30002500998624804212E-8f, 6.04699502254191894932E-8f,
|
||||
-2.67079385394061173391E-7f, 1.11738753912010371815E-6f,
|
||||
-4.41673835845875056359E-6f, 1.64484480707288970893E-5f,
|
||||
-5.75419501008210370398E-5f, 1.88502885095841655729E-4f,
|
||||
-5.76375574538582365885E-4f, 1.63947561694133579842E-3f,
|
||||
-4.32430999505057594430E-3f, 1.05464603945949983183E-2f,
|
||||
-2.37374148058994688156E-2f, 4.93052842396707084878E-2f,
|
||||
-9.49010970480476444210E-2f, 1.71620901522208775349E-1f,
|
||||
-3.04682672343198398683E-1f, 6.76795274409476084995E-1f};
|
||||
|
||||
const float B[] = {3.39623202570838634515E-9f, 2.26666899049817806459E-8f,
|
||||
2.04891858946906374183E-7f, 2.89137052083475648297E-6f,
|
||||
6.88975834691682398426E-5f, 3.36911647825569408990E-3f,
|
||||
8.04490411014108831608E-1f};
|
||||
T y = pabs(x);
|
||||
T y_le_eight = internal::pchebevl<T, 18>::run(
|
||||
pmadd(pset1<T>(0.5f), y, pset1<T>(-2.0f)), A);
|
||||
T y_gt_eight = pdiv(
|
||||
internal::pchebevl<T, 7>::run(
|
||||
psub(pdiv(pset1<T>(32.0f), y), pset1<T>(2.0f)), B),
|
||||
psqrt(y));
|
||||
// TODO: Perhaps instead check whether all packet elements are in
|
||||
// [-8, 8] and evaluate a branch based off of that. It's possible
|
||||
// in practice most elements are in this region.
|
||||
return pselect(pcmp_le(y, pset1<T>(8.0f)), y_le_eight, y_gt_eight);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct generic_i0e<T, double> {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static EIGEN_STRONG_INLINE T run(const T& x) {
|
||||
/* i0e.c
|
||||
*
|
||||
* Modified Bessel function of order zero,
|
||||
* exponentially scaled
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, i0e();
|
||||
*
|
||||
* y = i0e( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns exponentially scaled modified Bessel function
|
||||
* of order zero of the argument.
|
||||
*
|
||||
* The function is defined as i0e(x) = exp(-|x|) j0( ix ).
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* IEEE 0,30 30000 5.4e-16 1.2e-16
|
||||
* See i0().
|
||||
*
|
||||
*/
|
||||
|
||||
const double A[] = {-4.41534164647933937950E-18, 3.33079451882223809783E-17,
|
||||
-2.43127984654795469359E-16, 1.71539128555513303061E-15,
|
||||
-1.16853328779934516808E-14, 7.67618549860493561688E-14,
|
||||
-4.85644678311192946090E-13, 2.95505266312963983461E-12,
|
||||
-1.72682629144155570723E-11, 9.67580903537323691224E-11,
|
||||
-5.18979560163526290666E-10, 2.65982372468238665035E-9,
|
||||
-1.30002500998624804212E-8, 6.04699502254191894932E-8,
|
||||
-2.67079385394061173391E-7, 1.11738753912010371815E-6,
|
||||
-4.41673835845875056359E-6, 1.64484480707288970893E-5,
|
||||
-5.75419501008210370398E-5, 1.88502885095841655729E-4,
|
||||
-5.76375574538582365885E-4, 1.63947561694133579842E-3,
|
||||
-4.32430999505057594430E-3, 1.05464603945949983183E-2,
|
||||
-2.37374148058994688156E-2, 4.93052842396707084878E-2,
|
||||
-9.49010970480476444210E-2, 1.71620901522208775349E-1,
|
||||
-3.04682672343198398683E-1, 6.76795274409476084995E-1};
|
||||
const double B[] = {
|
||||
-7.23318048787475395456E-18, -4.83050448594418207126E-18,
|
||||
4.46562142029675999901E-17, 3.46122286769746109310E-17,
|
||||
-2.82762398051658348494E-16, -3.42548561967721913462E-16,
|
||||
1.77256013305652638360E-15, 3.81168066935262242075E-15,
|
||||
-9.55484669882830764870E-15, -4.15056934728722208663E-14,
|
||||
1.54008621752140982691E-14, 3.85277838274214270114E-13,
|
||||
7.18012445138366623367E-13, -1.79417853150680611778E-12,
|
||||
-1.32158118404477131188E-11, -3.14991652796324136454E-11,
|
||||
1.18891471078464383424E-11, 4.94060238822496958910E-10,
|
||||
3.39623202570838634515E-9, 2.26666899049817806459E-8,
|
||||
2.04891858946906374183E-7, 2.89137052083475648297E-6,
|
||||
6.88975834691682398426E-5, 3.36911647825569408990E-3,
|
||||
8.04490411014108831608E-1};
|
||||
T y = pabs(x);
|
||||
T y_le_eight = internal::pchebevl<T, 30>::run(
|
||||
pmadd(pset1<T>(0.5), y, pset1<T>(-2.0)), A);
|
||||
T y_gt_eight = pdiv(
|
||||
internal::pchebevl<T, 25>::run(
|
||||
psub(pdiv(pset1<T>(32.0), y), pset1<T>(2.0)), B),
|
||||
psqrt(y));
|
||||
// TODO: Perhaps instead check whether all packet elements are in
|
||||
// [-8, 8] and evaluate a branch based off of that. It's possible
|
||||
// in practice most elements are in this region.
|
||||
return pselect(pcmp_le(y, pset1<T>(8.0)), y_le_eight, y_gt_eight);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Scalar>
|
||||
struct i0e_impl {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static EIGEN_STRONG_INLINE Scalar run(const Scalar x) {
|
||||
return generic_i0e<Scalar, Scalar>::run(x);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Scalar>
|
||||
struct i1e_retval {
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
template <typename T, typename ScalarType>
|
||||
struct generic_i1e {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static EIGEN_STRONG_INLINE T run(const T&) {
|
||||
EIGEN_STATIC_ASSERT((internal::is_same<T, T>::value == false),
|
||||
THIS_TYPE_IS_NOT_SUPPORTED);
|
||||
return ScalarType(0);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct generic_i1e<T, float> {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static EIGEN_STRONG_INLINE T run(const T& x) {
|
||||
/* i1ef.c
|
||||
*
|
||||
* Modified Bessel function of order one,
|
||||
* exponentially scaled
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* float x, y, i1ef();
|
||||
*
|
||||
* y = i1ef( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns exponentially scaled modified Bessel function
|
||||
* of order one of the argument.
|
||||
*
|
||||
* The function is defined as i1(x) = -i exp(-|x|) j1( ix ).
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* IEEE 0, 30 30000 1.5e-6 1.5e-7
|
||||
* See i1().
|
||||
*
|
||||
*/
|
||||
const float A[] = {9.38153738649577178388E-9f, -4.44505912879632808065E-8f,
|
||||
2.00329475355213526229E-7f, -8.56872026469545474066E-7f,
|
||||
3.47025130813767847674E-6f, -1.32731636560394358279E-5f,
|
||||
4.78156510755005422638E-5f, -1.61760815825896745588E-4f,
|
||||
5.12285956168575772895E-4f, -1.51357245063125314899E-3f,
|
||||
4.15642294431288815669E-3f, -1.05640848946261981558E-2f,
|
||||
2.47264490306265168283E-2f, -5.29459812080949914269E-2f,
|
||||
1.02643658689847095384E-1f, -1.76416518357834055153E-1f,
|
||||
2.52587186443633654823E-1f};
|
||||
|
||||
const float B[] = {-3.83538038596423702205E-9f, -2.63146884688951950684E-8f,
|
||||
-2.51223623787020892529E-7f, -3.88256480887769039346E-6f,
|
||||
-1.10588938762623716291E-4f, -9.76109749136146840777E-3f,
|
||||
7.78576235018280120474E-1f};
|
||||
|
||||
|
||||
T y = pabs(x);
|
||||
T y_le_eight = pmul(y, internal::pchebevl<T, 17>::run(
|
||||
pmadd(pset1<T>(0.5f), y, pset1<T>(-2.0f)), A));
|
||||
T y_gt_eight = pdiv(
|
||||
internal::pchebevl<T, 7>::run(
|
||||
psub(pdiv(pset1<T>(32.0f), y),
|
||||
pset1<T>(2.0f)), B),
|
||||
psqrt(y));
|
||||
// TODO: Perhaps instead check whether all packet elements are in
|
||||
// [-8, 8] and evaluate a branch based off of that. It's possible
|
||||
// in practice most elements are in this region.
|
||||
y = pselect(pcmp_le(y, pset1<T>(8.0f)), y_le_eight, y_gt_eight);
|
||||
return pselect(pcmp_lt(x, pset1<T>(0.0f)), -y, y);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct generic_i1e<T, double> {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static EIGEN_STRONG_INLINE T run(const T& x) {
|
||||
/* i1e.c
|
||||
*
|
||||
* Modified Bessel function of order one,
|
||||
* exponentially scaled
|
||||
*
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double x, y, i1e();
|
||||
*
|
||||
* y = i1e( x );
|
||||
*
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* Returns exponentially scaled modified Bessel function
|
||||
* of order one of the argument.
|
||||
*
|
||||
* The function is defined as i1(x) = -i exp(-|x|) j1( ix ).
|
||||
*
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* IEEE 0, 30 30000 2.0e-15 2.0e-16
|
||||
* See i1().
|
||||
*
|
||||
*/
|
||||
const double A[] = {2.77791411276104639959E-18, -2.11142121435816608115E-17,
|
||||
1.55363195773620046921E-16, -1.10559694773538630805E-15,
|
||||
7.60068429473540693410E-15, -5.04218550472791168711E-14,
|
||||
3.22379336594557470981E-13, -1.98397439776494371520E-12,
|
||||
1.17361862988909016308E-11, -6.66348972350202774223E-11,
|
||||
3.62559028155211703701E-10, -1.88724975172282928790E-9,
|
||||
9.38153738649577178388E-9, -4.44505912879632808065E-8,
|
||||
2.00329475355213526229E-7, -8.56872026469545474066E-7,
|
||||
3.47025130813767847674E-6, -1.32731636560394358279E-5,
|
||||
4.78156510755005422638E-5, -1.61760815825896745588E-4,
|
||||
5.12285956168575772895E-4, -1.51357245063125314899E-3,
|
||||
4.15642294431288815669E-3, -1.05640848946261981558E-2,
|
||||
2.47264490306265168283E-2, -5.29459812080949914269E-2,
|
||||
1.02643658689847095384E-1, -1.76416518357834055153E-1,
|
||||
2.52587186443633654823E-1};
|
||||
const double B[] = {
|
||||
7.51729631084210481353E-18, 4.41434832307170791151E-18,
|
||||
-4.65030536848935832153E-17, -3.20952592199342395980E-17,
|
||||
2.96262899764595013876E-16, 3.30820231092092828324E-16,
|
||||
-1.88035477551078244854E-15, -3.81440307243700780478E-15,
|
||||
1.04202769841288027642E-14, 4.27244001671195135429E-14,
|
||||
-2.10154184277266431302E-14, -4.08355111109219731823E-13,
|
||||
-7.19855177624590851209E-13, 2.03562854414708950722E-12,
|
||||
1.41258074366137813316E-11, 3.25260358301548823856E-11,
|
||||
-1.89749581235054123450E-11, -5.58974346219658380687E-10,
|
||||
-3.83538038596423702205E-9, -2.63146884688951950684E-8,
|
||||
-2.51223623787020892529E-7, -3.88256480887769039346E-6,
|
||||
-1.10588938762623716291E-4, -9.76109749136146840777E-3,
|
||||
7.78576235018280120474E-1};
|
||||
T y = pabs(x);
|
||||
T y_le_eight = pmul(y, internal::pchebevl<T, 29>::run(
|
||||
pmadd(pset1<T>(0.5), y, pset1<T>(-2.0)), A));
|
||||
T y_gt_eight = pdiv(
|
||||
internal::pchebevl<T, 25>::run(
|
||||
psub(pdiv(pset1<T>(32.0), y),
|
||||
pset1<T>(2.0)), B),
|
||||
psqrt(y));
|
||||
// TODO: Perhaps instead check whether all packet elements are in
|
||||
// [-8, 8] and evaluate a branch based off of that. It's possible
|
||||
// in practice most elements are in this region.
|
||||
y = pselect(pcmp_le(y, pset1<T>(8.0)), y_le_eight, y_gt_eight);
|
||||
return pselect(pcmp_lt(x, pset1<T>(0.0f)), -y, y);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Scalar>
|
||||
struct i1e_impl {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static EIGEN_STRONG_INLINE Scalar run(const Scalar x) {
|
||||
return generic_i1e<Scalar, Scalar>::run(x);
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
namespace numext {
|
||||
@ -2285,21 +1940,7 @@ EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(betainc, Scalar)
|
||||
return EIGEN_MATHFUNC_IMPL(betainc, Scalar)::run(a, b, x);
|
||||
}
|
||||
|
||||
template <typename Scalar>
|
||||
EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(i0e, Scalar)
|
||||
i0e(const Scalar& x) {
|
||||
return EIGEN_MATHFUNC_IMPL(i0e, Scalar)::run(x);
|
||||
}
|
||||
|
||||
template <typename Scalar>
|
||||
EIGEN_DEVICE_FUNC inline EIGEN_MATHFUNC_RETVAL(i1e, Scalar)
|
||||
i1e(const Scalar& x) {
|
||||
return EIGEN_MATHFUNC_IMPL(i1e, Scalar)::run(x);
|
||||
}
|
||||
|
||||
} // end namespace numext
|
||||
|
||||
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_SPECIAL_FUNCTIONS_H
|
||||
|
@ -72,24 +72,6 @@ Packet pigammac(const Packet& a, const Packet& x) { using numext::igammac; retur
|
||||
template<typename Packet> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
Packet pbetainc(const Packet& a, const Packet& b,const Packet& x) { using numext::betainc; return betainc(a, b, x); }
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order zero i0e(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pi0e(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_i0e; return generic_i0e<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
/** \internal \returns the exponentially scaled modified Bessel function of
|
||||
* order one i1e(\a a) (coeff-wise) */
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_DECLARE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
|
||||
Packet pi1e(const Packet& x) {
|
||||
typedef typename unpacket_traits<Packet>::type ScalarType;
|
||||
using internal::generic_i1e; return generic_i1e<Packet, ScalarType>::run(x);
|
||||
}
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
} // end namespace Eigen
|
||||
|
@ -217,6 +217,19 @@ pi0e<double2>(const double2& x) {
|
||||
return make_double2(i0e(x.x), i0e(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pi0<float4>(const float4& x) {
|
||||
using numext::i0;
|
||||
return make_float4(i0(x.x), i0(x.y), i0(x.z), i0(x.w));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
|
||||
pi0<double2>(const double2& x) {
|
||||
using numext::i0;
|
||||
return make_double2(i0(x.x), i0(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pi1e<float4>(const float4& x) {
|
||||
using numext::i1e;
|
||||
@ -230,6 +243,123 @@ pi1e<double2>(const double2& x) {
|
||||
return make_double2(i1e(x.x), i1e(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pi1<float4>(const float4& x) {
|
||||
using numext::i1;
|
||||
return make_float4(i1(x.x), i1(x.y), i1(x.z), i1(x.w));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
|
||||
pi1<double2>(const double2& x) {
|
||||
using numext::i1;
|
||||
return make_double2(i1(x.x), i1(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pk0e<float4>(const float4& x) {
|
||||
using numext::k0e;
|
||||
return make_float4(k0e(x.x), k0e(x.y), k0e(x.z), k0e(x.w));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
|
||||
pk0e<double2>(const double2& x) {
|
||||
using numext::k0e;
|
||||
return make_double2(k0e(x.x), k0e(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pk0<float4>(const float4& x) {
|
||||
using numext::k0;
|
||||
return make_float4(k0(x.x), k0(x.y), k0(x.z), k0(x.w));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
|
||||
pk0<double2>(const double2& x) {
|
||||
using numext::k0;
|
||||
return make_double2(k0(x.x), k0(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pk1e<float4>(const float4& x) {
|
||||
using numext::k1e;
|
||||
return make_float4(k1e(x.x), k1e(x.y), k1e(x.z), k1e(x.w));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
|
||||
pk1e<double2>(const double2& x) {
|
||||
using numext::k1e;
|
||||
return make_double2(k1e(x.x), k1e(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pk1<float4>(const float4& x) {
|
||||
using numext::k1;
|
||||
return make_float4(k1(x.x), k1(x.y), k1(x.z), k1(x.w));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
|
||||
pk1<double2>(const double2& x) {
|
||||
using numext::k1;
|
||||
return make_double2(k1(x.x), k1(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pj0<float4>(const float4& x) {
|
||||
using numext::j0;
|
||||
return make_float4(j0(x.x), j0(x.y), j0(x.z), j0(x.w));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
|
||||
pj0<double2>(const double2& x) {
|
||||
using numext::j0;
|
||||
return make_double2(j0(x.x), j0(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pj1<float4>(const float4& x) {
|
||||
using numext::j1;
|
||||
return make_float4(j1(x.x), j1(x.y), j1(x.z), j1(x.w));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
|
||||
pj1<double2>(const double2& x) {
|
||||
using numext::j1;
|
||||
return make_double2(j1(x.x), j1(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 py0<float4>(const float4& x) {
|
||||
using numext::y0;
|
||||
return make_float4(y0(x.x), y0(x.y), y0(x.z), y0(x.w));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
|
||||
py0<double2>(const double2& x) {
|
||||
using numext::y0;
|
||||
return make_double2(y0(x.x), y0(x.y));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 py1<float4>(const float4& x) {
|
||||
using numext::y1;
|
||||
return make_float4(y1(x.x), y1(x.y), y1(x.z), y1(x.w));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double2
|
||||
py1<double2>(const double2& x) {
|
||||
using numext::y1;
|
||||
return make_double2(y1(x.x), y1(x.y));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // end namespace internal
|
||||
|
@ -106,6 +106,7 @@ ei_add_test(dgmres)
|
||||
ei_add_test(minres)
|
||||
ei_add_test(levenberg_marquardt)
|
||||
ei_add_test(kronecker_product)
|
||||
ei_add_test(bessel_functions)
|
||||
ei_add_test(special_functions)
|
||||
|
||||
# TODO: The following test names are prefixed with the cxx11 string, since historically
|
||||
|
370
unsupported/test/bessel_functions.cpp
Normal file
370
unsupported/test/bessel_functions.cpp
Normal file
@ -0,0 +1,370 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra.
|
||||
//
|
||||
// Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla
|
||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "main.h"
|
||||
#include "../Eigen/SpecialFunctions"
|
||||
|
||||
template<typename X, typename Y>
|
||||
void verify_component_wise(const X& x, const Y& y)
|
||||
{
|
||||
for(Index i=0; i<x.size(); ++i)
|
||||
{
|
||||
if((numext::isfinite)(y(i))) {
|
||||
VERIFY_IS_APPROX( x(i), y(i) );
|
||||
}
|
||||
else if((numext::isnan)(y(i)))
|
||||
VERIFY((numext::isnan)(x(i)));
|
||||
else
|
||||
VERIFY_IS_EQUAL( x(i), y(i) );
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ArrayType> void array_bessel_functions()
|
||||
{
|
||||
// Test Bessel function i0. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(21);
|
||||
ArrayType expected(21);
|
||||
ArrayType res(21);
|
||||
|
||||
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, 16.0, 18.0, 20.0;
|
||||
|
||||
expected << 4.35582826e+07, 6.21841242e+06, 8.93446228e+05, 1.29418563e+05,
|
||||
1.89489253e+04, 2.81571663e+03, 4.27564116e+02, 6.72344070e+01,
|
||||
1.13019220e+01, 2.27958530e+00, 1.00000000e+00, 2.27958530e+00,
|
||||
1.13019220e+01, 6.72344070e+01, 4.27564116e+02, 2.81571663e+03,
|
||||
1.89489253e+04, 1.29418563e+05, 8.93446228e+05, 6.21841242e+06,
|
||||
4.35582826e+07;
|
||||
|
||||
CALL_SUBTEST(res = i0(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function i0e. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(21);
|
||||
ArrayType expected(21);
|
||||
ArrayType res(21);
|
||||
|
||||
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, 16.0, 18.0, 20.0;
|
||||
|
||||
expected << 0.0897803118848, 0.0947062952128, 0.100544127361,
|
||||
0.107615251671, 0.116426221213, 0.127833337163, 0.143431781857,
|
||||
0.16665743264, 0.207001921224, 0.308508322554, 1.0, 0.308508322554,
|
||||
0.207001921224, 0.16665743264, 0.143431781857, 0.127833337163,
|
||||
0.116426221213, 0.107615251671, 0.100544127361, 0.0947062952128,
|
||||
0.0897803118848;
|
||||
|
||||
CALL_SUBTEST(res = i0e(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function i1. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(21);
|
||||
ArrayType expected(21);
|
||||
ArrayType res(21);
|
||||
|
||||
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, 16.0, 18.0, 20.0;
|
||||
|
||||
expected << -4.24549734e+07, -6.04313324e+06, -8.65059436e+05, -1.24707259e+05,
|
||||
-1.81413488e+04, -2.67098830e+03, -3.99873137e+02, -6.13419368e+01,
|
||||
-9.75946515e+00, -1.59063685e+00, 0.00000000e+00, 1.59063685e+00,
|
||||
9.75946515e+00, 6.13419368e+01, 3.99873137e+02, 2.67098830e+03,
|
||||
1.81413488e+04, 1.24707259e+05, 8.65059436e+05, 6.04313324e+06,
|
||||
4.24549734e+07;
|
||||
|
||||
CALL_SUBTEST(res = i1(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function i1e. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(21);
|
||||
ArrayType expected(21);
|
||||
ArrayType res(21);
|
||||
|
||||
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, 16.0, 18.0, 20.0;
|
||||
|
||||
expected << -0.0875062221833, -0.092036796872, -0.0973496147565,
|
||||
-0.103697667463, -0.11146429929, -0.121262681384, -0.134142493293,
|
||||
-0.152051459309, -0.178750839502, -0.215269289249, 0.0, 0.215269289249,
|
||||
0.178750839502, 0.152051459309, 0.134142493293, 0.121262681384,
|
||||
0.11146429929, 0.103697667463, 0.0973496147565, 0.092036796872,
|
||||
0.0875062221833;
|
||||
|
||||
CALL_SUBTEST(res = i1e(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function j0. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(77);
|
||||
ArrayType expected(77);
|
||||
ArrayType res(77);
|
||||
|
||||
x << -38., -37., -36., -35., -34., -33., -32., -31., -30.,
|
||||
-29., -28., -27., -26., -25., -24., -23., -22., -21., -20., -19.,
|
||||
-18., -17., -16., -15., -14., -13., -12., -11., -10., -9., -8.,
|
||||
-7., -6., -5., -4., -3., -2., -1., 0., 1., 2., 3.,
|
||||
4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14.,
|
||||
15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25.,
|
||||
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36.,
|
||||
37., 38.;
|
||||
|
||||
expected << 0.11433274, 0.01086237, -0.10556738,
|
||||
-0.12684568, -0.03042119, 0.09727067, 0.13807901, 0.05120815,
|
||||
-0.08636798, -0.14784876, -0.07315701, 0.07274192, 0.15599932,
|
||||
0.09626678, -0.05623027, -0.16241278, -0.12065148, 0.03657907,
|
||||
0.16702466, 0.14662944, -0.01335581, -0.16985425, -0.17489907,
|
||||
-0.01422447, 0.17107348, 0.2069261 , 0.04768931, -0.1711903 ,
|
||||
-0.24593576, -0.09033361, 0.17165081, 0.30007927, 0.15064526,
|
||||
-0.17759677, -0.39714981, -0.26005195, 0.22389078, 0.76519769,
|
||||
1. , 0.76519769, 0.22389078, -0.26005195, -0.39714981,
|
||||
-0.17759677, 0.15064526, 0.30007927, 0.17165081, -0.09033361,
|
||||
-0.24593576, -0.1711903 , 0.04768931, 0.2069261 , 0.17107348,
|
||||
-0.01422447, -0.17489907, -0.16985425, -0.01335581, 0.14662944,
|
||||
0.16702466, 0.03657907, -0.12065148, -0.16241278, -0.05623027,
|
||||
0.09626678, 0.15599932, 0.07274192, -0.07315701, -0.14784876,
|
||||
-0.08636798, 0.05120815, 0.13807901, 0.09727067, -0.03042119,
|
||||
-0.12684568, -0.10556738, 0.01086237, 0.11433274;
|
||||
|
||||
CALL_SUBTEST(res = j0(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function j1. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(81);
|
||||
ArrayType expected(81);
|
||||
ArrayType res(81);
|
||||
|
||||
x << -40., -39., -38., -37., -36., -35., -34., -33., -32., -31., -30.,
|
||||
-29., -28., -27., -26., -25., -24., -23., -22., -21., -20., -19.,
|
||||
-18., -17., -16., -15., -14., -13., -12., -11., -10., -9., -8.,
|
||||
-7., -6., -5., -4., -3., -2., -1., 0., 1., 2., 3.,
|
||||
4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14.,
|
||||
15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25.,
|
||||
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36.,
|
||||
37., 38., 39., 40.;
|
||||
|
||||
expected << -0.12603832, -0.0640561 , 0.05916189, 0.13058004, 0.08232981,
|
||||
-0.04399094, -0.13297118, -0.10061965, 0.02658903, 0.13302432,
|
||||
0.11875106, -0.0069342 , -0.13055149, -0.13658472, -0.01504573,
|
||||
0.12535025, 0.15403807, 0.03951932, -0.11717779, -0.17112027,
|
||||
-0.06683312, 0.10570143, 0.18799489, 0.09766849, -0.09039718,
|
||||
-0.20510404, -0.13337515, 0.07031805, 0.2234471 , 0.1767853 ,
|
||||
-0.04347275, -0.24531179, -0.23463635, 0.00468282, 0.27668386,
|
||||
0.32757914, 0.06604333, -0.33905896, -0.57672481, -0.44005059,
|
||||
0. , 0.44005059, 0.57672481, 0.33905896, -0.06604333,
|
||||
-0.32757914, -0.27668386, -0.00468282, 0.23463635, 0.24531179,
|
||||
0.04347275, -0.1767853 , -0.2234471 , -0.07031805, 0.13337515,
|
||||
0.20510404, 0.09039718, -0.09766849, -0.18799489, -0.10570143,
|
||||
0.06683312, 0.17112027, 0.11717779, -0.03951932, -0.15403807,
|
||||
-0.12535025, 0.01504573, 0.13658472, 0.13055149, 0.0069342 ,
|
||||
-0.11875106, -0.13302432, -0.02658903, 0.10061965, 0.13297118,
|
||||
0.04399094, -0.08232981, -0.13058004, -0.05916189, 0.0640561 ,
|
||||
0.12603832;
|
||||
|
||||
CALL_SUBTEST(res = j1(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
// Test Bessel function k0e. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(42);
|
||||
ArrayType expected(42);
|
||||
ArrayType res(42);
|
||||
|
||||
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., 23., 24., 25.,
|
||||
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38.,
|
||||
39., 40.;
|
||||
|
||||
expected << 1.97933385, 1.52410939, 1.14446308, 0.84156822,
|
||||
0.6977616 , 0.60929767, 0.54780756, 0.50186313, 0.4658451 ,
|
||||
0.43662302, 0.41229555, 0.39163193, 0.3737955 , 0.35819488,
|
||||
0.34439865, 0.33208364, 0.32100235, 0.31096159, 0.30180802,
|
||||
0.29341821, 0.28569149, 0.27854488, 0.2719092 , 0.26572635,
|
||||
0.25994703, 0.25452917, 0.2494366 , 0.24463801, 0.24010616,
|
||||
0.23581722, 0.23175022, 0.22788667, 0.22421014, 0.22070602,
|
||||
0.21736123, 0.21416406, 0.21110397, 0.20817141, 0.20535778,
|
||||
0.20265524, 0.20005668, 0.19755558;
|
||||
|
||||
CALL_SUBTEST(res = k0e(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function k0. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(42);
|
||||
ArrayType expected(42);
|
||||
ArrayType res(42);
|
||||
|
||||
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., 23., 24., 25.,
|
||||
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38.,
|
||||
39., 40.;
|
||||
|
||||
expected << 1.54150675, 0.92441907, 4.21024438e-01, 1.13893873e-01,
|
||||
3.47395044e-02, 1.11596761e-02, 3.69109833e-03, 1.24399433e-03,
|
||||
4.24795742e-04, 1.46470705e-04, 5.08813130e-05, 1.77800623e-05,
|
||||
6.24302055e-06, 2.20082540e-06, 7.78454386e-07, 2.76137082e-07,
|
||||
9.81953648e-08, 3.49941166e-08, 1.24946640e-08, 4.46875334e-09,
|
||||
1.60067129e-09, 5.74123782e-10, 2.06176797e-10, 7.41235161e-11,
|
||||
2.66754511e-11, 9.60881878e-12, 3.46416156e-12, 1.24987740e-12,
|
||||
4.51286453e-13, 1.63053459e-13, 5.89495073e-14, 2.13247750e-14,
|
||||
7.71838266e-15, 2.79505752e-15, 1.01266123e-15, 3.67057597e-16,
|
||||
1.33103515e-16, 4.82858338e-17, 1.75232770e-17, 6.36161716e-18,
|
||||
2.31029936e-18, 8.39286110e-19;
|
||||
|
||||
CALL_SUBTEST(res = k0(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function k0e. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(42);
|
||||
ArrayType expected(42);
|
||||
ArrayType res(42);
|
||||
|
||||
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., 23., 24., 25.,
|
||||
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38.,
|
||||
39., 40.;
|
||||
|
||||
expected << 1.97933385, 1.52410939, 1.14446308, 0.84156822,
|
||||
0.6977616 , 0.60929767, 0.54780756, 0.50186313,
|
||||
0.4658451 , 0.43662302, 0.41229555, 0.39163193,
|
||||
0.3737955 , 0.35819488, 0.34439865, 0.33208364,
|
||||
0.32100235, 0.31096159, 0.30180802, 0.29341821,
|
||||
0.28569149, 0.27854488, 0.2719092 , 0.26572635,
|
||||
0.25994703, 0.25452917, 0.2494366 , 0.24463801,
|
||||
0.24010616, 0.23581722, 0.23175022, 0.22788667,
|
||||
0.22421014, 0.22070602, 0.21736123, 0.21416406,
|
||||
0.21110397, 0.20817141, 0.20535778, 0.20265524,
|
||||
0.20005668, 0.19755558;
|
||||
|
||||
CALL_SUBTEST(res = k0e(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function k1. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(42);
|
||||
ArrayType expected(42);
|
||||
ArrayType res(42);
|
||||
|
||||
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., 23., 24., 25.,
|
||||
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38.,
|
||||
39., 40.;
|
||||
|
||||
expected << 3.74702597, 1.65644112, 6.01907230e-01, 1.39865882e-01,
|
||||
4.01564311e-02, 1.24834989e-02, 4.04461345e-03, 1.34391972e-03,
|
||||
4.54182487e-04, 1.55369212e-04, 5.36370164e-05, 1.86487735e-05,
|
||||
6.52086067e-06, 2.29075746e-06, 8.07858841e-07, 2.85834365e-07,
|
||||
1.01417294e-07, 3.60715712e-08, 1.28570417e-08, 4.59124963e-09,
|
||||
1.64226697e-09, 5.88305797e-10, 2.11029922e-10, 7.57898116e-11,
|
||||
2.72493059e-11, 9.80699893e-12, 3.53277807e-12, 1.27369078e-12,
|
||||
4.59568940e-13, 1.65940011e-13, 5.99574032e-14, 2.16773200e-14,
|
||||
7.84189960e-15, 2.83839927e-15, 1.02789171e-15, 3.72416929e-16,
|
||||
1.34991783e-16, 4.89519373e-17, 1.77585196e-17, 6.44478588e-18,
|
||||
2.33973340e-18, 8.49713195e-19;
|
||||
|
||||
CALL_SUBTEST(res = k1(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function k1e. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(42);
|
||||
ArrayType expected(42);
|
||||
ArrayType res(42);
|
||||
|
||||
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., 23., 24., 25.,
|
||||
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38.,
|
||||
39., 40.;
|
||||
|
||||
expected << 4.81127659, 2.73100971, 1.63615349, 1.03347685,
|
||||
0.80656348, 0.68157595, 0.60027386, 0.54217591,
|
||||
0.49807158, 0.46314909, 0.43462525, 0.41076657,
|
||||
0.39043094, 0.37283175, 0.35740757, 0.34374563,
|
||||
0.33153489, 0.32053597, 0.31056123, 0.30146131,
|
||||
0.29311559, 0.2854255 , 0.27830958, 0.27169987,
|
||||
0.26553913, 0.25977879, 0.25437733, 0.249299 ,
|
||||
0.24451285, 0.23999191, 0.2357126 , 0.23165413,
|
||||
0.22779816, 0.22412841, 0.22063036, 0.21729103,
|
||||
0.21409878, 0.21104314, 0.20811462, 0.20530466,
|
||||
0.20260547, 0.20000997;
|
||||
|
||||
CALL_SUBTEST(res = k1e(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function y0. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(42);
|
||||
ArrayType expected(42);
|
||||
ArrayType res(42);
|
||||
|
||||
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., 23., 24., 25.,
|
||||
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38.,
|
||||
39., 40.;
|
||||
|
||||
expected << -0.93157302, -0.44451873, 0.08825696, 0.51037567, 0.37685001,
|
||||
-0.01694074, -0.30851763, -0.28819468, -0.02594974, 0.22352149,
|
||||
0.2499367 , 0.05567117, -0.16884732, -0.22523731, -0.07820786,
|
||||
0.12719257, 0.2054643 , 0.095811 , -0.0926372 , -0.18755216,
|
||||
-0.10951969, 0.0626406 , 0.17020176, 0.1198876 , -0.03598179,
|
||||
-0.15283403, -0.12724943, 0.01204463, 0.13521498, 0.13183647,
|
||||
0.00948116, -0.11729573, -0.13383266, -0.02874248, 0.09913483,
|
||||
0.13340405, 0.04579799, -0.08085609, -0.13071488, -0.06066076,
|
||||
0.06262353, 0.12593642;
|
||||
|
||||
CALL_SUBTEST(res = y0(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function y1. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(42);
|
||||
ArrayType expected(42);
|
||||
ArrayType res(42);
|
||||
|
||||
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., 23., 24., 25.,
|
||||
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38.,
|
||||
39., 40.;
|
||||
|
||||
expected << -2.70410523, -1.47147239, -0.78121282, -0.10703243,
|
||||
0.32467442, 0.39792571, 0.14786314, -0.17501034, -0.30266724,
|
||||
-0.15806046, 0.10431458, 0.24901542, 0.16370554, -0.05709922,
|
||||
-0.21008141, -0.16664484, 0.02107363, 0.17797517, 0.16720504,
|
||||
0.00815513, -0.14956011, -0.16551161, -0.03253926, 0.12340586,
|
||||
0.1616692 , 0.05305978, -0.09882996, -0.15579655, -0.07025124,
|
||||
0.07552213, 0.14803412, 0.08442557, -0.05337283, -0.13854483,
|
||||
-0.09578012, 0.03238588, 0.12751273, 0.10445477, -0.01262946,
|
||||
-0.11514066, -0.11056411, -0.00579351;
|
||||
|
||||
CALL_SUBTEST(res = y1(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(bessel_functions)
|
||||
{
|
||||
CALL_SUBTEST_1(array_bessel_functions<ArrayXf>());
|
||||
CALL_SUBTEST_2(array_bessel_functions<ArrayXd>());
|
||||
}
|
@ -357,47 +357,7 @@ template<typename ArrayType> void array_special_functions()
|
||||
}
|
||||
#endif // EIGEN_HAS_C99_MATH
|
||||
|
||||
// Test Bessel function i0e. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(21);
|
||||
ArrayType expected(21);
|
||||
ArrayType res(21);
|
||||
|
||||
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, 16.0, 18.0, 20.0;
|
||||
|
||||
expected << 0.0897803118848, 0.0947062952128, 0.100544127361,
|
||||
0.107615251671, 0.116426221213, 0.127833337163, 0.143431781857,
|
||||
0.16665743264, 0.207001921224, 0.308508322554, 1.0, 0.308508322554,
|
||||
0.207001921224, 0.16665743264, 0.143431781857, 0.127833337163,
|
||||
0.116426221213, 0.107615251671, 0.100544127361, 0.0947062952128,
|
||||
0.0897803118848;
|
||||
|
||||
CALL_SUBTEST(res = i0e(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
// Test Bessel function i1e. Reference results obtained with SciPy.
|
||||
{
|
||||
ArrayType x(21);
|
||||
ArrayType expected(21);
|
||||
ArrayType res(21);
|
||||
|
||||
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, 16.0, 18.0, 20.0;
|
||||
|
||||
expected << -0.0875062221833, -0.092036796872, -0.0973496147565,
|
||||
-0.103697667463, -0.11146429929, -0.121262681384, -0.134142493293,
|
||||
-0.152051459309, -0.178750839502, -0.215269289249, 0.0, 0.215269289249,
|
||||
0.178750839502, 0.152051459309, 0.134142493293, 0.121262681384,
|
||||
0.11146429929, 0.103697667463, 0.0973496147565, 0.092036796872,
|
||||
0.0875062221833;
|
||||
|
||||
CALL_SUBTEST(res = i1e(x);
|
||||
verify_component_wise(res, expected););
|
||||
}
|
||||
|
||||
/* Code to generate the data for the following two test cases.
|
||||
/* Code to generate the data for the following two test cases.
|
||||
N = 5
|
||||
np.random.seed(3)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user