Skip to content

bench: refactor random number generation in JS benchmarks for stats/b… #5162

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

yaswanthkosuru
Copy link
Contributor

Resolves #4982.

Description

What is the purpose of this pull request?

This pull request:

  • Refactor random number generation in JS benchmarks for stats/base/dists/pareto-type1

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? 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

…ase/dists/pareto-type1

---
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: 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 Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Feb 10, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Feb 10, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/pareto-type1/cdf $\color{green}239/239$
$\color{green}+100.00\%$
$\color{green}23/23$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}239/239$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/ctor $\color{green}438/438$
$\color{green}+100.00\%$
$\color{green}32/32$
$\color{green}+100.00\%$
$\color{green}17/17$
$\color{green}+100.00\%$
$\color{green}438/438$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/entropy $\color{green}126/126$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}126/126$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/kurtosis $\color{green}128/128$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}128/128$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/logcdf $\color{green}243/243$
$\color{green}+100.00\%$
$\color{green}23/23$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}243/243$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/logpdf $\color{green}251/251$
$\color{green}+100.00\%$
$\color{green}23/23$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}251/251$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/mean $\color{green}122/122$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}122/122$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/median $\color{green}119/119$
$\color{green}+100.00\%$
$\color{green}6/6$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}119/119$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/mode $\color{green}124/124$
$\color{green}+100.00\%$
$\color{green}8/8$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}124/124$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/pdf $\color{green}251/251$
$\color{green}+100.00\%$
$\color{green}23/23$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}251/251$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/quantile $\color{green}235/235$
$\color{green}+100.00\%$
$\color{green}23/23$
$\color{green}+100.00\%$
$\color{green}3/3$
$\color{green}+100.00\%$
$\color{green}235/235$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/skewness $\color{green}196/196$
$\color{green}+100.00\%$
$\color{green}10/10$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}196/196$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/stdev $\color{green}203/203$
$\color{green}+100.00\%$
$\color{green}12/12$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}203/203$
$\color{green}+100.00\%$
stats/base/dists/pareto-type1/variance $\color{green}129/129$
$\color{green}+100.00\%$
$\color{green}10/10$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}129/129$
$\color{green}+100.00\%$

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

@yaswanthkosuru
Copy link
Contributor Author

@Planeshifter ready for review

@anandkaranubc
Copy link
Contributor

Great work, @yaswanthkosuru. Just some minor changes, otherwise the PR looks good!

@anandkaranubc anandkaranubc added the Needs Changes Pull request which needs changes before being merged. label Feb 10, 2025
…stats/base/dists/pareto-type1

---
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
---
@yaswanthkosuru
Copy link
Contributor Author

yaswanthkosuru commented Feb 10, 2025

@anandkaranubc addressed all changes can you please review.hoping no changes required more.
does make lint doesnt add gaps (ex:like gap between =,small gap after operators ). is there Any other way to do these?

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.

There still are some changes that are yet to be made based on the review.

@anandkaranubc
Copy link
Contributor

is there Any other way to do these?

Yes, you can call the bot for lint fixes, but relying on it isn't a good practice.

Signed-off-by: yaswanth <116426380+yaswanthkosuru@users.noreply.github.com>
var x;
var y;
var i;

alpha = 100.56789;
beta = 55.54321;
dist = new Pareto1( alpha, beta );
len=100;
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
len=100;
len = 100;

len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 100.0 );
Copy link
Contributor

Choose a reason for hiding this comment

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

Is EPS needed here?

len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 100.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[ i ] = uniform( EPS, 100.0 );
x[ i ] = uniform( 0.0, 100.0 );

Same comment as above. If EPS is necessary here, it's fine to keep it. Otherwise, the range should remain the same as original.

var x;
var y;
var i;

alpha = 100.56789;
beta = 55.54321;
len=100;
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
len=100;
len = 100;


b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*50.0 ) + EPS;
y = mylogcdf( x );
y = mylogcdf( x[ i % len] );
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
y = mylogcdf( x[ i % len] );
y = mylogcdf( x[ i % len ] );

Comment on lines 76 to 83
alpha = 100.56789;
beta = 55.54321;
len=100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 50.0 );
}
mypdf = pdf.factory( alpha, beta );
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
alpha = 100.56789;
beta = 55.54321;
len=100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 50.0 );
}
mypdf = pdf.factory( alpha, beta );
alpha = 100.56789;
beta = 55.54321;
mypdf = pdf.factory( alpha, beta );
len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 50.0 );
}

Comment on lines +50 to 51
}
b.tic();
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
}
b.tic();
}
b.tic();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Changes Pull request which needs changes before being merged. Needs Review A pull request which needs code review. 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/pareto-type1
3 participants