Skip to content

Conversation

@iampratik13
Copy link
Contributor

Resolves none

Description

What is the purpose of this pull request?

This pull request:

feat: add stats/base/ndarray/stdev

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

{{TODO: add disclosure if applicable}}


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

stdlib-bot commented Dec 19, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/ndarray/stdev $\color{green}127/127$
$\color{green}+0.00%$
$\color{green}3/3$
$\color{green}+0.00%$
$\color{green}1/1$
$\color{green}+0.00%$
$\color{green}127/127$
$\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 20, 2025
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Parameters
----------
arrays: ArrayLikeObject<ndarray>
Array-like object containing two elements: a one-dimensional input
Copy link
Member

Choose a reason for hiding this comment

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

This should be updated to match the README.

Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
/**
* Computes the standard deviation of a one-dimensional ndarray.
*
* @param arrays - array-like object containing an input ndarray and a correction 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
* @param arrays - array-like object containing an input ndarray and a correction ndarray
* @param arrays - array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray specifying a degrees of freedom adjustment


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

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

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

Comment on lines +33 to +37

var correction = scalar2ndarray( 1.0, opts );

console.log( ndarray2array( x ) );

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 correction = scalar2ndarray( 1.0, opts );
console.log( ndarray2array( x ) );
console.log( ndarray2array( x ) );
var correction = scalar2ndarray( 1.0, opts );

Copy link
Member

Choose a reason for hiding this comment

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

Match README.

* var stdev = require( '@stdlib/stats/base/ndarray/stdev' );
*
* var opts = {
* 'dtype': 'float64'
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
* 'dtype': 'float64'
* 'dtype': 'generic'

/**
* Computes the standard deviation of a one-dimensional ndarray.
*
* @param {ArrayLikeObject<Object>} arrays - array-like object containing ndarrays
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
* @param {ArrayLikeObject<Object>} arrays - array-like object containing ndarrays
* @param {ArrayLikeObject<Object>} arrays - array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray specifying a degrees of freedom adjustment

Comment on lines +59 to +67
var x;
var N;

x = arrays[ 0 ];
correction = ndarraylike2scalar( arrays[ 1 ] );

N = numelDimension( x, 0 );
stride = getStride( x, 0 );
return strided( N, correction, getData( x ), stride, getOffset( x ) );
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 x;
var N;
x = arrays[ 0 ];
correction = ndarraylike2scalar( arrays[ 1 ] );
N = numelDimension( x, 0 );
stride = getStride( x, 0 );
return strided( N, correction, getData( x ), stride, getOffset( x ) );
var x;
x = arrays[ 0 ];
correction = ndarraylike2scalar( arrays[ 1 ] );
return strided( numelDimension( x, 0 ), correction, getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len

Consistency with elsewhere.

{
"name": "@stdlib/stats/base/ndarray/stdev",
"version": "0.0.0",
"description": "Compute the standard deviation of one-dimensional ndarrays.",
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 the standard deviation of one-dimensional ndarrays.",
"description": "Compute the standard deviation of a one-dimensional ndarray.",

"stats",
"mathematics",
"math",
"standard deviation",
Copy link
Member

Choose a reason for hiding this comment

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

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 20, 2025
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Pratik  <bhagwatpratik781@gmail.com>
@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Changes Pull request which needs changes before being merged. labels Dec 20, 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