Skip to content

refactor: update benchmarks and tests in math/base/special/acosh #5318

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 2 commits into from
Feb 20, 2025

Conversation

anandkaranubc
Copy link
Contributor

@anandkaranubc anandkaranubc commented Feb 19, 2025

Resolves none.

Description

What is the purpose of this pull request?

This pull request:

  • Refactors random number generation in JS benchmarks for math/base/special/acosh
  • Replaces randu() with uniform() from @stdlib/random/array/uniform for cleaner and more consistent code.
  • Moves the random number generation outside the benchmarking loops.
  • Updates the test messages to follow code conventions.

Related Issues

Does this pull request have any related issues?

This pull request:

  • resolves none

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

---
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: 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: missing_dependencies
  - 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: 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-bot stdlib-bot added Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review. labels Feb 19, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Feb 19, 2025

Coverage Report

Package Statements Branches Functions Lines
math/base/special/acosh $\color{green}217/217$
$\color{green}+100.00\%$
$\color{green}14/14$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}217/217$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@anandkaranubc
Copy link
Contributor Author

The non-exact tests in the test files were also removed because they were not being executed.

A follow-up question regarding this refactoring: The refactoring is mainly being done for C/C++ or JS benchmarks. Is there a need to apply it to the Julia, R, or Python benchmarks as well? I believe so..?

@kgryte
Copy link
Member

kgryte commented Feb 19, 2025

Is there a need to apply it to the Julia, R, or Python benchmarks as well?

@anandkaranubc Technically, yes, but this is very low priority, so I think we can punt to the future.

@@ -59,19 +56,13 @@ tape( 'the function computes the hyperbolic arccosine on the interval [1.0,3.0]'
y = acosh( x[i] );
if ( y === expected[ i ] ) {
t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anandkaranubc These changes should be reverted or you need to remove the if branch. Right now, if we were to update the test fixtures and the upstream values were to change, we would not catch that, as you now only assert when the values are equal. In this case, the approximate branch was included as a fallback in case values were to ever differ.

Copy link
Contributor Author

@anandkaranubc anandkaranubc Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will revert those. Is this different from what's being done in stats/base/dists/*. It was pointed out to me by @Neerajpathak07 in one of my PRs. Discussion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anandkaranubc That comment applies to naive calculations. See the C implementation: https://github.com/stdlib-js/stdlib/pull/3974/files#diff-88bd0b2a5a78d2d32485c3217f1784e428ebf5cae61ec45eb5a1b872f400e0d7. In that implementation, there is no computation. Here, for acosh, we would, however, expect some approximate results due to floating-point rounding error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhh, I see! Sorry, I overlooked that. Thanks for the clarification.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Feb 19, 2025
---
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: 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: 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: passed
---
Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kgryte kgryte added Benchmarks Pull requests adding or improving benchmarks for measuring performance. and removed Needs Changes Pull request which needs changes before being merged. labels Feb 20, 2025
@kgryte kgryte merged commit 54e5f3f into stdlib-js:develop Feb 20, 2025
29 checks passed
@anandkaranubc anandkaranubc deleted the acosh-benchmarks branch February 20, 2025 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Benchmarks Pull requests adding or improving benchmarks for measuring performance. Math Issue or pull request specific to math functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants