From 9cd2b1aaf43e76b1a58263d07675419531c1463e Mon Sep 17 00:00:00 2001 From: prajjwalbajpai Date: Thu, 13 Mar 2025 16:42:00 +0530 Subject: [PATCH 01/14] feat: add support for accessor arrays and refactor stats/base/nanvariancewd --- 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 --- --- .../stats/base/nanvariancewd/README.md | 44 ++-- .../base/nanvariancewd/benchmark/benchmark.js | 23 +- .../benchmark/benchmark.ndarray.js | 21 +- .../stats/base/nanvariancewd/docs/repl.txt | 32 ++- .../base/nanvariancewd/docs/types/index.d.ts | 19 +- .../base/nanvariancewd/docs/types/test.ts | 3 + .../base/nanvariancewd/examples/index.js | 18 +- .../lib/{nanvariancewd.js => accessors.js} | 45 ++-- .../stats/base/nanvariancewd/lib/index.js | 11 +- .../stats/base/nanvariancewd/lib/main.js | 23 +- .../stats/base/nanvariancewd/lib/ndarray.js | 30 ++- .../{test.nanvariancewd.js => test.main.js} | 201 +++++++++++++++- .../base/nanvariancewd/test/test.ndarray.js | 221 +++++++++++++++++- 13 files changed, 543 insertions(+), 148 deletions(-) rename lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/{nanvariancewd.js => accessors.js} (66%) rename lib/node_modules/@stdlib/stats/base/nanvariancewd/test/{test.nanvariancewd.js => test.main.js} (59%) diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md b/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md index 35df01d49a2b..1ae7c8e30d24 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md @@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var nanvariancewd = require( '@stdlib/stats/base/nanvariancewd' ); ``` -#### nanvariancewd( N, correction, x, stride ) +#### nanvariancewd( N, correction, x, strideX ) Computes the [variance][variance] of a strided array `x` ignoring `NaN` values and using Welford's algorithm. @@ -114,17 +114,14 @@ The function has the following parameters: - **N**: number of indexed elements. - **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **stride**: index increment for `x`. +- **strideX**: stride length for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, ```javascript -var floor = require( '@stdlib/math/base/special/floor' ); - var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN ]; -var N = floor( x.length / 2 ); -var v = nanvariancewd( N, 1, x, 2 ); +var v = nanvariancewd( 4, 1, x, 2 ); // returns 6.25 ``` @@ -134,18 +131,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = nanvariancewd( N, 1, x1, 2 ); +var v = nanvariancewd( 4, 1, x1, 2 ); // returns 6.25 ``` -#### nanvariancewd.ndarray( N, correction, x, stride, offset ) +#### nanvariancewd.ndarray( N, correction, x, strideX, offsetX ) Computes the [variance][variance] of a strided array ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. @@ -158,17 +152,14 @@ var v = nanvariancewd.ndarray( x.length, 1, x, 1, 0 ); The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in the strided array starting from the second element ```javascript -var floor = require( '@stdlib/math/base/special/floor' ); - var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -var N = floor( x.length / 2 ); -var v = nanvariancewd.ndarray( N, 1, x, 2, 1 ); +var v = nanvariancewd.ndarray( 4, 1, x, 2, 1 ); // returns 6.25 ``` @@ -181,6 +172,7 @@ var v = nanvariancewd.ndarray( N, 1, x, 2, 1 ); ## Notes - If `N <= 0`, both functions return `NaN`. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). - If `n - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements), both functions return `NaN`. - Depending on the environment, the typed versions ([`dnanvariancewd`][@stdlib/stats/base/dnanvariancewd], [`snanvariancewd`][@stdlib/stats/base/snanvariancewd], etc.) are likely to be significantly more performant. @@ -195,18 +187,12 @@ var v = nanvariancewd.ndarray( N, 1, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var nanvariancewd = require( '@stdlib/stats/base/nanvariancewd' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); console.log( x ); var v = nanvariancewd( x.length, 1, x, 1 ); @@ -258,6 +244,8 @@ console.log( v ); [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor + [@welford:1962a]: https://doi.org/10.1080/00401706.1962.10490022 [@vanreeken:1968a]: https://doi.org/10.1145/362929.362961 diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.js index 814189c6687f..43a094abe75f 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.js @@ -21,11 +21,18 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; -var nanvariancewd = require( './../lib/nanvariancewd.js' ); +var nanvariancewd = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; // FUNCTIONS // @@ -38,17 +45,7 @@ var nanvariancewd = require( './../lib/nanvariancewd.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - if ( randu() < 0.2 ) { - x.push( NaN ); - } else { - x.push( ( randu()*20.0 ) - 10.0 ); - } - } + var x = uniform( len, -10, 10, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.ndarray.js index 339ed2b68ef0..65b3f668c5f7 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.ndarray.js @@ -21,13 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; var nanvariancewd = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,17 +45,7 @@ var nanvariancewd = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - if ( randu() < 0.2 ) { - x.push( NaN ); - } else { - x.push( ( randu()*20.0 ) - 10.0 ); - } - } + var x = uniform( len, -10, 10, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt index a3b5d9dcb638..538bbf4cb923 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, correction, x, stride ) +{{alias}}( N, correction, x, strideX ) Computes the variance of a strided array ignoring `NaN` values and using Welford's algorithm. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and `stride` parameters determine which elements + in the strided array are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -34,8 +34,8 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -49,22 +49,19 @@ > {{alias}}( x.length, 1, x, 1 ) ~4.3333 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, 1, x, stride ) + > {{alias}}( 3, 1, x, 2 ) ~4.3333 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, 1, x1, stride ) + > {{alias}}( 3, 1, x1, 2 ) ~4.3333 -{{alias}}.ndarray( N, correction, x, stride, offset ) + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) Computes the variance of a strided array ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. @@ -93,10 +90,10 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -113,8 +110,7 @@ // Using offset parameter: > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, 1, x, 2, 1 ) + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) ~4.3333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/types/index.d.ts index e1f49c0edb18..694ca8f637c6 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/types/index.d.ts @@ -20,7 +20,12 @@ /// -import { NumericArray } from '@stdlib/types/array'; +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; /** * Interface describing `nanvariancewd`. @@ -32,7 +37,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns variance * * @example @@ -41,7 +46,7 @@ interface Routine { * var v = nanvariancewd( x.length, 1, x, 1 ); * // returns ~4.3333 */ - ( N: number, correction: number, x: NumericArray, stride: number ): number; + ( N: number, correction: number, x: InputArray, strideX: number ): number; /** * Computes the variance of a strided array ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. @@ -49,8 +54,8 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns variance * * @example @@ -59,7 +64,7 @@ interface Routine { * var v = nanvariancewd.ndarray( x.length, 1, x, 1, 0 ); * // returns ~4.3333 */ - ndarray( N: number, correction: number, x: NumericArray, stride: number, offset: number ): number; + ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; } /** @@ -68,7 +73,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns variance * * @example diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/types/test.ts index 4f1e6251e3cc..1152305688f8 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/types/test.ts @@ -16,6 +16,7 @@ * limitations under the License. */ +import AccessorArray = require( '@stdlib/array/base/accessor' ); import nanvariancewd = require( './index' ); @@ -26,6 +27,7 @@ import nanvariancewd = require( './index' ); const x = new Float64Array( 10 ); nanvariancewd( x.length, 1, x, 1 ); // $ExpectType number + nanvariancewd( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number } // The compiler throws an error if the function is provided a first argument which is not a number... @@ -101,6 +103,7 @@ import nanvariancewd = require( './index' ); const x = new Float64Array( 10 ); nanvariancewd.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number + nanvariancewd.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number } // The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/examples/index.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/examples/index.js index fa0f9a94187e..f08423a1755a 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/examples/index.js @@ -18,22 +18,12 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var nanvariancewd = require( './../lib' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( (randu()*100.0) - 50.0 ); - } -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); console.log( x ); var v = nanvariancewd( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/nanvariancewd.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/accessors.js similarity index 66% rename from lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/nanvariancewd.js rename to lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/accessors.js index 5efb419f6cc5..8d4fb794433b 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/nanvariancewd.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/accessors.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,20 +28,29 @@ * - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022). * - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961). * +* @private * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} stride - stride length +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * * @example -* var x = [ 1.0, -2.0, NaN, 2.0 ]; +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * -* var v = nanvariancewd( x.length, 1, x, 1 ); +* var x = toAccessorArray( [ 1.0, -2.0, NaN, 2.0 ] ); +* +* var v = nanvariancewd( x.length, 1, arraylike2object( x ), 1, 0 ); * // returns ~4.3333 */ -function nanvariancewd( N, correction, x, stride ) { +function nanvariancewd( N, correction, x, strideX, offsetX ) { var delta; + var xbuf; + var get; var mu; var M2; var ix; @@ -50,33 +59,33 @@ function nanvariancewd( N, correction, x, stride ) { var n; var i; - if ( N <= 0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - v = x[ 0 ]; + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[ 0 ]; + + if ( N === 1 || strideX === 0 ) { + v = get( xbuf, offsetX ); if ( v === v && N-correction > 0.0 ) { return 0.0; } return NaN; } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } + + ix = offsetX; M2 = 0.0; mu = 0.0; n = 0; for ( i = 0; i < N; i++ ) { - v = x[ ix ]; + v = get( xbuf, ix ); if ( v === v ) { delta = v - mu; n += 1; mu += delta / n; M2 += delta * ( v - mu ); } - ix += stride; + ix += strideX; } nc = n - correction; if ( nc <= 0.0 ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/index.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/index.js index b51d8cf6749b..6985b6c7bab3 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/index.js @@ -32,19 +32,24 @@ * // returns ~4.3333 * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var nanvariancewd = require( '@stdlib/stats/base/nanvariancewd' ); * * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ]; -* var N = floor( x.length / 2 ); * -* var v = nanvariancewd.ndarray( N, 1, x, 2, 1 ); +* var v = nanvariancewd.ndarray( 5, 1, x, 2, 1 ); * // returns 6.25 */ // MODULES // +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/main.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/main.js index f5a006d685fe..e52e00d53ae0 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/main.js @@ -20,14 +20,31 @@ // MODULES // -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var nanvariancewd = require( './nanvariancewd.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); var ndarray = require( './ndarray.js' ); // MAIN // -setReadOnly( nanvariancewd, 'ndarray', ndarray ); +/** +* Computes the variance of a strided array ignoring `NaN` values and using Welford's algorithm. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {number} variance +* +* @example +* var x = [ 1.0, -2.0, NaN, 2.0 ]; +* var N = x.length; +* +* var v = nanvariancewd( N, 1, x, 1 ); +* // returns ~4.3333 +*/ +function nanvariancewd( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +} // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/ndarray.js index abe3ebc8ce28..4ba4ef5fa8d5 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/ndarray.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + // MAIN // /** @@ -31,25 +37,23 @@ * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {NumericArray} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); -* * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ]; -* var N = floor( x.length / 2 ); * -* var v = nanvariancewd( N, 1, x, 2, 1 ); +* var v = nanvariancewd( 5, 1, x, 2, 1 ); * // returns 6.25 */ -function nanvariancewd( N, correction, x, stride, offset ) { +function nanvariancewd( N, correction, x, strideX, offsetX ) { var delta; var mu; var M2; var ix; var nc; + var o; var v; var n; var i; @@ -57,14 +61,18 @@ function nanvariancewd( N, correction, x, stride, offset ) { if ( N <= 0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { - v = x[ offset ]; + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, correction, o, strideX, offsetX ); + } + if ( N === 1 || strideX === 0 ) { + v = x[ offsetX ]; if ( v === v && N-correction > 0.0 ) { return 0.0; } return NaN; } - ix = offset; + ix = offsetX; M2 = 0.0; mu = 0.0; n = 0; @@ -76,7 +84,7 @@ function nanvariancewd( N, correction, x, stride, offset ) { mu += delta / n; M2 += delta * ( v - mu ); } - ix += stride; + ix += strideX; } nc = n - correction; if ( nc <= 0.0 ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.nanvariancewd.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js similarity index 59% rename from lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.nanvariancewd.js rename to lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js index 8344438f7d40..e73130007bbf 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.nanvariancewd.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js @@ -1,3 +1,4 @@ + /** * @license Apache-2.0 * @@ -21,10 +22,10 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var Float64Array = require( '@stdlib/array/float64' ); -var nanvariancewd = require( './../lib/nanvariancewd.js' ); +var nanvariancewd = require( './../lib/main.js' ); // TESTS // @@ -94,6 +95,60 @@ tape( 'the function calculates the population variance of a strided array (ignor t.end(); }); +tape( 'the function calculates the population variance of a strided array (ignoring `NaN` values) (accessors)', function test( t ) { + var x; + var v; + var i; + + x = [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ]; + + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ]; + + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-6), 'returns expected value' ); + + x = [ -4.0, NaN ]; + + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, NaN ]; + + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ 4.0 ]; + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = []; + for ( i = 0; i < 1e3; i++ ) { + x.push( 100.0 ); + } + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ]; + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = []; + for ( i = 0; i < 1e3; i++ ) { + x.push( NaN ); + } + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function calculates the sample variance of a strided array (ignoring `NaN` values)', function test( t ) { var x; var v; @@ -148,6 +203,60 @@ tape( 'the function calculates the sample variance of a strided array (ignoring t.end(); }); +tape( 'the function calculates the sample variance of a strided array (ignoring `NaN` values) (accessors)', function test( t ) { + var x; + var v; + var i; + + x = [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-2), 'returns expected value' ); + + x = [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-7), 'returns expected value' ); + + x = [ -4.0, NaN ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ 4.0 ]; + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = []; + for ( i = 0; i < 1e3; i++ ) { + x.push( 100.0 ); + } + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ]; + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = []; + for ( i = 0; i < 1e3; i++ ) { + x.push( NaN ); + } + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { var x; var v; @@ -213,7 +322,6 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -230,15 +338,36 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]; - N = floor( x.length / 2 ); - v = nanvariancewd( N, 1, x, 2 ); + v = nanvariancewd( 5, 1, x, 2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ]; + + v = nanvariancewd( 5, 1, toAccessorArray( x ), 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; @@ -255,9 +384,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 4.0, // 0 2.0 ]; - N = floor( x.length / 2 ); - v = nanvariancewd( N, 1, x, -2 ); + v = nanvariancewd( 5, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = []; @@ -270,6 +398,37 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + var i; + + x = [ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = nanvariancewd( 5, 1, toAccessorArray( x ), -2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + x = []; + for ( i = 0; i < 1e3; i++ ) { + x.push( 100.0 ); + } + v = nanvariancewd( x.length, 1, toAccessorArray( x ), -1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` provided the correction term is not less than `0` and the first element is not `NaN`', function test( t ) { var x; var v; @@ -292,10 +451,31 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p t.end(); }); +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` provided the correction term is not less than `0` and the first element is not `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( x.length, x.length, toAccessorArray( x ), 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -313,9 +493,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = nanvariancewd( N, 1, x1, 2 ); + v = nanvariancewd( 5, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.ndarray.js index 91885e4015ad..478609352e0a 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.ndarray.js @@ -21,8 +21,8 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var nanvariancewd = require( './../lib/ndarray.js' ); @@ -93,6 +93,60 @@ tape( 'the function calculates the population variance of a strided array (ignor t.end(); }); +tape( 'the function calculates the population variance of a strided array (ignoring `NaN` values) (accessors)', function test( t ) { + var x; + var v; + var i; + + x = [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ]; + + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ]; + + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-6), 'returns expected value' ); + + x = [ -4.0, NaN ]; + + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, NaN ]; + + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ 4.0 ]; + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = []; + for ( i = 0; i < 1e3; i++ ) { + x.push( 100.0 ); + } + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ]; + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = []; + for ( i = 0; i < 1e3; i++ ) { + x.push( NaN ); + } + v = nanvariancewd( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function calculates the sample variance of a strided array (ignoring `NaN` values)', function test( t ) { var x; var v; @@ -147,6 +201,60 @@ tape( 'the function calculates the sample variance of a strided array (ignoring t.end(); }); +tape( 'the function calculates the sample variance of a strided array (ignoring `NaN` values) (accessors)', function test( t ) { + var x; + var v; + var i; + + x = [ 1.0, -2.0, -4.0, 5.0, NaN, 0.0, 3.0 ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-2), 'returns expected value' ); + + x = [ 1.0, NaN, NaN, -2.0, NaN, -4.0, NaN, 5.0, NaN, 0.0, 3.0, NaN ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-7), 'returns expected value' ); + + x = [ -4.0, NaN ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ 4.0 ]; + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = []; + for ( i = 0; i < 1e3; i++ ) { + x.push( 100.0 ); + } + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ]; + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = []; + for ( i = 0; i < 1e3; i++ ) { + x.push( NaN ); + } + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { var x; var v; @@ -212,7 +320,6 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -229,15 +336,36 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]; - N = floor( x.length / 2 ); - v = nanvariancewd( N, 1, x, 2, 0 ); + v = nanvariancewd( 5, 1, x, 2, 0 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ]; + + v = nanvariancewd( 5, 1, toAccessorArray( x ), 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; @@ -254,9 +382,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 4.0, // 0 2.0 ]; - N = floor( x.length / 2 ); - v = nanvariancewd( N, 1, x, -2, 8 ); + v = nanvariancewd( 5, 1, x, -2, 8 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = []; @@ -269,6 +396,37 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var x; + var v; + var i; + + x = [ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = nanvariancewd( 5, 1, toAccessorArray( x ), -2, 8 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + x = []; + for ( i = 0; i < 1e3; i++ ) { + x.push( 100.0 ); + } + v = nanvariancewd( x.length, 1, toAccessorArray( x ), -1, x.length-1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` provided the correction term is not less than `0` and the first element is not `NaN`', function test( t ) { var x; var v; @@ -291,8 +449,29 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p t.end(); }); +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` provided the correction term is not less than `0` and the first element is not `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( x.length, 1, toAccessorArray( x ), 0, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( x.length, x.length, toAccessorArray( x ), 0, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -308,9 +487,31 @@ tape( 'the function supports an `offset` parameter', function test( t ) { NaN, NaN // 4 ]; - N = floor( x.length / 2 ); - v = nanvariancewd( N, 1, x, 2, 1 ); + v = nanvariancewd( 5, 1, x, 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `offset` parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + NaN, + NaN // 4 + ]; + + v = nanvariancewd( 5, 1, toAccessorArray( x ), 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From f5d00bf32a21b4d4cc1d2d77adfc3c03f4a44bfc Mon Sep 17 00:00:00 2001 From: prajjwalbajpai Date: Thu, 20 Mar 2025 14:17:07 +0530 Subject: [PATCH 02/14] fix: added NaN to test --- 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: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/base/nanvariancewd/README.md | 19 +++++++++----- .../base/nanvariancewd/benchmark/benchmark.js | 26 ++++++++++++------- .../benchmark/benchmark.ndarray.js | 26 ++++++++++++------- .../stats/base/nanvariancewd/docs/repl.txt | 4 +-- .../base/nanvariancewd/examples/index.js | 15 ++++++++--- .../base/nanvariancewd/test/test.main.js | 1 - 6 files changed, 60 insertions(+), 31 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md b/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md index 1ae7c8e30d24..e0473f405e58 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md @@ -157,9 +157,9 @@ The function has the following additional parameters: While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in the strided array starting from the second element ```javascript -var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ]; -var v = nanvariancewd.ndarray( 4, 1, x, 2, 1 ); +var v = nanvariancewd.ndarray( 5, 1, x, 2, 1 ); // returns 6.25 ``` @@ -187,12 +187,19 @@ var v = nanvariancewd.ndarray( 4, 1, x, 2, 1 ); ```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var nanvariancewd = require( '@stdlib/stats/base/nanvariancewd' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = nanvariancewd( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.js index 43a094abe75f..75811758c67c 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.js @@ -21,22 +21,30 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; var nanvariancewd = require( './../lib/main.js' ); -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -45,7 +53,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.ndarray.js index 65b3f668c5f7..af41fa704b90 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/benchmark/benchmark.ndarray.js @@ -21,22 +21,30 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; var nanvariancewd = require( './../lib/ndarray.js' ); -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -45,7 +53,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt index 538bbf4cb923..7724489e6348 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt @@ -109,8 +109,8 @@ ~4.3333 // Using offset parameter: - > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; - > {{alias}}.ndarray( 3, 1, x, 2, 1 ) + > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ]; + > {{alias}}.ndarray( 4, 1, x, 2, 1 ) ~4.3333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/examples/index.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/examples/index.js index f08423a1755a..b08ceff6d48b 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/examples/index.js @@ -18,12 +18,19 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var nanvariancewd = require( './../lib' ); -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = nanvariancewd( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js index e73130007bbf..e73cfa7603a9 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js @@ -1,4 +1,3 @@ - /** * @license Apache-2.0 * From 2003e2c999f749329a88b2591740ba96fa1b3ead Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Thu, 20 Mar 2025 11:30:31 +0100 Subject: [PATCH 03/14] docs: add returns annotations --- 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/math/array/special/abs/docs/types/index.d.ts | 2 ++ lib/node_modules/@stdlib/math/array/special/abs/lib/main.js | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/node_modules/@stdlib/math/array/special/abs/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/array/special/abs/docs/types/index.d.ts index cbf7373a8918..a2d08374f061 100644 --- a/lib/node_modules/@stdlib/math/array/special/abs/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/array/special/abs/docs/types/index.d.ts @@ -73,6 +73,7 @@ interface Unary { * // returns [ 1.0, 2.0, 3.0 ] * * var bool = ( out === y ); + * // returns true */ assign>( x: InputArray, out: V ): V; } @@ -95,6 +96,7 @@ interface Unary { * // returns [ 1.0, 2.0, 3.0 ] * * var bool = ( out === y ); +* // returns true */ declare const abs: Unary; diff --git a/lib/node_modules/@stdlib/math/array/special/abs/lib/main.js b/lib/node_modules/@stdlib/math/array/special/abs/lib/main.js index 56c59ee21fc6..1bfefe981a06 100644 --- a/lib/node_modules/@stdlib/math/array/special/abs/lib/main.js +++ b/lib/node_modules/@stdlib/math/array/special/abs/lib/main.js @@ -65,6 +65,7 @@ var POLICY = 'same'; * // returns [ 1.0, 2.0, 3.0 ] * * var bool = ( out === y ); +* // returns true */ var abs = unaryFactory( base, IDTYPES, ODTYPES, POLICY ); From 86ebdc429ad7160e2663df7ae1a28401bd3cdf3b Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Thu, 20 Mar 2025 11:46:05 +0100 Subject: [PATCH 04/14] chore: add Git note --- 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: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../1f73fef9451cc77da8f45dfeb28c359685321859.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 docs/git-notes/1f73fef9451cc77da8f45dfeb28c359685321859.txt diff --git a/docs/git-notes/1f73fef9451cc77da8f45dfeb28c359685321859.txt b/docs/git-notes/1f73fef9451cc77da8f45dfeb28c359685321859.txt new file mode 100644 index 000000000000..0aa3ca951480 --- /dev/null +++ b/docs/git-notes/1f73fef9451cc77da8f45dfeb28c359685321859.txt @@ -0,0 +1,9 @@ +--- +type: amend-message +--- +docs: update namespace TypeScript declarations + +PR-URL: #5816 + +Reviewed-by: Philipp Burckhardt +Signed-off-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> From a384a6f84e8b47690fb4e37f17754997b9eac26d Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Thu, 20 Mar 2025 11:46:14 +0100 Subject: [PATCH 05/14] chore: add Git note --- 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: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../61bb59320efa31c8f9c942ca3bbade7828ce6165.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 docs/git-notes/61bb59320efa31c8f9c942ca3bbade7828ce6165.txt diff --git a/docs/git-notes/61bb59320efa31c8f9c942ca3bbade7828ce6165.txt b/docs/git-notes/61bb59320efa31c8f9c942ca3bbade7828ce6165.txt new file mode 100644 index 000000000000..07721e1ec3a1 --- /dev/null +++ b/docs/git-notes/61bb59320efa31c8f9c942ca3bbade7828ce6165.txt @@ -0,0 +1,10 @@ +--- +type: amend-message +--- +feat(stats): add C implementation for `stats/base/dists/hypergeometric/skewness` + +PR-URL: #4560 +Closes: #3666 + +Co-authored-by: stdlib-bot +Reviewed-by: Philipp Burckhardt From d49cae8d350d012153e1af5c633f3ea344aa6ef1 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Thu, 20 Mar 2025 11:46:23 +0100 Subject: [PATCH 06/14] chore: add Git note --- 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: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../dc9f39f6f289ac4a78bdfb99571db2fbbdd6e7a2.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 docs/git-notes/dc9f39f6f289ac4a78bdfb99571db2fbbdd6e7a2.txt diff --git a/docs/git-notes/dc9f39f6f289ac4a78bdfb99571db2fbbdd6e7a2.txt b/docs/git-notes/dc9f39f6f289ac4a78bdfb99571db2fbbdd6e7a2.txt new file mode 100644 index 000000000000..fdcaca07ec38 --- /dev/null +++ b/docs/git-notes/dc9f39f6f289ac4a78bdfb99571db2fbbdd6e7a2.txt @@ -0,0 +1,9 @@ +--- +type: amend-message +--- +chore: address commit comments + +PR-URL: #6011 +Progresses: #6002 + +Reviewed-by: Philipp Burckhardt From cec132827f3d57324680c7e814cc6ec305dd6df8 Mon Sep 17 00:00:00 2001 From: prajjwalbajpai Date: Thu, 20 Mar 2025 21:35:51 +0530 Subject: [PATCH 07/14] fix: fixed errors in examples --- 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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/nanvariancewd/README.md | 8 ++++---- .../@stdlib/stats/base/nanvariancewd/docs/repl.txt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md b/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md index e0473f405e58..ade3efb4f9ee 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md @@ -121,21 +121,21 @@ The `N` and stride parameters determine which elements in the strided array are ```javascript var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN ]; -var v = nanvariancewd( 4, 1, x, 2 ); +var v = nanvariancewd( 5, 1, x, 2 ); // returns 6.25 ``` Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - + ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = nanvariancewd( 4, 1, x1, 2 ); +var v = nanvariancewd( 5, 1, x1, 2 ); // returns 6.25 ``` diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt index 7724489e6348..ed0316eae27a 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt @@ -50,14 +50,14 @@ ~4.3333 // Using `N` and stride parameters: - > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > {{alias}}( 3, 1, x, 2 ) + > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN ]; + > {{alias}}( 4, 1, x, 2 ) ~4.3333 // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, 1, x1, 2 ) + > {{alias}}( 4, 1, x1, 2 ) ~4.3333 From 5d8bb03b473b7637ba447dcf0d9ea25605452668 Mon Sep 17 00:00:00 2001 From: Aayush Khanna <96649223+aayush0325@users.noreply.github.com> Date: Sun, 23 Mar 2025 22:09:14 +0530 Subject: [PATCH 08/14] chore: update line wrapping in repl.txt --- .../@stdlib/stats/base/nanvariancewd/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt index ed0316eae27a..d7fa02916cb6 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt @@ -3,8 +3,8 @@ Computes the variance of a strided array ignoring `NaN` values and using Welford's algorithm. - The `N` and `stride` parameters determine which elements - in the strided array are accessed at runtime. + The `N` and `stride` parameters determine which elements in the strided + array are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. From 8840d5151bc19f1a95e55501ca67943c437e4112 Mon Sep 17 00:00:00 2001 From: Aayush Khanna <96649223+aayush0325@users.noreply.github.com> Date: Sun, 23 Mar 2025 22:12:04 +0530 Subject: [PATCH 09/14] chore: fix linting error --- lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt index d7fa02916cb6..8f96cc7602c1 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt @@ -3,7 +3,7 @@ Computes the variance of a strided array ignoring `NaN` values and using Welford's algorithm. - The `N` and `stride` parameters determine which elements in the strided + The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed From 1aae82dd35f1eec4393b158e032ef3da1d339191 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 1 Apr 2025 22:14:06 -0700 Subject: [PATCH 10/14] docs: update copy Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md b/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md index ade3efb4f9ee..b4e72cd2c041 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/README.md @@ -100,7 +100,7 @@ var nanvariancewd = require( '@stdlib/stats/base/nanvariancewd' ); #### nanvariancewd( N, correction, x, strideX ) -Computes the [variance][variance] of a strided array `x` ignoring `NaN` values and using Welford's algorithm. +Computes the [variance][variance] of a strided array ignoring `NaN` values and using Welford's algorithm. ```javascript var x = [ 1.0, -2.0, NaN, 2.0 ]; From aa2e85b2e26a84f858e126669b92bbd96793793a Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 1 Apr 2025 22:14:51 -0700 Subject: [PATCH 11/14] docs: fix wrapping Signed-off-by: Athan --- .../@stdlib/stats/base/nanvariancewd/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt index 8f96cc7602c1..1f3cf7063440 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/docs/repl.txt @@ -3,8 +3,8 @@ Computes the variance of a strided array ignoring `NaN` values and using Welford's algorithm. - The `N` and `stride` parameters determine which elements in the strided - array are accessed at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. From 06e34a8e7ca8c8f96ee6fcca0f5fef335835cd41 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 1 Apr 2025 22:17:43 -0700 Subject: [PATCH 12/14] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/stats/base/nanvariancewd/lib/accessors.js | 3 +-- lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/main.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/accessors.js index 8d4fb794433b..b36c4406a3f3 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/accessors.js @@ -59,7 +59,7 @@ function nanvariancewd( N, correction, x, strideX, offsetX ) { var n; var i; - // Cache reference to array data: + // Cache a reference to array data: xbuf = x.data; // Cache a reference to the element accessor: @@ -72,7 +72,6 @@ function nanvariancewd( N, correction, x, strideX, offsetX ) { } return NaN; } - ix = offsetX; M2 = 0.0; mu = 0.0; diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/main.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/main.js index e52e00d53ae0..d17c81fbc758 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/lib/main.js @@ -37,9 +37,8 @@ var ndarray = require( './ndarray.js' ); * * @example * var x = [ 1.0, -2.0, NaN, 2.0 ]; -* var N = x.length; * -* var v = nanvariancewd( N, 1, x, 1 ); +* var v = nanvariancewd( x.length, 1, x, 1 ); * // returns ~4.3333 */ function nanvariancewd( N, correction, x, strideX ) { From b944dac946c634beb1bd441b6c911d0b3654a036 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 1 Apr 2025 22:23:10 -0700 Subject: [PATCH 13/14] test: add missing tests and update descriptions Signed-off-by: Athan --- .../base/nanvariancewd/test/test.main.js | 72 +++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js index e73cfa7603a9..f109e1bc625f 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.main.js @@ -40,7 +40,7 @@ tape( 'the function has an arity of 4', function test( t ) { t.end(); }); -tape( 'the function calculates the population variance of a strided array (ignoring `NaN` values)', function test( t ) { +tape( 'the function calculates the population variance of a strided array', function test( t ) { var x; var v; var i; @@ -94,7 +94,7 @@ tape( 'the function calculates the population variance of a strided array (ignor t.end(); }); -tape( 'the function calculates the population variance of a strided array (ignoring `NaN` values) (accessors)', function test( t ) { +tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { var x; var v; var i; @@ -148,7 +148,7 @@ tape( 'the function calculates the population variance of a strided array (ignor t.end(); }); -tape( 'the function calculates the sample variance of a strided array (ignoring `NaN` values)', function test( t ) { +tape( 'the function calculates the sample variance of a strided array', function test( t ) { var x; var v; var i; @@ -202,7 +202,7 @@ tape( 'the function calculates the sample variance of a strided array (ignoring t.end(); }); -tape( 'the function calculates the sample variance of a strided array (ignoring `NaN` values) (accessors)', function test( t ) { +tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { var x; var v; var i; @@ -271,6 +271,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( 0, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = nanvariancewd( -1, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` provided the first element is not `NaN`', function test( t ) { var x; var v; @@ -288,6 +303,23 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat t.end(); }); +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` provided the first element is not `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( 1, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( 1, 0, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided an `N` parameter equal to `1`, the function returns a sample variance equal to `NaN`', function test( t ) { var x; var v; @@ -305,6 +337,23 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a sample t.end(); }); +tape( 'if provided an `N` parameter equal to `1`, the function returns a sample variance equal to `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( 1, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( 1, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided a `correction` parameter yielding a correction term less than or equal to `0`, the function returns `NaN`', function test( t ) { var x; var v; @@ -320,6 +369,21 @@ tape( 'if provided a `correction` parameter yielding a correction term less than t.end(); }); +tape( 'if provided a `correction` parameter yielding a correction term less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( x.length, x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = nanvariancewd( x.length, x.length+1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports a `stride` parameter', function test( t ) { var x; var v; From dedcadd20e6aa9510aec85218a4130c23a7f7c9b Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 1 Apr 2025 22:26:55 -0700 Subject: [PATCH 14/14] test: add missing tests and update descriptions Signed-off-by: Athan --- .../base/nanvariancewd/test/test.ndarray.js | 72 +++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.ndarray.js index 478609352e0a..190ab17e7693 100644 --- a/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanvariancewd/test/test.ndarray.js @@ -39,7 +39,7 @@ tape( 'the function has an arity of 5', function test( t ) { t.end(); }); -tape( 'the function calculates the population variance of a strided array (ignoring `NaN` values)', function test( t ) { +tape( 'the function calculates the population variance of a strided array', function test( t ) { var x; var v; var i; @@ -93,7 +93,7 @@ tape( 'the function calculates the population variance of a strided array (ignor t.end(); }); -tape( 'the function calculates the population variance of a strided array (ignoring `NaN` values) (accessors)', function test( t ) { +tape( 'the function calculates the population variance of a strided array (accessors)', function test( t ) { var x; var v; var i; @@ -147,7 +147,7 @@ tape( 'the function calculates the population variance of a strided array (ignor t.end(); }); -tape( 'the function calculates the sample variance of a strided array (ignoring `NaN` values)', function test( t ) { +tape( 'the function calculates the sample variance of a strided array', function test( t ) { var x; var v; var i; @@ -201,7 +201,7 @@ tape( 'the function calculates the sample variance of a strided array (ignoring t.end(); }); -tape( 'the function calculates the sample variance of a strided array (ignoring `NaN` values) (accessors)', function test( t ) { +tape( 'the function calculates the sample variance of a strided array (accessors)', function test( t ) { var x; var v; var i; @@ -270,6 +270,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( 0, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = nanvariancewd( -1, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` provided the first element is not `NaN`', function test( t ) { var x; var v; @@ -287,6 +302,23 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat t.end(); }); +tape( 'if provided an `N` parameter equal to `1`, the function returns a population variance of `0` provided the first element is not `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( 1, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( 1, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided an `N` parameter equal to `1`, the function returns a sample variance equal to `NaN`', function test( t ) { var x; var v; @@ -304,6 +336,23 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a sample t.end(); }); +tape( 'if provided an `N` parameter equal to `1`, the function returns a sample variance equal to `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( 1, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( 1, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided a `correction` parameter yielding a correction term less than or equal to `0`, the function returns `NaN`', function test( t ) { var x; var v; @@ -319,6 +368,21 @@ tape( 'if provided a `correction` parameter yielding a correction term less than t.end(); }); +tape( 'if provided a `correction` parameter yielding a correction term less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanvariancewd( x.length, x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = nanvariancewd( x.length, x.length+1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports a `stride` parameter', function test( t ) { var x; var v;