Skip to content

feat: add C implementation for stats/base/dists/erlang/pdf#10554

Open
rautelaKamal wants to merge 1 commit intostdlib-js:developfrom
rautelaKamal:feat/stats/base/dists/erlang/pdf-c-port
Open

feat: add C implementation for stats/base/dists/erlang/pdf#10554
rautelaKamal wants to merge 1 commit intostdlib-js:developfrom
rautelaKamal:feat/stats/base/dists/erlang/pdf-c-port

Conversation

@rautelaKamal
Copy link
Copy Markdown
Contributor

@rautelaKamal rautelaKamal commented Feb 27, 2026

Ref #3575.

Description

What is the purpose of this pull request?

This pull request:

  • Adds a C implementation for @stdlib/stats/base/dists/erlang/pdf, fulfilling the open RFC [RFC]: Add C implementation for @stdlib/stats/base/dists/erlang/pdf #3575.
  • Validates that the shape parameter k is a non-negative integer using stdlib_base_is_nonnegative_integer(k).
  • Reuses the existing Gamma distribution implementation by safely proxying the evaluation directly to the stdlib_base_dists_gamma_pdf C function, since the Erlang distribution is mathematically a special case of the Gamma distribution.
  • Integrates standard N-API bindings, Makefile, include.gypi, binding.gyp, and the native.js benchmarks & tests.

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.".

I utilized an AI coding assistant to help scaffold the C implementations, N-API bindings, makefiles, and native benchmarks. The logic was reviewed and verified manually to ensure mathematical correctness and alignment with standard project practices.


@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 27, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented Feb 27, 2026

Coverage Report

Package Statements Branches Functions Lines
blas/ext/base $\color{red}59225/70981$
$\color{green}+83.44%$
$\color{red}1066/1209$
$\color{green}+88.17%$
$\color{red}20/601$
$\color{green}+3.33%$
$\color{red}59225/70981$
$\color{green}+83.44%$
blas/ext/base/ndarray $\color{red}8859/9468$
$\color{green}+93.57%$
$\color{red}153/155$
$\color{green}+98.71%$
$\color{red}0/77$
$\color{green}+0.00%$
$\color{red}8859/9468$
$\color{green}+93.57%$
stats/base/dists/erlang/pdf $\color{green}289/289$
$\color{green}+0.00%$
$\color{green}11/11$
$\color{green}+0.00%$
$\color{green}3/3$
$\color{green}+0.00%$
$\color{green}289/289$
$\color{green}+0.00%$

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

@rautelaKamal rautelaKamal force-pushed the feat/stats/base/dists/erlang/pdf-c-port branch 5 times, most recently from a9a7359 to 37e1576 Compare February 27, 2026 23:54
@Om-A-osc
Copy link
Copy Markdown
Contributor

@rautelaKamal
CI checks failing for package.json.
Order of keys is important for package.json linting. Maybe have a look at lib/node_modules/@stdlib/stats/base/dists/erlang/mean/package.json and try rearranging.

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 file needs to mirror test/test.pdf.js. Currently missing:

  • fixture-based tests against ./fixtures/julia/large_rate.json, large_shape.json, both_large.json
  • tests for +infinity / -infinity for x
  • tests for the degenerate distribution when k == 0
  • missing imports (abs, PINF, NINF, EPS)
  • missing // FIXTURES // section

See test/test.pdf.js in this same package and @stdlib/stats/base/dists/erlang/mgf/test/test.native.js for the expected structure.

Comment on lines +36 to +39
"dependencies": {
"@stdlib/math/base/assert/is-nonnegative-integer": "^0.2.2",
"@stdlib/stats/base/dists/gamma/pdf": "^0.2.2"
},
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.

Don't manually populate dependencies. These are auto-generated. Should be:

Suggested change
"dependencies": {
"@stdlib/math/base/assert/is-nonnegative-integer": "^0.2.2",
"@stdlib/stats/base/dists/gamma/pdf": "^0.2.2"
},
"dependencies": {},

@Planeshifter Planeshifter added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Mar 4, 2026
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Mar 5, 2026
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 benchmark/c/ directory (benchmark.c and Makefile) and examples/c/ directory (example.c and Makefile). These are required when adding a C implementation. See, e.g., @stdlib/stats/base/dists/erlang/mgf for reference.

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 README.md needs a C APIs section documenting the C interface (usage, examples, function signature). See @stdlib/stats/base/dists/erlang/mgf/README.md for the expected structure.

Copy link
Copy Markdown
Contributor Author

@rautelaKamal rautelaKamal Mar 10, 2026

Choose a reason for hiding this comment

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

Thank you for the detailed feedback. I've addressed all the review comments: mirrored the fixture/infinity/degenerate k=0 tests into test.native.js, added benchmark/c/ and examples/c/ directories with Makefiles, and added the C APIs section to the README

@Planeshifter Planeshifter removed the Needs Review A pull request which needs code review. label Mar 10, 2026
@Planeshifter Planeshifter changed the title feat: add C implementation for stats/base/dists/erlang/pdf feat: add C implementation for stats/base/dists/erlang/pdf Mar 10, 2026
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Mar 10, 2026
@rautelaKamal rautelaKamal force-pushed the feat/stats/base/dists/erlang/pdf-c-port branch from 318b207 to 69a1a9a Compare April 4, 2026 18:25
@rautelaKamal rautelaKamal force-pushed the feat/stats/base/dists/erlang/pdf-c-port branch from 0a4edf9 to c7e4246 Compare April 5, 2026 18:45
@github-actions github-actions bot mentioned this pull request Apr 6, 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. 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.

4 participants