Skip to content

bench: refactor random number generation in stats/base/dists/laplace #5270

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

Conversation

gkbishnoi07
Copy link
Contributor

Resolves #4976

Description

What is the purpose of this pull request?

This pull request:

  • Refactors random number generation in JS benchmarks for stats/base/dists/laplace.
  • Replaces randu() with uniform() for cleaner and more consistent code.
  • Moves the random number generation outside the benchmarking loops to improve efficiency.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request?

No.

Checklist

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

@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Feb 17, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Feb 17, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/laplace/cdf $\color{green}222/222$
$\color{green}+100.00\%$
$\color{green}21/21$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}222/222$
$\color{green}+100.00\%$
stats/base/dists/laplace/ctor $\color{green}488/488$
$\color{green}+100.00\%$
$\color{green}36/36$
$\color{green}+100.00\%$
$\color{green}19/19$
$\color{green}+100.00\%$
$\color{green}488/488$
$\color{green}+100.00\%$
stats/base/dists/laplace/entropy $\color{green}177/177$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}177/177$
$\color{green}+100.00\%$
stats/base/dists/laplace/kurtosis $\color{green}175/175$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}175/175$
$\color{green}+100.00\%$
stats/base/dists/laplace/logcdf $\color{green}222/222$
$\color{green}+100.00\%$
$\color{green}21/21$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}222/222$
$\color{green}+100.00\%$
stats/base/dists/laplace/logpdf $\color{green}219/219$
$\color{green}+100.00\%$
$\color{green}17/17$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}219/219$
$\color{green}+100.00\%$
stats/base/dists/laplace/mean $\color{green}112/112$
$\color{green}+100.00\%$
$\color{green}7/7$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}112/112$
$\color{green}+100.00\%$
stats/base/dists/laplace/median $\color{green}112/112$
$\color{green}+100.00\%$
$\color{green}7/7$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}112/112$
$\color{green}+100.00\%$
stats/base/dists/laplace/mgf $\color{green}236/236$
$\color{green}+100.00\%$
$\color{green}18/18$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}236/236$
$\color{green}+100.00\%$
stats/base/dists/laplace/mode $\color{green}175/175$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}175/175$
$\color{green}+100.00\%$
stats/base/dists/laplace/pdf $\color{green}218/218$
$\color{green}+100.00\%$
$\color{green}17/17$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}218/218$
$\color{green}+100.00\%$
stats/base/dists/laplace/quantile $\color{green}222/222$
$\color{green}+100.00\%$
$\color{green}21/21$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}222/222$
$\color{green}+100.00\%$
stats/base/dists/laplace/skewness $\color{green}175/175$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}175/175$
$\color{green}+100.00\%$
stats/base/dists/laplace/stdev $\color{green}176/176$
$\color{green}+100.00\%$
$\color{green}9/9$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}176/176$
$\color{green}+100.00\%$

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

@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc @kgryte please review this PRs

@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc @Planeshifter ready for review

@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc please review this PRs

@anandkaranubc
Copy link
Contributor

@anandkaranubc please review this PRs

On it!

@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc please review this PRs

On it!

thanks

@anandkaranubc anandkaranubc added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Feb 20, 2025
@anandkaranubc
Copy link
Contributor

anandkaranubc commented Feb 20, 2025

@gkbishnoi07, Can you also make the same changes that were made in #5296?

Specifically, the set::* benchmarks in ctor need their isnan checks updated.

The title should be updated to (for consistency):

bench: refactor random number generation in stats/base/dists/laplace

@gkbishnoi07
Copy link
Contributor Author

Can you also make the same changes that were made in #5296?

Specifically, the set::* benchmarks in ctor need their isnan checks updated.

Sure, I'll update you soon.

@gkbishnoi07 gkbishnoi07 changed the title bench: refactor random number generation in JS benchmarks for stats/base/dists/laplace bench: refactor random number generation in stats/base/dists/laplace Feb 21, 2025
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Feb 21, 2025
@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc please review this PRs

@anandkaranubc
Copy link
Contributor

Should I create an issue for changes in ctor?

@gkbishnoi07 Can you point out the files that need this change? Note that this change is only needed where the random number generation occurs outside the benchmarking loops.

Why? Because in cases like these, specifically in the ctor set::* benchmarks, y is being initialized as an array instead of a value. That is why the isnan(y) check appears to be a bug here.

@gkbishnoi07
Copy link
Contributor Author

Should I create an issue for changes in ctor?

@gkbishnoi07 Can you point out the files that need this change? Note that this change is only needed where the random number generation occurs outside the benchmarking loops.

Why? Because in cases like these, specifically in the ctor set::* benchmarks, y is being initialized as an array instead of a value. That is why the isnan(y) check appears to be a bug here.

@anandkaranubc Got it! I just noticed that some files still have random generation inside the benchmarking loop instead of using a uniform distribution.

First, I'm working on updating those files, and along the way, I'll implement insan(dist.*).

@anandkaranubc
Copy link
Contributor

I just noticed that some files still have random generation inside the benchmarking loop instead of using a uniform distribution.

Yes, and this change is being tracked in #4993. Ideally, this change should already be reflected in the respective PRs. If you have other PRs related to this tracking issue, please update them as well. Thanks!

@gkbishnoi07
Copy link
Contributor Author

I just noticed that some files still have random generation inside the benchmarking loop instead of using a uniform distribution.

Yes, and this change is being tracked in #4993. Ideally, this change should already be reflected in the respective PRs. If you have other PRs related to this tracking issue, please update them as well. Thanks!

Ok sure!

@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc, are you reviewing this PR now?

@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc i applied all changes please look out this PR

@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc please review this PRs

@anandkaranubc
Copy link
Contributor

@anandkaranubc please review this PRs

On it!

@anandkaranubc
Copy link
Contributor

anandkaranubc commented Mar 3, 2025

@gkbishnoi07 The PR still needs some changes.

@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Mar 3, 2025
@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc changes applied please review this PRs

@anandkaranubc
Copy link
Contributor

It's also good practice to keep your commit messages consistent with code conventions.

Here is the guide

@anandkaranubc anandkaranubc removed the Needs Review A pull request which needs code review. label Mar 3, 2025
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Mar 3, 2025
Copy link
Contributor

@anandkaranubc anandkaranubc left a comment

Choose a reason for hiding this comment

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

Please also confirm if the same change is consistent throughout the PR.

@anandkaranubc anandkaranubc removed the Needs Review A pull request which needs code review. label Mar 4, 2025
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Mar 4, 2025
@gkbishnoi07
Copy link
Contributor Author

gkbishnoi07 commented Mar 4, 2025

@anandkaranubc please review

Copy link
Contributor

@anandkaranubc anandkaranubc left a comment

Choose a reason for hiding this comment

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

Everything looks good now! Thanks for working on this.

@anandkaranubc anandkaranubc removed Needs Review A pull request which needs code review. Needs Changes Pull request which needs changes before being merged. labels Mar 4, 2025
@anandkaranubc anandkaranubc requested a review from stdlib-bot March 4, 2025 15:24
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Mar 4, 2025
@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc stdlib bot again give Needs Review label?

@anandkaranubc
Copy link
Contributor

@anandkaranubc stdlib bot again give Needs Review label?

Yes, the PR needs to go through the maintainers before it can be merged.
Be patient, and it will land soon.

@gkbishnoi07
Copy link
Contributor Author

@anandkaranubc stdlib bot again give Needs Review label?

Yes, the PR needs to go through the maintainers before it can be merged. Be patient, and it will land soon.

Okay,thanks

Copy link
Member

@Planeshifter Planeshifter left a comment

Choose a reason for hiding this comment

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

Thanks @gkbishnoi07 for your PR and @anandkaranubc for review. Let's get this one in. 🚀

@Planeshifter Planeshifter added the Ready To Merge A pull request which is ready to be merged. label Mar 5, 2025
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Mar 5, 2025
@stdlib-bot
Copy link
Contributor

PR Commit Message

bench: refactor random number generation in `stats/base/dists/laplace`

PR-URL: https://github.com/stdlib-js/stdlib/pull/5270
Closes: https://github.com/stdlib-js/stdlib/issues/4976

Co-authored-by: Gopi Kishan <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
Reviewed-by: anandkaranubc <[email protected]>

Please review the above commit message and make any necessary adjustments.

@Planeshifter Planeshifter merged commit e5238bb into stdlib-js:develop Mar 5, 2025
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First PR A pull request resolving a Good First Issue. Ready To Merge A pull request which is ready to be merged. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: Refactor random number generation in JS benchmarks for stats/base/dists/laplace
4 participants