Skip to content

feat: add math/base/special/boxcoxf#10150

Open
navyansh007 wants to merge 4 commits intostdlib-js:developfrom
navyansh007:boxcoxf-c-implementation
Open

feat: add math/base/special/boxcoxf#10150
navyansh007 wants to merge 4 commits intostdlib-js:developfrom
navyansh007:boxcoxf-c-implementation

Conversation

@navyansh007
Copy link
Contributor

Resolves #10149

Description

What is the purpose of this pull request?

This pull request:

  • Adds @stdlib/math/base/special/boxcoxf, a single-precision floating-point one-parameter Box-Cox transformation
  • Includes C implementation, JavaScript implementation, native addon bindings, tests, benchmarks, and documentation

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

…files

---
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: 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: passed
  - task: lint_c_examples
    status: passed
  - task: lint_c_benchmarks
    status: passed
  - 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: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: missing_dependencies
  - 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
---
…pecial/boxcoxf

---
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: na
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - 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: 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: passed
  - task: lint_license_headers
    status: passed
---
@stdlib-bot stdlib-bot added Math Issue or pull request specific to math functionality. Needs Review A pull request which needs code review. labels Feb 7, 2026
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Feb 7, 2026

Coverage Report

Package Statements Branches Functions Lines
math/base/special/boxcoxf $\color{green}205/205$
$\color{green}+0.00%$
$\color{green}13/13$
$\color{green}+0.00%$
$\color{green}2/2$
$\color{green}+0.00%$
$\color{green}205/205$
$\color{green}+0.00%$

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

---
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: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: missing_dependencies
  - task: lint_r
    status: na
  - task: lint_c_src
    status: passed
  - task: lint_c_examples
    status: passed
  - task: lint_c_benchmarks
    status: passed
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
Comment on lines +24 to +28
var abs = require( '@stdlib/math/base/special/abs' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var lnf = require( '@stdlib/math/base/special/lnf' );
var expm1 = require( '@stdlib/math/base/special/expm1' );
Copy link
Member

Choose a reason for hiding this comment

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

@navyansh007 Any reasons to use double-precision functions here instead of single-precision ones?

Suggested change
var abs = require( '@stdlib/math/base/special/abs' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var lnf = require( '@stdlib/math/base/special/lnf' );
var expm1 = require( '@stdlib/math/base/special/expm1' );
var absf = require( '@stdlib/math/base/special/absf' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
var lnf = require( '@stdlib/math/base/special/lnf' );
var expm1f = require( '@stdlib/math/base/special/expm1f' );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @gunjjoshi. My mistake- I copied the imports directly from math/base/special/boxcox/lib/main.js without switching them to the single-precision equivalents. I'll update abs, isnan, and isPositiveZero to absf, isnanf, and isPositiveZerof.
However, expm1f doesn't currently exist in stdlib, so I'm keeping the double-precision expm1 and casting the result to float32- this matches the approach used in the C implementation as well.

Copy link
Member

Choose a reason for hiding this comment

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

We'll need to wait until expm1f is implemented. Once we have that, we can come back to this PR.

// MAIN //

/**
* Computes a one-parameter Box-Cox transformation for single-precision floating-point number.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Computes a one-parameter Box-Cox transformation for single-precision floating-point number.
* Computes a one-parameter Box-Cox transformation for a single-precision floating-point number.


/**
* Computes a one-parameter Box-Cox transformation for single-precision floating-point number.
*
Copy link
Member

Choose a reason for hiding this comment

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

@navyansh007 We are missing the "Method" description here, which is present in boxcox

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally left out the Method section because the one in boxcox is specifically a numerical analysis for double-precision (float64). It derives the threshold 1.0e-19 from the float64 epsilon and the range of ln for double-precision numbers. Copying it as-is didn't seem correct to me for boxcoxf, since float32 has a larger epsilon and a different log range, which is why the threshold here is 1.0e-10 instead. I'd be happy to add a Method section with the corresponding float32 analysis. Would you be able to point me in the right direction on how to best frame that, or should I follow the same derivation approach as boxcox but with single-precision constants?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we will definitely need to frame it for single-precision. You should be able to derive it using single-precision constants. You can do something like:

In [24]: var FLOAT32_EXPONENT_BIAS = require( '@stdlib/constants/float32/exponent-bias' );

In [25]: var FLOAT32_NUM_SIGNIFICAND_BITS = require( '@stdlib/constants/float32/num-significand-bits' );

In [26]: var powf = require('@stdlib/math/base/special/powf')
Out[26]: [Function: powf]

In [27]: var lnf = require( '@stdlib/math/base/special/lnf' );

In [28]: var ln_max = lnf( 2 - powf( 2, -FLOAT32_NUM_SIGNIFICAND_BITS ) ) + ( FLOAT32_EXPONENT_BIAS ) * lnf( 2 )
Out[28]: 88.7228392958641

In [29]: var ln_min = ( 1 - FLOAT32_EXPONENT_BIAS - FLOAT32_NUM_SIGNIFICAND_BITS ) * lnf( 2 )
Out[29]: -103.27893018722534

And something similar for double-precision.

{
"name": "@stdlib/math/base/special/boxcoxf",
"version": "0.0.0",
"description": "Compute a one-parameter Box-Cox transformation for single-precision floating-point number.",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"description": "Compute a one-parameter Box-Cox transformation for single-precision floating-point number.",
"description": "Compute a one-parameter Box-Cox transformation for a single-precision floating-point number.",


# boxcoxf

> Compute a one-parameter [Box-Cox transformation][box-cox-transformation] for single-precision floating-point number.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> Compute a one-parameter [Box-Cox transformation][box-cox-transformation] for single-precision floating-point number.
> Compute a one-parameter [Box-Cox transformation][box-cox-transformation] for a single-precision floating-point number.

Let's use 'a' here and everywhere else in this PR too.

Comment on lines +96 to +97
float r;
double t;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
float r;
double t;
double t;
float r;

@gunjjoshi gunjjoshi added Needs Changes Pull request which needs changes before being merged. status: Blocked Issue or pull request which is currently blocked. and removed Needs Review A pull request which needs code review. labels Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Math Issue or pull request specific to math functionality. Needs Changes Pull request which needs changes before being merged. status: Blocked Issue or pull request which is currently blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: Add implementation for @stdlib/math/base/special/boxcoxf

3 participants