Skip to content

bench: refactor random number generation in stats/base/dists/signrank #5088

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 2 commits into from

Conversation

shraddha761
Copy link

@shraddha761 shraddha761 commented Feb 7, 2025

Resolves #4986

Description

What is the purpose of this pull request?

This pull request:

  • {{TODO: add description describing what this pull request does}}

Related Issues

Does this pull request have any related issues?

This pull request:

  • resolves #{{TODO: add issue number}}

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: 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. 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 7, 2025
@stdlib-bot
Copy link
Contributor

Hello! Thank you for your contribution to stdlib.

We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:

  1. Please read our contributing guidelines.

  2. Update your pull request description to include this checked box:

    - [x] Read, understood, and followed the [contributing guidelines](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md)

This acknowledgment confirms that you've read the guidelines, which include:

  • The developer's certificate of origin
  • Your agreement to license your contributions under the project's terms

We can't review or accept contributions without this acknowledgment.

Thank you for your understanding and cooperation. We look forward to reviewing your contribution!

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 7, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/signrank/cdf $\color{red}309/311$
$\color{green}+99.36\%$
$\color{red}36/37$
$\color{green}+97.30\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{red}309/311$
$\color{green}+99.36\%$
stats/base/dists/signrank/pdf $\color{red}292/294$
$\color{green}+99.32\%$
$\color{red}34/35$
$\color{green}+97.14\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{red}292/294$
$\color{green}+99.32\%$
stats/base/dists/signrank/quantile $\color{green}305/305$
$\color{green}+100.00\%$
$\color{green}45/45$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}305/305$
$\color{green}+100.00\%$

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

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 for your PR, @shraddha761! To complete the linked issue, please also make the following changes:

Move random number generation out of the benchmarking loops and initialize it before the benchmarks.

See the linked PR for how this would look like.

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

@Planeshifter did some changes as required

Comment on lines +34 to +35
var nValues;
var values;
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
var nValues;
var values;
var len;
var n;

Please add only len and keep the original variable names unchanged (for consistency).

Comment on lines 37 to +38
var i;
var y;
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
var i;
var y;
var y;
var i;

Comment on lines +24 to +25
var uniform = require( '@stdlib/random/base/uniform' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
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
var uniform = require( '@stdlib/random/base/uniform' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/base/uniform' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );

Copy link
Contributor

Choose a reason for hiding this comment

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

Float64Array should be used instead of Array

Comment on lines +40 to +45
values = new Array( b.iterations );
nValues = new Array( b.iterations );
for ( i = 0; i < b.iterations; i++ ) {
values[ i ] = uniform( 0.0, 20.0 );
nValues[ i ] = discreteUniform( 1, 20 );
}
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
values = new Array( b.iterations );
nValues = new Array( b.iterations );
for ( i = 0; i < b.iterations; i++ ) {
values[ i ] = uniform( 0.0, 20.0 );
nValues[ i ] = discreteUniform( 1, 20 );
}
len = 100;
x = new Float64Array( len );
n = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( 0.0, 20.0 );
n[ i ] = discreteUniform( 1, 20 );
}

Comment on lines +49 to +50
x = values[ i ];
y = cdf( x, nValues[ i ] );
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 = values[ i ];
y = cdf( x, nValues[ i ] );
y = cdf( x[ i % len ], n[ i % len ] );

@@ -54,6 +61,7 @@ bench( pkg, function benchmark( b ) {
});

bench( pkg+':factory', function benchmark( b ) {
var values;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here and also applies throughout the PR.

Comment on lines +74 to +77
values = new Array( b.iterations );
for ( i = 0; i < b.iterations; i++ ) {
values[ i ] = uniform( 0.0, 20.0 );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be updated too by following the example above.

var pkg = require( './../package.json' ).name;
var quantile = require( './../lib' );
var EPS = 1e-10;
Copy link
Contributor

Choose a reason for hiding this comment

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

EPS is not needed in this benchmark file, as the original code uses:

p = randu();

Thus, using p = uniform( 0.0, 1.0 ); is perfectly fine in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is ever used, it should be imported as:

var EPS = require( '@stdlib/constants/float64/eps' );

@anandkaranubc
Copy link
Contributor

Thanks, @shraddha761, for working on this issue. I've left some feedback and an example for you to review. I hope that helps. You may also find the reference issues provided in #4986 useful too.

Can you also change the title to:

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

Note: There are backticks around stats/base/dists/signrank

@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
@kgryte kgryte changed the title bench: refactor random number stats/base/dists/signrank bench: refactor random number generation in stats/base/dists/signrank Mar 17, 2025
@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label Mar 17, 2025
@kgryte kgryte added the autoclose: Stale Pull request which should be auto-closed as considered stale. label Apr 30, 2025
@stdlib-bot
Copy link
Contributor

This pull request has been automatically closed because it has been inactive for an extended period after changes were requested. If you still wish to pursue this contribution, feel free to reopen the pull request or submit a new one.

We appreciate your interest in contributing to stdlib!

@stdlib-bot stdlib-bot closed this Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autoclose: Stale Pull request which should be auto-closed as considered stale. First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Good First PR A pull request resolving a Good First Issue. 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.

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