Skip to content

feat: add C implementation for stats/base/dists/studentized-range/cdf#10106

Open
nirmaljb wants to merge 6 commits intostdlib-js:developfrom
nirmaljb:feat/studentized-range-cdf
Open

feat: add C implementation for stats/base/dists/studentized-range/cdf#10106
nirmaljb wants to merge 6 commits intostdlib-js:developfrom
nirmaljb:feat/studentized-range-cdf

Conversation

@nirmaljb
Copy link
Copy Markdown
Contributor

@nirmaljb nirmaljb commented Feb 5, 2026

Resolves #3887.

Description

What is the purpose of this pull request?

This pull request:

  • Adds a C implementation of the studentized-range cumulative distribution function (CDF).
  • Includes benchmarks for the C implementation.
  • Provides examples demonstrating the usage of the studentized-range CDF in C.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

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.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. Good First PR A pull request resolving a Good First Issue. labels Feb 5, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented Feb 5, 2026

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/studentized-range/cdf $\color{red}709/769$
$\color{green}+0.00%$
$\color{red}70/87$
$\color{green}+0.00%$
$\color{green}10/10$
$\color{green}+0.00%$
$\color{red}709/769$
$\color{green}+0.00%$

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

@nirmaljb nirmaljb marked this pull request as draft February 5, 2026 17:21
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Feb 5, 2026
@nirmaljb nirmaljb marked this pull request as ready for review February 5, 2026 17:43
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Feb 5, 2026
@nirmaljb nirmaljb changed the title feat: Add C implementation for stats/base/dists/studentized-range/cdf feat: Add feat: Add C implementation for stats/base/dists/studentized_range/cdf Feb 5, 2026
@nakul-krishnakumar nakul-krishnakumar changed the title feat: Add feat: Add C implementation for stats/base/dists/studentized_range/cdf feat: add C implementation for stats/base/dists/studentized-range/cdf Feb 5, 2026
@stdlib-bot stdlib-bot added the Merge Conflicts Pull request which has merge conflicts. label Feb 10, 2026
@nirmaljb nirmaljb marked this pull request as draft February 10, 2026 17:35
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Feb 10, 2026
---
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: passed
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: missing_dependencies
  - task: lint_c_examples
    status: missing_dependencies
  - task: lint_c_benchmarks
    status: missing_dependencies
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
---
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: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - 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: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
---
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: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: missing_dependencies
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: missing_dependencies
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
---
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: na
  - 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: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
… snippet

---
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: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: missing_dependencies
  - 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: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
… snippet

---
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: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: missing_dependencies
  - 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: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@nirmaljb nirmaljb force-pushed the feat/studentized-range-cdf branch from 1e3bd36 to 240b121 Compare February 16, 2026 15:28
@nirmaljb nirmaljb marked this pull request as ready for review February 16, 2026 15:29
@stdlib-bot stdlib-bot added Needs Review A pull request which needs code review. and removed Merge Conflicts Pull request which has merge conflicts. labels Feb 16, 2026
Copy link
Copy Markdown
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 contribution! Left round of feedback.

Comment on lines +53 to +55
function cdf( q, r, v, nranges ) {
return addon( q, r, v, nranges );
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The native wrapper doesn't default nranges to 1 when undefined. Calling cdf(q, r, v) with three arguments forwards undefined to the addon (coerced to NaN), causing stdlib_base_is_positive_integer(NaN) to return false and the CDF to return NaN. This breaks parity with lib/main.js and contradicts the 3-arg JSDoc examples which claim ~0.0644.

Suggested change
function cdf( q, r, v, nranges ) {
return addon( q, r, v, nranges );
}
function cdf( q, r, v, nranges ) {
if ( nranges === void 0 ) {
nranges = 1;
}
return addon( q, r, v, nranges );
}

* // returns ~0.913
*
* @example
* var y = cdf( 0.5, 3.0, 2.0, 2, 1.0 );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This example passes 5 arguments, but cdf only accepts 4 (q, r, v, nranges). Drop the trailing 1.0.

Suggested change
* var y = cdf( 0.5, 3.0, 2.0, 2, 1.0 );
* var y = cdf( 0.5, 3.0, 2.0, 2 );

p = 0.0;
}
} else {
// Case: |z| >= 37
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the else-branch of if ( zabs > 37.0 ), so it's the |z| <= 37 case.

Suggested change
// Case: |z| >= 37
// Case: |z| <= 37

Comment on lines +78 to +93
static double CUTOFF = 7.071; // 10 / sqrt(2)
static double p0 = 220.2068679123761e0;
static double p1 = 221.2135961699311e0;
static double p2 = 112.0792914978709e0;
static double p3 = 33.91286607838300e0;
static double p4 = 6.373962203531650e0;
static double p5 = 0.7003830644436881e0;
static double p6 = 0.3526249659989109e-01;
static double q0 = 440.4137358247522e0;
static double q1 = 793.8265125199484e0;
static double q2 = 637.3336333788311e0;
static double q3 = 296.5642487796737e0;
static double q4 = 86.78073220294608e0;
static double q5 = 16.06417757920695e0;
static double q6 = 1.755667163182642e0;
static double q7 = 0.8838834764831844e-1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These file-scope scalars are immutable — mark them static const double to match stdlib's C conventions.

*
* @private
* @param z - standard deviation from the mean
* @returns evaluated CDF
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use @return (no trailing s) in C JSDoc to match stdlib convention. Update all occurrences in this file (apnorm, fint, gaussLegreQuadrature, prangeVInf, f26, gausslegdquad, and the main function).

double cmm = ( b - a ) / 2.0;
double d = ( b + a ) / 2.0;
int32_t j;
for( j = 0; j < n; j++ ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Missing space after for. Every other loop in this file has one.

Suggested change
for( j = 0; j < n; j++ ) {
for ( j = 0; j < n; j++ ) {

Comment on lines +305 to +306
* double y = cdf( 0.5, 3.0, 2.0, 2 );
* // returns ~0.01
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use the fully qualified C symbol in the @example block.

Suggested change
* double y = cdf( 0.5, 3.0, 2.0, 2 );
* // returns ~0.01
* double y = stdlib_base_dists_studentized_range_cdf( 0.5, 3.0, 2.0, 1.0 );
* // returns ~0.0644

@Planeshifter Planeshifter added the Ready To Merge A pull request which is ready to be merged. label Apr 20, 2026
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Apr 20, 2026
@Planeshifter Planeshifter added Needs Changes Pull request which needs changes before being merged. and removed Ready To Merge A pull request which is ready to be merged. labels Apr 20, 2026
@stdlib-js stdlib-js deleted a comment from stdlib-bot Apr 20, 2026
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. 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]: Add C implementation for @stdlib/stats/base/dists/studentized-range/cdf

3 participants