-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[libc++][math] Mathematical Special Functions: Hermite Polynomial #89982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
37880b0
apply original diff from D58876
PaulXiCao f73bb1b
moved new files into math/
PaulXiCao 5d6b824
cmake: fix include by adding new files to file listing
PaulXiCao b4a313a
move test files from internal libcxx/ into std/
PaulXiCao 3871157
replace "_VSTD" by "std". similar to D117811
PaulXiCao 4e50b18
replace deprecated _LIBCPP_INLINE_VISIBILITY by _LIBCPP_HIDE_FROM_ABI
PaulXiCao a158fe8
hermite tests succeed! (fixed compiler warning: shadowing variable)
PaulXiCao 9938c1a
laguerre tests succeeds! (fixed compiler warning: shadowing variable)
PaulXiCao 87b240d
legendre tests succeeds! (fixed compiler warning: shadowing variable)
PaulXiCao 6add3f4
assoc_laguerre tests succeeds! (fixed compiler warning: shadowing var…
PaulXiCao d34933d
assoc_legendre tests succeeds! (fixed compiler warning: shadowing var…
PaulXiCao b13a000
hermite: fix documentation comment
PaulXiCao 2333750
hermite: minor code changes: rename variables, brace initialization
PaulXiCao 188edd1
create experimental/math module
PaulXiCao 073ae40
set header info for lit
PaulXiCao 8f4573b
keeping only hermite, i.e. remove laguerre, legendre
PaulXiCao 622cb1a
remove explicit type conversions
PaulXiCao 23ffb72
use more readable variable names
PaulXiCao 390947d
make use of function template argument deduction
PaulXiCao f9b489b
constness of passed arguments
PaulXiCao cbcef27
unify return path via ternary op
PaulXiCao 48268c9
clang format
PaulXiCao 7c4a14a
cleanup preprocessor usage
PaulXiCao 57cdb04
sufficient additional overloads by LWG 3234
PaulXiCao a42128e
simplify hermite(float)
PaulXiCao d0500d9
implement: template<class Integer> double hermite(unsigned, Integer)
PaulXiCao 711a757
remove old comment
PaulXiCao ece1daf
make use of Lit: // UNSUPPORTED: c++XX
PaulXiCao 5bba7f1
cleanup tests
PaulXiCao 6f0006b
update docs/Status
PaulXiCao b60044d
modulemap include private headers
PaulXiCao e33c6d9
remove doxygen style file comment
PaulXiCao 135e5e7
move out of experimental/
PaulXiCao 161349b
all functions need _LIBCPP_HIDE_FROM_API
PaulXiCao f87416c
remove `std::` similar to other surrounding code
PaulXiCao 12574b8
include missing header: type_traits/is_integral
PaulXiCao 6199348
test: place Lit comment correctly
PaulXiCao 6f5e9eb
don't use yoda conditional
PaulXiCao adbe52b
edits according to mentioned style issues
PaulXiCao aca72ce
shorten internal hermite function's name
PaulXiCao 445f6b1
style format of template argument
PaulXiCao b2aa559
fully qualify function calls
PaulXiCao 9fb7f78
test: style changes, renaming, etc.
PaulXiCao 778d8ff
status page
PaulXiCao 7a329b9
remove dead code: lit header comments
PaulXiCao 1bc981b
remove comment about integer->double conversion
PaulXiCao d8e41c8
specify implementation-defined behavior: hermite(n,x) for n>=128
PaulXiCao df553a6
hermite(unsigned, _Integer): changed SFINAE usage
PaulXiCao 9f11623
link status page from general C++17 status page
PaulXiCao d5b4b49
move implementation from include/cmath to include/__math/special_func…
PaulXiCao f77fd3c
simplify NaN handling (no conversion)
PaulXiCao 68cee2f
simplify status documentation: single paper needs no table
PaulXiCao 68eef29
assign std::hermite to myself
PaulXiCao 379b6df
remove anonymous namespace in test file
PaulXiCao c0f15bf
test: add synopsis
PaulXiCao aaf8364
test: remove unused include
PaulXiCao c264bad
test: sort includes
PaulXiCao 097d622
test: refactor/style change. only test<T>() within main()
PaulXiCao b5cee48
test: make use of types::for_each
PaulXiCao 2275201
test: replace exception throwing by assert
PaulXiCao d69176d
test: additional sample points with abs(x)>1
PaulXiCao 25f6c80
test: checks for x=+-inf as input
PaulXiCao 6cd8c7f
handle overflows
PaulXiCao 965dfb6
index.rst: add special math status page to TOC
PaulXiCao 44b7b80
cmath.inc: uncomment std::hermite functions
PaulXiCao 932e084
cmath: added implemented functions to synopsis
PaulXiCao 473f600
cmath: add hermite{l,f} to synopsis
PaulXiCao 6932143
test: format test's synopsis
PaulXiCao 4af48df
get rid of doxygen-style comments
PaulXiCao 8755100
test: renamed MAX_N to g_max_n
PaulXiCao 4fe24ae
test: assert(false) instead of assert(0)
PaulXiCao 34bd197
test: inf result for finite input
PaulXiCao 4580bf0
rename to use ugly name: inf -> __inf
PaulXiCao d68145c
silence clang-tidy warning about variable name in math code
PaulXiCao 1a66064
test: add more values for integeral x
PaulXiCao f01e17a
export functions for module usage
PaulXiCao bb43f5a
Revert "export functions for module usage"
PaulXiCao bc27d9c
Adds a work-around to pass the module tests.
PaulXiCao 7cb43b0
fix test: unsupported case must also return a value
PaulXiCao 6a6fce8
remove wrongly added code
PaulXiCao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.. special-math-status: | ||
PaulXiCao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
====================================================== | ||
libc++ Mathematical Special Functions Status (P0226R1) | ||
====================================================== | ||
|
||
.. include:: ../Helpers/Styles.rst | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Overview | ||
======== | ||
|
||
This document contains the status of the C++17 mathematical special functions implementation in libc++. | ||
It is used to track both the status of the sub-projects of the effort and who is assigned to these sub-projects. | ||
This avoids duplicating effort. | ||
|
||
If you are interested in contributing to this effort, please send a message | ||
to the #libcxx channel in the LLVM discord. Please *do not* start working | ||
on any items below that has already been assigned to someone else. | ||
|
||
Sub-projects in the Implementation Effort | ||
========================================= | ||
|
||
.. csv-table:: | ||
:file: SpecialMathProjects.csv | ||
:header-rows: 1 | ||
:widths: auto | ||
|
||
Paper and Issue Status | ||
====================== | ||
|
||
The underlying paper is `Mathematical Special Functions for C++17 (P0226) <https://wg21.link/P0226>`_ and is included in C++17. | ||
Implementation is *In Progress*. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Section,Description,Assignee,Complete | ||
| `[sf.cmath.assoc.laguerre] <https://wg21.link/sf.cmath.assoc.laguerre>`_, std::assoc_laguerre, None, |Not Started| | ||
| `[sf.cmath.assoc.legendre] <https://wg21.link/sf.cmath.assoc.legendre>`_, std::assoc_legendre, None, |Not Started| | ||
| `[sf.cmath.beta] <https://wg21.link/sf.cmath.beta>`_, std::beta, None, |Not Started| | ||
| `[sf.cmath.comp.ellint.1] <https://wg21.link/sf.cmath.comp.ellint.1>`_, std::comp_ellint_1, None, |Not Started| | ||
| `[sf.cmath.comp.ellint.2] <https://wg21.link/sf.cmath.comp.ellint.2>`_, std::comp_ellint_2, None, |Not Started| | ||
| `[sf.cmath.comp.ellint.3] <https://wg21.link/sf.cmath.comp.ellint.3>`_, std::comp_ellint_3, None, |Not Started| | ||
| `[sf.cmath.cyl.bessel.i] <https://wg21.link/sf.cmath.cyl.bessel.i>`_, std::cyl_bessel_i, None, |Not Started| | ||
| `[sf.cmath.cyl.bessel.j] <https://wg21.link/sf.cmath.cyl.bessel.j>`_, std::cyl_bessel_j, None, |Not Started| | ||
| `[sf.cmath.cyl.bessel.k] <https://wg21.link/sf.cmath.cyl.bessel.k>`_, std::cyl_bessel_k, None, |Not Started| | ||
| `[sf.cmath.cyl.neumann] <https://wg21.link/sf.cmath.cyl.neumann>`_, std::cyl_neumann, None, |Not Started| | ||
| `[sf.cmath.ellint.1] <https://wg21.link/sf.cmath.ellint.1>`_, std::ellint_1, None, |Not Started| | ||
| `[sf.cmath.ellint.2] <https://wg21.link/sf.cmath.ellint.2>`_, std::ellint_2, None, |Not Started| | ||
| `[sf.cmath.ellint.3] <https://wg21.link/sf.cmath.ellint.3>`_, std::ellint_3, None, |Not Started| | ||
| `[sf.cmath.expint] <https://wg21.link/sf.cmath.expint>`_, std::expint, None, |Not Started| | ||
| `[sf.cmath.hermite] <https://wg21.link/sf.cmath.hermite>`_, std::hermite, Paul Xi Cao, |Complete| | ||
| `[sf.cmath.laguerre] <https://wg21.link/sf.cmath.laguerre>`_, std::laguerre, None, |Not Started| | ||
| `[sf.cmath.legendre] <https://wg21.link/sf.cmath.legendre>`_, std::legendre, None, |Not Started| | ||
| `[sf.cmath.riemann.zeta] <https://wg21.link/sf.cmath.riemann.zeta>`_, std::riemann_zeta, None, |Not Started| | ||
| `[sf.cmath.sph.bessel] <https://wg21.link/sf.cmath.sph.bessel>`_, std::sph_bessel, None, |Not Started| | ||
| `[sf.cmath.sph.legendre] <https://wg21.link/sf.cmath.sph.legendre>`_, std::sph_legendre, None, |Not Started| | ||
| `[sf.cmath.sph.neumann] <https://wg21.link/sf.cmath.sph.neumann>`_, std::sph_neumann, None, |Not Started| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// -*- C++ -*- | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___MATH_SPECIAL_FUNCTIONS_H | ||
#define _LIBCPP___MATH_SPECIAL_FUNCTIONS_H | ||
|
||
#include <__config> | ||
#include <__math/copysign.h> | ||
#include <__math/traits.h> | ||
#include <__type_traits/enable_if.h> | ||
#include <__type_traits/is_integral.h> | ||
#include <limits> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
#if _LIBCPP_STD_VER >= 17 | ||
|
||
template <class _Real> | ||
_LIBCPP_HIDE_FROM_ABI _Real __hermite(unsigned __n, _Real __x) { | ||
// The Hermite polynomial H_n(x). | ||
// The implementation is based on the recurrence formula: H_{n+1}(x) = 2x H_n(x) - 2n H_{n-1}. | ||
// Press, William H., et al. Numerical recipes 3rd edition: The art of scientific computing. | ||
PaulXiCao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Cambridge university press, 2007, p. 183. | ||
|
||
// NOLINTBEGIN(readability-identifier-naming) | ||
if (__math::isnan(__x)) | ||
return __x; | ||
|
||
_Real __H_0{1}; | ||
if (__n == 0) | ||
return __H_0; | ||
|
||
_Real __H_n_prev = __H_0; | ||
_Real __H_n = 2 * __x; | ||
for (unsigned __i = 1; __i < __n; ++__i) { | ||
_Real __H_n_next = 2 * (__x * __H_n - __i * __H_n_prev); | ||
__H_n_prev = __H_n; | ||
__H_n = __H_n_next; | ||
} | ||
|
||
if (!__math::isfinite(__H_n)) { | ||
// Overflow occured. Two possible cases: | ||
// n is odd: return infinity of the same sign as x. | ||
// n is even: return +Inf | ||
_Real __inf = std::numeric_limits<_Real>::infinity(); | ||
return (__n & 1) ? __math::copysign(__inf, __x) : __inf; | ||
} | ||
return __H_n; | ||
// NOLINTEND(readability-identifier-naming) | ||
} | ||
|
||
inline _LIBCPP_HIDE_FROM_ABI double hermite(unsigned __n, double __x) { return std::__hermite(__n, __x); } | ||
|
||
inline _LIBCPP_HIDE_FROM_ABI float hermite(unsigned __n, float __x) { | ||
// use double internally -- float is too prone to overflow! | ||
return static_cast<float>(std::hermite(__n, static_cast<double>(__x))); | ||
} | ||
|
||
inline _LIBCPP_HIDE_FROM_ABI long double hermite(unsigned __n, long double __x) { return std::__hermite(__n, __x); } | ||
|
||
inline _LIBCPP_HIDE_FROM_ABI float hermitef(unsigned __n, float __x) { return std::hermite(__n, __x); } | ||
|
||
inline _LIBCPP_HIDE_FROM_ABI long double hermitel(unsigned __n, long double __x) { return std::hermite(__n, __x); } | ||
|
||
template <class _Integer, std::enable_if_t<std::is_integral_v<_Integer>, int> = 0> | ||
_LIBCPP_HIDE_FROM_ABI double hermite(unsigned __n, _Integer __x) { | ||
return std::hermite(__n, static_cast<double>(__x)); | ||
} | ||
|
||
#endif // _LIBCPP_STD_VER >= 17 | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___MATH_SPECIAL_FUNCTIONS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked whether the results actually make sense beyond 128?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only check upto
n<128
.By the nature of it we can only check upto some finite value and this given value from the Standard seemed reasonable. Also note that our implementation does not distinguish between different orders (e.g. nothing like below/above any threshold). Do you think that we should increase the test coverage for the parameters?