feat: add C & JS implementation of math/base/special/digammaf#10265
feat: add C & JS implementation of math/base/special/digammaf#10265officiallyanee wants to merge 6 commits intostdlib-js:developfrom
math/base/special/digammaf#10265Conversation
---
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: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: passed
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: passed
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: passed
- task: lint_c_examples
status: passed
- task: lint_c_benchmarks
status: passed
- 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
---
Coverage Report
The above coverage report was generated for the changes in this PR. |
---
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: 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: na
- task: lint_license_headers
status: passed
---
|
The issue regarding coverage: I tried to run test.native.js locally and it was running if i deleted test.js but both were not running together. |
gunjjoshi
left a comment
There was a problem hiding this comment.
@officiallyanee You can go through the implementation of @stdlib/math/base/special/digamma once and refactor the implementation in this PR. Currently, it seems more close to how it is in Cephes, but there are some conventions that need to be followed while implementing a function from a reference implementation.
| * | ||
| * ## Notice | ||
| * | ||
| * The original C code, long comment, copyright, license, and constants are from [Cephes]{@link http://www.netlib.org/cephes}. The implementation follows the original, but has been modified for JavaScript. |
There was a problem hiding this comment.
The double-precision implementation uses boost, as the reference implementation, but here you have referred to Cephes. Is there any particular reason for that?
There was a problem hiding this comment.
I went through various single precision packages and saw preferred reference for single precision packages seemed to Cephes since it has a separate implementation for float32 version of functions. Is that fine?
| float p, q, nz, s, w, y, z; | ||
| int32_t i, n, negative; |
There was a problem hiding this comment.
We must declare only one variable per line.
| y += 1.0f / w; | ||
| } | ||
| y -= STDLIB_CONSTANT_FLOAT32_EULERGAMMA; | ||
| goto done; |
There was a problem hiding this comment.
We should avoid using goto statements. In this case, for instance, you can directly return y after conditionally decrementing nz from it, based on the value of negative.
| return x; | ||
| } | ||
|
|
||
| // Handle negative arguments using reflection formula |
There was a problem hiding this comment.
Comments must end with either ... or :, here and at all other places.
---
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: passed
- 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: na
- task: lint_license_headers
status: passed
---
| * var v = digammaf( NaN ); | ||
| * // returns NaN | ||
| */ | ||
| function digammaf(x) { |
There was a problem hiding this comment.
All the JavaScript files in this PR are missing spaces around function call arguments and inside control-flow parentheses. The stdlib style guide requires spaces around arguments (e.g., foo( bar ) not foo(bar)) and inside if/for/while parentheses (e.g., if ( condition ) not if (condition)).
This needs to be fixed throughout all .js files in this PR.
|
|
||
| for (i = 0; i < x.length; i++) { | ||
| y = digammaf(x[i]); | ||
| e = expected[i]; |
There was a problem hiding this comment.
The expected values from the Julia fixtures are Float64. In test.js you correctly wrap them with float64ToFloat32( expected[i] ), but here in the native tests you're comparing raw Float64 expected values against Float32 results. You should import float64ToFloat32 and wrap the expected values here too, same as in test.js. See math/base/special/lnf/test/test.native.js for a reference that does this correctly.
| #include "stdlib/math/base/special/cotf.h" | ||
| #include "stdlib/math/base/assert/is_nanf.h" | ||
| #include "stdlib/constants/float32/pi.h" | ||
| #include "stdlib/constants/float32/max.h" |
There was a problem hiding this comment.
This #include for stdlib/constants/float32/max.h is unused — STDLIB_CONSTANT_FLOAT32_MAX doesn't appear anywhere in the implementation. Let's remove it, and also remove @stdlib/constants/float32/max from the dependencies arrays in manifest.json.
| #include "stdlib/constants/float32/max.h" |
|
|
||
| module.exports = main; | ||
|
|
||
| // exports: { "digammaf": "main" } |
There was a problem hiding this comment.
This // exports: comment isn't standard for math/base/special packages. Let's remove this line.
| // exports: { "digammaf": "main" } |
| #include "stdlib/math/base/special/digammaf.h" | ||
| #include "stdlib/math/base/napi/unary.h" | ||
|
|
||
| STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_digammaf ) |
There was a problem hiding this comment.
This directory is missing a src/Makefile (for cleaning build artifacts). Every stdlib C package includes one — see e.g. math/base/special/digamma/src/Makefile. You can copy it directly from any existing package since they're all identical.
---
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: passed
- 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: na
- task: lint_license_headers
status: passed
---
…mmaf
---
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: 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: 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: passed
- 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: na
- task: lint_license_headers
status: passed
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes. report:
Progresses #649
Description
This pull request:
Related Issues
This pull request has the following related issues:
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
{{TODO: add disclosure if applicable}}
@stdlib-js/reviewers