-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: add stats/base/ndarray/sstdev
#9341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
|
|
||
| var bench = require( '@stdlib/bench' ); | ||
| var uniform = require( '@stdlib/random/array/uniform' ); | ||
| var isnan = require( '@stdlib/math/base/assert/is-nan' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| var isnan = require( '@stdlib/math/base/assert/is-nan' ); | |
| var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); |
Single-precision.
| > var xbuf = [ 1.0, -2.0, 2.0 ]; | ||
| > var dt = 'generic'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| > 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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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' } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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' } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 = sstdev( [ x, correction ] ); | ||
| if ( isnan( v ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if ( isnan( v ) ) { | |
| if ( isnanf( v ) ) { |
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnan( v ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if ( isnan( v ) ) { | |
| if ( isnanf( v ) ) { |
kgryte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left initial comments.
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:
stats/base/ndarray/sstdevRelated 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?
If you answered "yes" above, how did you use AI assistance?
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
stdevpackage 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