Eigen-Contrib  5.0.1-dev+master
 
Loading...
Searching...
No Matches
SpecialFunctionsOverloads.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// This Source Code Form is subject to the terms of the Mozilla
5// Public License v. 2.0. If a copy of the MPL was not distributed
6// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
7// SPDX-FileCopyrightText: The Eigen Authors
8// SPDX-License-Identifier: MPL-2.0
9
10#ifndef EIGEN_SPECIAL_FUNCTIONS_OVERLOADS_H
11#define EIGEN_SPECIAL_FUNCTIONS_OVERLOADS_H
12
13// IWYU pragma: private
14#include "./InternalHeaderCheck.h"
15
16namespace Eigen {
17namespace internal {
18
19// Unqualified lookup of a special function from this namespace sees std::erf, std::erfc, std::lgamma and whatever
20// argument-dependent lookup adds. The using-declaration and the deleted declarations hide the ArrayBase overloads in
21// namespace Eigen and keep ordinary lookup from reaching anything else. Both the detection and the call below are made
22// from here, so they see the same overload set.
23namespace special_function_overloads {
24
25#define EIGEN_SPECIAL_FUNCTION_OVERLOAD(NAME) \
26 struct NAME##_fn { \
27 template <typename Scalar, typename... Rest, \
28 typename Result = decltype(NAME(std::declval<const Scalar&>(), std::declval<const Rest&>()...))> \
29 static std::is_same<std::decay_t<Result>, Scalar> test(int); \
30 template <typename... Args> \
31 static std::false_type test(...); \
32 template <typename Scalar, typename... Args> \
33 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar call(const Args&... args) { \
34 return NAME(args...); \
35 } \
36 };
37// A deleted template rather than a deleted function: GCC 10 drops the overloads that argument-dependent lookup finds
38// when ordinary lookup finds a deleted non-template function.
39#define EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(NAME) \
40 template <typename = void> \
41 void NAME() = delete; \
42 EIGEN_SPECIAL_FUNCTION_OVERLOAD(NAME)
43
44EIGEN_USING_STD(erf)
45EIGEN_SPECIAL_FUNCTION_OVERLOAD(erf)
46EIGEN_USING_STD(erfc)
47EIGEN_SPECIAL_FUNCTION_OVERLOAD(erfc)
48EIGEN_USING_STD(lgamma)
49EIGEN_SPECIAL_FUNCTION_OVERLOAD(lgamma)
50EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(digamma)
51EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(zeta)
52EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(polygamma)
53EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(ndtri)
54EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(igamma)
55EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(igammac)
56EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(igamma_der_a)
57EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(gamma_sample_der_alpha)
58EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(betainc)
59EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_i0)
60EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_i0e)
61EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_i1)
62EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_i1e)
63EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_j0)
64EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_j1)
65EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_y0)
66EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_y1)
67EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_k0)
68EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_k0e)
69EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_k1)
70EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY(bessel_k1e)
71
72#undef EIGEN_SPECIAL_FUNCTION_OVERLOAD_ADL_ONLY
73#undef EIGEN_SPECIAL_FUNCTION_OVERLOAD
74
75} // namespace special_function_overloads
76
77template <typename Fn, bool IsScalar, typename Scalar, typename... Rest>
78struct has_special_function_overload_impl : std::false_type {};
79template <typename Fn, typename Scalar, typename... Rest>
80struct has_special_function_overload_impl<Fn, true, Scalar, Rest...>
81 : bool_constant<!NumTraits<Scalar>::IsInteger && decltype(Fn::template test<Scalar, Rest...>(0))::value> {};
82
83// Whether Fn's lookup finds an overload callable with Scalar, Rest... for the non-integer scalar type Scalar that
84// returns Scalar. Another result type means that the overload takes another type, such as the double of std::lgamma,
85// which the argument reaches through a conversion, and computes at that type's precision. Packets never use one.
86template <typename Fn, typename Scalar, typename... Rest>
87struct has_special_function_overload
88 : has_special_function_overload_impl<Fn, std::is_same<Scalar, typename unpacket_traits<Scalar>::type>::value,
89 Scalar, Rest...> {};
90
91template <typename Fn, typename Scalar>
92struct special_function_overload {
93 template <typename... Args>
94 EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Args&... args) {
95 return Fn::template call<Scalar>(args...);
96 }
97};
98
99// The implementation of a special function for arguments of types Scalar, Rest...: the overload that Fn's lookup finds
100// when there is one, so that a custom scalar type keeps its own implementation, and Default otherwise.
101template <typename Fn, typename Default, typename Scalar, typename... Rest>
102struct special_function_overload_or : std::conditional_t<has_special_function_overload<Fn, Scalar, Rest...>::value,
103 special_function_overload<Fn, Scalar>, Default> {};
104
105} // namespace internal
106} // namespace Eigen
107
108#endif // EIGEN_SPECIAL_FUNCTIONS_OVERLOADS_H
Namespace containing all symbols from the Eigen library.
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_y1_op< typename Derived::Scalar >, const Derived > bessel_y1(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:270
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k0e_op< typename Derived::Scalar >, const Derived > bessel_k0e(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:143
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k0_op< typename Derived::Scalar >, const Derived > bessel_k0(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:121
const Eigen::CwiseBinaryOp< Eigen::internal::scalar_igammac_op< typename Derived::Scalar >, const Derived, const ExponentDerived > igammac(const Eigen::ArrayBase< Derived > &a, const Eigen::ArrayBase< ExponentDerived > &x)
Definition SpecialFunctionsArrayAPI.h:86
const Eigen::CwiseBinaryOp< Eigen::internal::scalar_igamma_der_a_op< typename Derived::Scalar >, const Derived, const ExponentDerived > igamma_der_a(const Eigen::ArrayBase< Derived > &a, const Eigen::ArrayBase< ExponentDerived > &x)
Definition SpecialFunctionsArrayAPI.h:49
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k1_op< typename Derived::Scalar >, const Derived > bessel_k1(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:164
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i1_op< typename Derived::Scalar >, const Derived > bessel_i1(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:78
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i0e_op< typename Derived::Scalar >, const Derived > bessel_i0e(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:57
const Eigen::CwiseTernaryOp< Eigen::internal::scalar_betainc_op< typename ArgXDerived::Scalar >, const ArgADerived, const ArgBDerived, const ArgXDerived > betainc(const Eigen::ArrayBase< ArgADerived > &a, const Eigen::ArrayBase< ArgBDerived > &b, const Eigen::ArrayBase< ArgXDerived > &x)
Definition SpecialFunctionsArrayAPI.h:120
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i1e_op< typename Derived::Scalar >, const Derived > bessel_i1e(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:100
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_j1_op< typename Derived::Scalar >, const Derived > bessel_j1(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:249
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_y0_op< typename Derived::Scalar >, const Derived > bessel_y0(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:228
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_i0_op< typename Derived::Scalar >, const Derived > bessel_i0(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:35
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_k1e_op< typename Derived::Scalar >, const Derived > bessel_k1e(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:186
const Eigen::CwiseBinaryOp< Eigen::internal::scalar_gamma_sample_der_alpha_op< typename AlphaDerived::Scalar >, const AlphaDerived, const SampleDerived > gamma_sample_der_alpha(const Eigen::ArrayBase< AlphaDerived > &alpha, const Eigen::ArrayBase< SampleDerived > &sample)
Definition SpecialFunctionsArrayAPI.h:69
const Eigen::CwiseBinaryOp< Eigen::internal::scalar_polygamma_op< typename DerivedX::Scalar >, const DerivedN, const DerivedX > polygamma(const Eigen::ArrayBase< DerivedN > &n, const Eigen::ArrayBase< DerivedX > &x)
Definition SpecialFunctionsArrayAPI.h:103
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_bessel_j0_op< typename Derived::Scalar >, const Derived > bessel_j0(const Eigen::ArrayBase< Derived > &x)
Definition BesselFunctionsArrayAPI.h:207
const Eigen::CwiseBinaryOp< Eigen::internal::scalar_igamma_op< typename Derived::Scalar >, const Derived, const ExponentDerived > igamma(const Eigen::ArrayBase< Derived > &a, const Eigen::ArrayBase< ExponentDerived > &x)
Definition SpecialFunctionsArrayAPI.h:31
const Eigen::CwiseBinaryOp< Eigen::internal::scalar_zeta_op< typename DerivedX::Scalar >, const DerivedX, const DerivedQ > zeta(const Eigen::ArrayBase< DerivedX > &x, const Eigen::ArrayBase< DerivedQ > &q)
Definition SpecialFunctionsArrayAPI.h:141