-
-
Notifications
You must be signed in to change notification settings - Fork 813
feat: add math/base/special/chebyshev-t-polynomial
#5774
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
base: develop
Are you sure you want to change the base?
feat: add math/base/special/chebyshev-t-polynomial
#5774
Conversation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: passed - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
/stdlib update-copyright-years |
Coverage Report
The above coverage report was generated for the changes in this PR. |
Time to bring Once this is approved, I will also add its respective C implementation. 😄 |
delta = abs( y - expected[ i ] ); | ||
|
||
// NOTE: The tolerance is higher due to the numerical differences between the `hyp2f1` implementation in JavaScript and its reference implementation in SciPy. | ||
tol = 755.0 * EPS * abs( expected[ i ] ); |
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 expected this from the start. Fortunately, they are not as crazy as hyp2f1
. The test coverage report also confirms that this function only uses parts of the helper functions hyp2f1ra
and hys2f1
that rely on evaluating the hypergeometric function through power series expansion. Thus, numerical differences…
lib/node_modules/@stdlib/math/base/special/chebyshev-t-polynomial/README.md
Show resolved
Hide resolved
lib/node_modules/@stdlib/math/base/special/chebyshev-t-polynomial/README.md
Outdated
Show resolved
Hide resolved
|
||
def main(): | ||
"""Generate fixture data.""" | ||
x = np.linspace(-1, 1, 1000) |
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.
In the text fixture generation, I have kept x
in the [-1,1]
range, where these polynomials are typically considered. Is it also necessary to test outside of this interval?
For |x| > 1
, the polynomials grow exponentially rather than oscillating. Our implementation can handle that since there is no restriction on x
.
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'm fine leaving it in [-1,1]
is that is the typical range.
) { | ||
return NaN; | ||
} | ||
return hyp2f1( -n, n, 0.5, 0.5*(1-x) ); |
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.
No restrictions on x
over here :)
Signed-off-by: Karan Anand <119553199+anandkaranubc@users.noreply.github.com>
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
Co-authored-by: Karan Anand <119553199+anandkaranubc@users.noreply.github.com> Signed-off-by: Athan <kgryte@gmail.com>
|
||
# chebyshevtpoly | ||
|
||
> [Chebyshev Polynomial][chebyshev-polynomial] of the first kind. |
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.
> [Chebyshev Polynomial][chebyshev-polynomial] of the first kind. | |
> [Chebyshev polynomial][chebyshev-polynomial] of the first kind. |
"polynomial" does not need to be capitalized. Applies here and elsewhere throughout this package.
|
||
where `n` is the polynomial degree. | ||
|
||
The [Chebyshev Polynomial][chebyshev-polynomial] of the first kind is related to the Gaussian hypergeometric function via the following equation |
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.
The [Chebyshev Polynomial][chebyshev-polynomial] of the first kind is related to the Gaussian hypergeometric function via the following equation | |
The [Chebyshev Polynomial][chebyshev-polynomial] of the first kind is related to the [Gaussian hypergeometric function][@stdlib/math/base/special/hyp2f1] via the following equation |
You'll need to add the link defn below in the links section. Also double-check that I used the correct package name.
// returns NaN | ||
``` | ||
|
||
If provided a polynomial degree `n` which is not a nonnegative integer, the function returns `NaN`. |
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.
Why do we restrict to only integer degrees? Why not follow SciPy and state that non-integer values are resolved relative to the hypergeometric function?
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var randu = require( '@stdlib/random/base/randu' ); |
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.
We can update this example to use console/log-each-map
.
|
||
<section class="links"> | ||
|
||
[chebyshev-polynomial]: https://en.wikipedia.org/wiki/Chebyshev_polynomials#Definitions |
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.
You can drop #Definitions
here.
@@ -0,0 +1,38 @@ | |||
|
|||
{{alias}}( n, x ) | |||
Evaluates the Chebyshev polynomial of the first kind |
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.
Your line wrapping is off here.
'use strict'; | ||
|
||
var randu = require( '@stdlib/random/base/randu' ); | ||
var round = require( '@stdlib/math/base/special/round' ); |
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.
Same comment as README.
function chebyshevtpoly( n, x ) { | ||
if ( | ||
isnan( x ) || | ||
!isInteger( n ) || |
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.
Not clear to me that we need to apply this restriction.
) { | ||
return NaN; | ||
} | ||
return hyp2f1( -n, n, 0.5, 0.5*(1.0-x) ); |
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.
For integer x
, why not use the recurrence relation directly, as in SciPy?
{ | ||
"name": "@stdlib/math/base/special/chebyshev-t-polynomial", | ||
"version": "0.0.0", | ||
"description": "Evaluates the Chebyshev polynomial of the first kind.", |
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.
"description": "Evaluates the Chebyshev polynomial of the first kind.", | |
"description": "Evaluate the Chebyshev polynomial of the first kind.", |
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.
Left an initial round of comments.
Progresses #123
Description
This pull request:
x
.Related Issues
This pull request:
x
#123Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers