8000 feat: add `stats/base/ndarray/sstdev` by MeKaustubh07 · Pull Request #9341 · stdlib-js/stdlib · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@MeKaustubh07
Copy link
Contributor

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: 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
Resolves None.


Description

What is the purpose of this pull request?

This pull request:

  • feat : add stats/base/ndarray/sstdev

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • none

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

This PR was created by duplicating the stdev package and adapting it to compute the maximum absolute value instead of the maximum value. GitHub Copilot assisted with updating test cases, documentation, and verifying consistency across all files.


@stdlib-js/reviewers


< 8000 input type="hidden" name="dropdown_direction" value="w" data-targets="batch-deferred-content.inputs" autocomplete="off" />
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Dec 24, 2025
@stdlib-bot
Copy link
Contributor
stdlib-bot commented Dec 24, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/ndarray/sstdev $\color{green}124/124$
$\color{green}+0.00%$
$\color{green}3/3$
$\color{green}+0.00%$
$\color{green}1/1$
$\color{green}+0.00%$
$\color{green}124/124$
$\color{green}+0.00%$

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

@kgryte kgryte added Feature Issue or pull request for adding a new feature. and removed Needs Review A pull request which needs code review. labels Dec 24, 2025

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
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
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );

Single-precision.

Comment on lines 37 to 38
> var xbuf = [ 1.0, -2.0, 2.0 ];
> var dt = 'generic';
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
> var xbuf = [ 1.0, -2.0, 2.0 ];
> var dt = 'generic';
> var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] );
> var dt = 'float32';

Single-precision must be provided to single-precision.


/// <reference types="@stdlib/types"/>

import { typedndarray } from '@stdlib/types/ndarray';
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
import { typedndarray } from '@stdlib/types/ndarray';
import { float32ndarray, typedndarray } from '@stdlib/types/ndarray';

* var v = sstdev( [ x, correction ] );
* // returns ~2.0817
*/
declare function sstdev<T extends typedndarray = typedndarray>( arrays: [ T, T ] ): 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
declare function sstdev<T extends typedndarray = typedndarray>( arrays: [ T, T ] ): number;
declare function sstdev<T extends typedndarray<number> = typedndarray<number>>( arrays: [ float32ndarray, T ] ): number;

const x = zeros( [ 10 ], {
'dtype': 'float32'
});
const correction = scalar2ndarray( 1.0, { 'dtype': 'float32' } );
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
const correction = scalar2ndarray( 1.0, { 'dtype': 'float32' } );
const correction = scalar2ndarray( 1.0, {
'dtype': 'float32'
});

Be consistent. See L30-32.

const x = zeros( [ 10 ], {
'dtype': 'float32'
});
const correction = scalar2ndarray( 1.0, { 'dtype': 'float32' } );
Copy link
Member

Choos 7440 e a reason for hiding this comment

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

Suggested change
const correction = scalar2ndarray( 1.0, { 'dtype': 'float32' } );
const correction = scalar2ndarray( 1.0, {
'dtype': 'float32'
});

* var sstdev = require( '@stdlib/stats/base/ndarray/sstdev' );
*
* var opts = {
* 'dtype': 'generic'
Copy link
Member

Choose a reason for hiding this comment

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

Incorrect. You need to pass down a Float32Array.

Copy link
Member

Choose a reason for hiding this comment

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

See main.js example. Beware of copy-paste mistakes.


var tape = require( 'tape' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
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
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );

Single-precision utils for single-precision data.

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v < 6D47 span class=pl-c1>= sstdev( [ x, correction ] );
if ( isnan( v ) ) {
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
if ( isnan( v ) ) {
if ( isnanf( v ) ) {

}
}
b.toc();
if ( isnan( v ) ) {
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
if ( isnan( v ) ) {
if ( isnanf( v ) ) {

Copy link
Member
@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

Left initial comments.

@kgryte kgryte added the Needs Changes Pull request which needs changes before being merged. label Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue or pull request for adding a new feature. 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.

3 participants

31D8
0