Debian Codegraph @

third-party/boost-math/include/boost/math/special_functions/hermite.hpp

raw
1
2 // (C) Copyright John Maddock 2006.
3 // (C) Copyright Matt Borland 2024.
4 // Use, modification and distribution are subject to the
5 // Boost Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
8 #ifndef BOOST_MATH_SPECIAL_HERMITE_HPP
9 #define BOOST_MATH_SPECIAL_HERMITE_HPP
10
11 #ifdef _MSC_VER
12 #pragma once
13 #endif
14
15 #include <boost/math/tools/config.hpp>
16 #include <boost/math/tools/promotion.hpp>
17 #include <boost/math/special_functions/math_fwd.hpp>
18 #include <boost/math/policies/error_handling.hpp>
19
20 namespace boost{
21 namespace math{
22
23 // Recurrence relation for Hermite polynomials:
24 template <class T1, class T2, class T3>
25 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2, T3>::type
26 hermite_next(unsigned n, T1 x, T2 Hn, T3 Hnm1)
27 {
28 using promoted_type = tools::promote_args_t<T1, T2, T3>;
29 return (2 * promoted_type(x) * promoted_type(Hn) - 2 * n * promoted_type(Hnm1));
30 }
31
32 namespace detail{
33
34 // Implement Hermite polynomials via recurrence:
35 template <class T>
36 BOOST_MATH_GPU_ENABLED T hermite_imp(unsigned n, T x)
37 {
38 T p0 = 1;
39 T p1 = 2 * x;
40
41 if(n == 0)
42 return p0;
43
44 unsigned c = 1;
45
46 while(c < n)
47 {
48 BOOST_MATH_GPU_SAFE_SWAP(p0, p1);
49 p1 = static_cast<T>(hermite_next(c, x, p0, p1));
50 ++c;
51 }
52 return p1;
53 }
54
55 } // namespace detail
56
57 template <class T, class Policy>
58 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type
59 hermite(unsigned n, T x, const Policy&)
60 {
61 typedef typename tools::promote_args<T>::type result_type;
62 typedef typename policies::evaluation<result_type, Policy>::type value_type;
63 return policies::checked_narrowing_cast<result_type, Policy>(detail::hermite_imp(n, static_cast<value_type>(x)), "boost::math::hermite<%1%>(unsigned, %1%)");
64 }
65
66 template <class T>
67 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type
68 hermite(unsigned n, T x)
69 {
70 return boost::math::hermite(n, x, policies::policy<>());
71 }
72
73 } // namespace math
74 } // namespace boost
75
76 #endif // BOOST_MATH_SPECIAL_HERMITE_HPP
77
78
79