Skip to content

bench: refactor random number generation in stats/base/dists/bernoulli #4775

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 5 commits into from
Jan 18, 2025

Conversation

anandkaranubc
Copy link
Contributor

Resolves none.

Description

What is the purpose of this pull request?

This pull request:

  • Refactors random number generation in JS benchmarks for stats/base/dists/bernoulli.
  • Replaces randu() with uniform() for cleaner and more consistent code.

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

@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 16, 2025
@anandkaranubc anandkaranubc marked this pull request as draft January 16, 2025 15:51
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Jan 16, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Jan 16, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/bernoulli/cdf $\color{green}215/215$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}215/215$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/ctor $\color{green}409/409$
$\color{green}+100.00\%$
$\color{green}26/26$
$\color{green}+100.00\%$
$\color{green}15/15$
$\color{green}+100.00\%$
$\color{green}409/409$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/entropy $\color{green}178/178$
$\color{green}+100.00\%$
$\color{green}12/12$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}178/178$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/kurtosis $\color{green}109/109$
$\color{green}+100.00\%$
$\color{green}7/7$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}109/109$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/mean $\color{green}165/165$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}165/165$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/median $\color{green}107/107$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}107/107$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/mgf $\color{green}195/195$
$\color{green}+100.00\%$
$\color{green}13/13$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}195/195$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/mode $\color{green}177/177$
$\color{green}+100.00\%$
$\color{green}11/11$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}177/177$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/pmf $\color{green}226/226$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}226/226$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/quantile $\color{green}224/224$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}224/224$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/skewness $\color{green}116/116$
$\color{green}+100.00\%$
$\color{green}11/11$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}116/116$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/stdev $\color{green}166/166$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}166/166$
$\color{green}+100.00\%$
stats/base/dists/bernoulli/variance $\color{green}107/107$
$\color{green}+100.00\%$
$\color{green}7/7$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}107/107$
$\color{green}+100.00\%$

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

…sts/bernoulli

---
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: 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: passed
  - task: run_c_examples
    status: passed
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: passed
  - task: run_c_benchmarks
    status: passed
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: passed
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: passed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: passed
  - task: run_c_examples
    status: passed
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: passed
  - task: run_c_benchmarks
    status: passed
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: passed
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: passed
---
@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Jan 16, 2025
@anandkaranubc
Copy link
Contributor Author

anandkaranubc commented Jan 16, 2025

Hi @kgryte,

I wanted to confirm a couple of things about these refactorings:

  1. Are we replacing all randu() expressions with uniform() for consistency, or only those where the minimum cannot be zero (e.g., randu() * 1.0 + EPS)?

  2. For expressions like round( randu() ), would it be better to use discreteUniform instead?

Thanks for the help!

@anandkaranubc anandkaranubc marked this pull request as ready for review January 16, 2025 16:02
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 16, 2025
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
Copy link
Member

kgryte commented Jan 16, 2025

Are we replacing all randu() expressions with uniform() for consistency, or only those where the minimum cannot be zero (e.g., randu() * 1.0 + EPS)?

All would be nice, not just those involving EPS.

For expressions like round( randu() ), would it be better to use discreteUniform instead?

Yes, discrete-uniform would be preferred.

@anandkaranubc
Copy link
Contributor Author

Are we replacing all randu() expressions with uniform() for consistency, or only those where the minimum cannot be zero (e.g., randu() * 1.0 + EPS)?

All would be nice, not just those involving EPS.

For expressions like round( randu() ), would it be better to use discreteUniform instead?

Yes, discrete-uniform would be preferred.

I meant even the ones like randu() * 20.0 or leave them like that?

@kgryte
Copy link
Member

kgryte commented Jan 16, 2025

I meant even the ones like randu() * 20.0 or leave them like that?

Yes, even those.

@anandkaranubc
Copy link
Contributor Author

anandkaranubc commented Jan 16, 2025

I meant even the ones like randu() * 20.0 or leave them like that?

Yes, even those.

Open to your feedback, @kgryte. Thanks!

@anandkaranubc anandkaranubc marked this pull request as draft January 16, 2025 22:33
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Jan 16, 2025
…/base/dists/bernoulli

---
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: 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: passed
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
…bc/stdlib into bernoulli-benchmarks

---
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: passed
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
@anandkaranubc anandkaranubc marked this pull request as ready for review January 18, 2025 06:11
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 18, 2025
@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 Jan 18, 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: 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: 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: passed
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
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. Thanks, @anandkaranubc!

@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 Jan 18, 2025
@kgryte kgryte merged commit 802775e into stdlib-js:develop Jan 18, 2025
29 checks passed
@anandkaranubc anandkaranubc deleted the bernoulli-benchmarks branch January 18, 2025 07:49
saurabhraghuvanshii pushed a commit to saurabhraghuvanshii/stdlib-gs that referenced this pull request Jan 18, 2025
saurabhraghuvanshii pushed a commit to saurabhraghuvanshii/stdlib-gs that referenced this pull request Jan 19, 2025
Neerajpathak07 pushed a commit to Neerajpathak07/stdlib that referenced this pull request Jan 23, 2025
Vinit-Pandit pushed a commit to Vinit-Pandit/stdlibMine that referenced this pull request Feb 4, 2025
ShabiShett07 pushed a commit to ShabiShett07/stdlib that referenced this pull request Feb 26, 2025
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. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants