Skip to content

bench: refactor random number generation in stats/base/dists/uniform #5027

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

Closed
wants to merge 1 commit into from

Conversation

MunishMummadi
Copy link

@MunishMummadi MunishMummadi commented Feb 2, 2025

This issue is related to #4991 i.e RFC:

Description

This PR has changes to benchmarking file located at stats/base/dists/uniform

This pull request:

  • Replaced rand() with corresponding uniform() implementation within the benchmarking files.

Questions

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 Statistics Issue or pull request related to statistical functionality. First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Needs Review A pull request which needs code review. labels Feb 2, 2025
Copy link
Contributor

@stdlib-bot stdlib-bot left a comment

Choose a reason for hiding this comment

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

👋 Hi there! 👋

And thank you for opening your first pull request! We will review it shortly. 🏃 💨

@stdlib-bot
Copy link
Contributor

stdlib-bot commented Feb 2, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/uniform/cdf $\color{green}225/225$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}225/225$
$\color{green}+100.00\%$
stats/base/dists/uniform/ctor $\color{green}479/479$
$\color{green}+100.00\%$
$\color{green}43/43$
$\color{green}+100.00\%$
$\color{green}18/18$
$\color{green}+100.00\%$
$\color{green}479/479$
$\color{green}+100.00\%$
stats/base/dists/uniform/entropy $\color{green}184/184$
$\color{green}+100.00\%$
$\color{green}7/7$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}184/184$
$\color{green}+100.00\%$
stats/base/dists/uniform/kurtosis $\color{green}119/119$
$\color{green}+100.00\%$
$\color{green}7/7$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}119/119$
$\color{green}+100.00\%$
stats/base/dists/uniform/logcdf $\color{green}229/229$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}229/229$
$\color{green}+100.00\%$
stats/base/dists/uniform/logpdf $\color{green}219/219$
$\color{green}+100.00\%$
$\color{green}23/23$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}219/219$
$\color{green}+100.00\%$
stats/base/dists/uniform/mean $\color{green}175/175$
$\color{green}+100.00\%$
$\color{green}7/7$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}175/175$
$\color{green}+100.00\%$
stats/base/dists/uniform/median $\color{green}175/175$
$\color{green}+100.00\%$
$\color{green}7/7$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}175/175$
$\color{green}+100.00\%$
stats/base/dists/uniform/mgf $\color{green}235/235$
$\color{green}+100.00\%$
$\color{green}21/21$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}235/235$
$\color{green}+100.00\%$
stats/base/dists/uniform/pdf $\color{green}287/287$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}287/287$
$\color{green}+100.00\%$
stats/base/dists/uniform/quantile $\color{green}215/215$
$\color{green}+100.00\%$
$\color{green}22/22$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}215/215$
$\color{green}+100.00\%$
stats/base/dists/uniform/skewness $\color{green}119/119$
$\color{green}+100.00\%$
$\color{green}7/7$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}119/119$
$\color{green}+100.00\%$
stats/base/dists/uniform/stdev $\color{green}122/122$
$\color{green}+100.00\%$
$\color{green}5/5$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}122/122$
$\color{green}+100.00\%$
stats/base/dists/uniform/variance $\color{green}182/182$
$\color{green}+100.00\%$
$\color{green}7/7$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}182/182$
$\color{green}+100.00\%$

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

@anandkaranubc
Copy link
Contributor

Thanks, @MunishMummadi, for working on this! I've left a few suggestions for you to review.

Also, can you change the title to:

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

@MunishMummadi MunishMummadi changed the title feat: refactor benchmarking files at stats/base/dists/uniform bench: refactor random number generation in stats/base/dists/uniform Feb 2, 2025
@MunishMummadi
Copy link
Author

Sure, I have updated the title.

@MunishMummadi
Copy link
Author

@anandkaranubc I don't see any code review. If that's what you mean by suggestions. Please correct me if I am wrong.

Comment on lines 41 to 43
x = uniform( -10.0, 10.0);
min = uniform( -20.0, 0.0);
max = min + uniform( 0.0, 40.0);
Copy link
Contributor

Choose a reason for hiding this comment

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

The random number generation should be moved outside the benchmarking loop, before b.tic().

Copy link
Author

Choose a reason for hiding this comment

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

The random number generation should be moved outside the benchmarking loop, before b.tic().

I have a question about this suggestion. Are you expecting this change only for this file or to the complete PR.

Copy link
Contributor

@anandkaranubc anandkaranubc Feb 4, 2025

Choose a reason for hiding this comment

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

Yes, this change is expected in the complete PR. One of the main reasons for this refactoring is to ensure that random number generation does not interfere with benchmarking. Reference PRs would be a good source to verify if your changes are correct.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the confirmation. I thought so, I will update soon.

@anandkaranubc
Copy link
Contributor

@anandkaranubc I don't see any code review. If that's what you mean by suggestions. Please correct me if I am wrong.

Sorry, my bad. They should be visible now.

@anandkaranubc anandkaranubc added the Needs Changes Pull request which needs changes before being merged. label Feb 3, 2025
@MunishMummadi MunishMummadi marked this pull request as draft February 3, 2025 19:01
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Feb 3, 2025
@MunishMummadi MunishMummadi marked this pull request as ready for review February 3, 2025 23:05
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Feb 3, 2025
@MunishMummadi
Copy link
Author

MunishMummadi commented Feb 3, 2025

@anandkaranubc I also added changes where they seem fit. i have doubts about the b.tic() i commented about it on the code review.
edit: changed to changes

@MunishMummadi MunishMummadi marked this pull request as draft February 4, 2025 20:55
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Feb 4, 2025
Comment on lines +39 to +42
x = uniform( -10.0, 10.0 );
min = uniform( -20.0, 0.0 );
max = uniform( min, min + 40.0 );

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
x = uniform( -10.0, 10.0 );
min = uniform( -20.0, 0.0 );
max = uniform( min, min + 40.0 );
len = 100;
x = new Float64Array( len );
min = new Float64Array( len );
max = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( -10.0, 10.0 );
min[ i ] = uniform( -20.0, 0.0 );
max[ i ] = uniform( min[ i ], min[ i ] + 40.0 );
}

This would be the correct way to initialize random values for the variables.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for this update. This really helps!!!

@Planeshifter
Copy link
Member

Meanwhile #5176 was merged, so this PR won't be needed anymore. Thanks for your efforts, @MunishMummadi, which we appreciate!

@MunishMummadi MunishMummadi deleted the 4991 branch February 15, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Needs Changes Pull request which needs changes before being merged. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants