From 3ae71d5ae205bbfb7fe99f4a9b2845007b6cfd0e Mon Sep 17 00:00:00 2001 From: AryanBhirud Date: Thu, 6 Mar 2025 21:55:03 +0530 Subject: [PATCH 01/15] feat: add accessor protocol support to --- 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- CONTRIBUTORS | 1 + .../@stdlib/stats/base/variancepn/README.md | 16 +- .../base/variancepn/benchmark/benchmark.js | 19 +- .../variancepn/benchmark/benchmark.ndarray.js | 19 +- .../stats/base/variancepn/docs/repl.txt | 20 +-- .../base/variancepn/docs/types/index.d.ts | 18 +- .../stats/base/variancepn/docs/types/test.ts | 5 +- .../stats/base/variancepn/examples/index.js | 16 +- .../stats/base/variancepn/lib/accessors.js | 104 +++++++++++ .../stats/base/variancepn/lib/ndarray.js | 41 +++-- .../stats/base/variancepn/lib/variancepn.js | 49 +---- .../stats/base/variancepn/test/test.js | 2 +- .../base/variancepn/test/test.ndarray.js | 164 ++++++++++++++++- .../base/variancepn/test/test.variancepn.js | 168 +++++++++++++++++- 14 files changed, 524 insertions(+), 118 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js diff --git a/CONTRIBUTORS b/CONTRIBUTORS index f42bcc8cf5a5..b7b057ca60d0 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -17,6 +17,7 @@ Ali Salesi Aman Bhansali Amit Jimiwal Anudeep Sanapala +Aryan Bhirud Athan Reines Ayaka <73595362+USERSATOSHI@users.noreply.github.com> Brendan Graetz diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/README.md b/lib/node_modules/@stdlib/stats/base/variancepn/README.md index 5775585ee772..56011cb5af6a 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/variancepn/README.md @@ -2,7 +2,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. @@ -197,18 +197,12 @@ var v = variancepn.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 variancepn = require( '@stdlib/stats/base/variancepn' ); -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 = variancepn( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js index 24b5d4603b04..328bb17d1675 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.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. @@ -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 variancepn = require( './../lib/variancepn.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var variancepn = require( './../lib/variancepn.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - 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/variancepn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.js index a60d78aca901..83e16d1bbfd8 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.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. @@ -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 variancepn = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var variancepn = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - 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/variancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt index e3bffde92299..8adbd83bf654 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt @@ -2,8 +2,8 @@ {{alias}}( N, correction, x, stride ) Computes the variance of a strided array using a two-pass 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. @@ -31,7 +31,7 @@ Input array. stride: integer - Index increment. + Stride length. Returns ------- @@ -45,21 +45,20 @@ > {{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, stride ) ~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, stride ) ~4.3333 + {{alias}}.ndarray( N, correction, x, stride, offset ) Computes the variance of a strided array using a two-pass algorithm and alternative indexing semantics. @@ -89,7 +88,7 @@ Input array. stride: integer - Index increment. + Stride length. offset: integer Starting index. @@ -108,8 +107,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/variancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts index 7db62141e6a1..65054eacede5 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts @@ -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. @@ -20,14 +20,20 @@ /// -import { NumericArray } from '@stdlib/types/array'; +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + /** * Interface describing `variancepn`. */ interface Routine { /** - * Computes the variance of a strided array using a two-pass algorithm. + * Computes the variance of a strided array using a two-pass algorithm and alternative indexing semantics. * * @param N - number of indexed elements * @param correction - degrees of freedom adjustment @@ -38,10 +44,10 @@ interface Routine { * @example * var x = [ 1.0, -2.0, 2.0 ]; * - * var v = variancepn( x.length, 1, x, 1 ); + * var v = variancepn( x.length, 1, x, 1, 0 ); * // returns ~4.3333 */ - ( N: number, correction: number, x: NumericArray, stride: number ): number; + ( N: number, correction: number, x: NumericArray | InputArray, stride: number ): number; /** * Computes the variance of a strided array using a two-pass algorithm and alternative indexing semantics. @@ -59,7 +65,7 @@ interface Routine { * var v = variancepn.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, stride: number, offset: number ): number; } /** diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts index 146d3b4a5983..b0cf16808f20 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts @@ -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. @@ -16,6 +16,7 @@ * limitations under the License. */ +import AccessorArray = require( '@stdlib/array/base/accessor' ); import variancepn = require( './index' ); @@ -26,6 +27,7 @@ import variancepn = require( './index' ); const x = new Float64Array( 10 ); variancepn( x.length, 1, x, 1 ); // $ExpectType number + variancepn( 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 variancepn = require( './index' ); const x = new Float64Array( 10 ); variancepn.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number + variancepn.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/variancepn/examples/index.js b/lib/node_modules/@stdlib/stats/base/variancepn/examples/index.js index c128c57945e2..de1d865ef6bd 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/examples/index.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. @@ -18,18 +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 variancepn = require( './../lib' ); -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 = variancepn( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js new file mode 100644 index 000000000000..a611ece5d593 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js @@ -0,0 +1,104 @@ +/** +* @license Apache-2.0 +* +* 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +// MAIN // + +/** +* Computes the variance of a strided array using a two-pass algorithm. +* +* ## Method +* +* - This implementation uses a two-pass approach, as suggested by Neely (1966). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Object} x - input array object +* @param {Array} x.accessors - array element accessors +* @param {integer} stride - stride length +* @param {integer} offset - starting index +* @returns {number} variance +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 1.0, -2.0, 2.0 ] ); +* +* var v = variancepn( 3, 1, arraylike2object( x ), 1, 0 ); +* // returns ~4.3333 +*/ +function variancepn( N, correction, x, stride, offset ) { + var xbuf; + var get; + var sum; + var mu; + var M2; + var ix; + var M; + var d; + var n; + var i; + + // Cache references to array data: + xbuf = x.data; + + // Cache references to element accessors: + get = x.accessors[ 0 ]; + + sum = 0.0; + M2 = 0.0; + M = 0.0; + ix = offset; + n = N - correction; + + if ( N <= 0 || n <= 0 ) { + return NaN; + } + if ( N === 1 || stride === 0 ) { + return 0.0; + } + + // Compute the mean: + for ( i = 0; i < N; i++ ) { + sum += get( xbuf, ix ); + ix += stride; + } + mu = sum / N; + + // Compute the variance: + ix = offset; + for ( i = 0; i < N; i++ ) { + d = get( xbuf, ix ) - mu; + M2 += d * d; + M += d; + ix += stride; + } + + return ( M2 / n ) - ( ( M / N ) * ( M / n ) ); +} + +module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js index 6d3ee7b50e81..3e4f0be9f900 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.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. @@ -20,7 +20,9 @@ // MODULES // +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ).ndarray; +var accessors = require( './accessors.js' ); // MAIN // @@ -39,40 +41,47 @@ var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ).ndarray; * * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array +* @param {Object} x - input array object +* @param {Array} x.accessors - array element accessors * @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} offset - starting index * @returns {number} variance * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); +* var x = [ 1.0, -2.0, 2.0 ]; +* var N = x.length; * -* 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 = variancepn( N, 1, x, 2, 1 ); -* // returns 6.25 +* var v = variancepn( N, 1, x, 1, 0 ); +* // returns ~4.3333 */ function variancepn( N, correction, x, stride, offset ) { + var xobj; var mu; - var ix; var M2; + var ix; var M; var d; var n; var i; + xobj = arraylike2object( x ); + + if ( xobj.accessorProtocol ) { + return accessors( N, correction, xobj, stride, offset ); + } + n = N - correction; - if ( N <= 0 || n <= 0.0 ) { + if ( N <= 0 || n <= 0 ) { return NaN; } if ( N === 1 || stride === 0 ) { return 0.0; } - // Compute an estimate for the mean: + + // Compute the mean: mu = gsumpw( N, x, stride, offset ) / N; - // Compute the variance... + // Compute the variance: ix = offset; M2 = 0.0; M = 0.0; @@ -82,10 +91,8 @@ function variancepn( N, correction, x, stride, offset ) { M += d; ix += stride; } - return (M2/n) - ((M/N)*(M/n)); -} - -// EXPORTS // + return ( M2 / n ) - ( ( M / N ) * ( M / n ) ); +} module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/variancepn.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/variancepn.js index e6be432823a1..ab7ae6e28484 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/variancepn.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/lib/variancepn.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. @@ -20,7 +20,8 @@ // MODULES // -var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -39,54 +40,22 @@ var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); * * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array +* @param {Object} x - input array object +* @param {Array} x.accessors - array element accessors * @param {integer} stride - stride length +* @param {integer} offset - starting index * @returns {number} variance * * @example * var x = [ 1.0, -2.0, 2.0 ]; * var N = x.length; * -* var v = variancepn( N, 1, x, 1 ); +* var v = variancepn( N, 1, x, 1); * // returns ~4.3333 */ function variancepn( N, correction, x, stride ) { - var mu; - var ix; - var M2; - var M; - var d; - var n; - var i; - - n = N - correction; - if ( N <= 0 || n <= 0.0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - return 0.0; - } - // Compute an estimate for the mean: - mu = gsumpw( N, x, stride ) / N; - - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - // Compute the variance... - M2 = 0.0; - M = 0.0; - for ( i = 0; i < N; i++ ) { - d = x[ ix ] - mu; - M2 += d * d; - M += d; - ix += stride; - } - return (M2/n) - ((M/N)*(M/n)); + var offset = stride2offset( N, stride ); + return ndarray( N, correction, x, stride, offset ); } - -// EXPORTS // - module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.js b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.js index 952358607ce1..06df5112b985 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.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. diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js index 0628463ab9a1..d65585d1e2bf 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.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. @@ -23,6 +23,7 @@ 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 variancepn = require( './../lib/ndarray.js' ); @@ -58,6 +59,25 @@ tape( 'the function calculates the population variance of a strided array', func t.end(); }); +tape( 'the function calculates the population variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( 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', function test( t ) { var x; var v; @@ -77,6 +97,25 @@ tape( 'the function calculates the sample variance of a strided array', function t.end(); }); +tape( 'the function calculates the sample variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( 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; @@ -92,6 +131,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` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 0, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( -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`', function test( t ) { var x; var v; @@ -104,6 +158,18 @@ 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` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 1, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { var x; var v; @@ -119,6 +185,21 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or t.end(); }); +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, x.length, toAccessorArray( x ), 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( 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 N; var x; @@ -142,6 +223,29 @@ tape( 'the function supports a `stride` parameter', function test( t ) { t.end(); }); +tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { + var N; + 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 + ]; + + N = floor( x.length / 2 ); + v = variancepn( N, 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; @@ -165,6 +269,29 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); +tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { + var N; + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + N = floor( x.length / 2 ); + v = variancepn( N, 1, toAccessorArray( x ), -2, 6 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { var x; var v; @@ -177,6 +304,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', t.end(); }); +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, 1, toAccessorArray( x ), 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports an `offset` parameter', function test( t ) { var N; var x; @@ -199,3 +338,26 @@ tape( 'the function supports an `offset` parameter', function test( t ) { t.end(); }); + +tape( 'the function supports an `offset` parameter (accessor)', function test( t ) { + var N; + 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 + ]; + N = floor( x.length / 2 ); + + v = variancepn( N, 1, toAccessorArray( x ), 2, 1 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js index 5b72a7c7e5be..ad6df37c9193 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.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. @@ -24,6 +24,7 @@ var tape = require( 'tape' ); var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var variancepn = require( './../lib/variancepn.js' ); @@ -59,6 +60,25 @@ tape( 'the function calculates the population variance of a strided array', func t.end(); }); +tape( 'the function calculates the population variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( 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', function test( t ) { var x; var v; @@ -78,6 +98,25 @@ tape( 'the function calculates the sample variance of a strided array', function t.end(); }); +tape( 'the function calculates the sample variance of a strided array (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = variancepn( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = variancepn( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = variancepn( 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; @@ -93,6 +132,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` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 0, 1, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( -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`', function test( t ) { var x; var v; @@ -105,6 +159,18 @@ 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` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( 1, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { var x; var v; @@ -120,6 +186,21 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or t.end(); }); +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, x.length, toAccessorArray( x ), 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = variancepn( 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 N; var x; @@ -143,6 +224,29 @@ tape( 'the function supports a `stride` parameter', function test( t ) { t.end(); }); +tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { + var N; + 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 + ]; + + N = floor( x.length / 2 ); + v = variancepn( N, 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; @@ -166,6 +270,29 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); +tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { + var N; + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + N = floor( x.length / 2 ); + v = variancepn( N, 1, toAccessorArray( x ), -2 ); + + t.strictEqual( v, 6.25, 'returns expected value' ); + t.end(); +}); + tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { var x; var v; @@ -178,6 +305,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', t.end(); }); +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = variancepn( x.length, 1, toAccessorArray( x ), 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports view offsets', function test( t ) { var x0; var x1; @@ -204,3 +343,30 @@ tape( 'the function supports view offsets', function test( t ) { t.end(); }); + +tape( 'the function supports view offsets (accessor)', function test( t ) { + var x0; + var x1; + var N; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); + + v = variancepn( N, 1, toAccessorArray( x1 ), 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); From f5e709c57b2c29d68d74a76e9aebe25b54e747f3 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 29 Apr 2025 17:58:22 -0700 Subject: [PATCH 02/15] Discard changes to CONTRIBUTORS --- CONTRIBUTORS | 1 - 1 file changed, 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b7b057ca60d0..f42bcc8cf5a5 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -17,7 +17,6 @@ Ali Salesi Aman Bhansali Amit Jimiwal Anudeep Sanapala -Aryan Bhirud Athan Reines Ayaka <73595362+USERSATOSHI@users.noreply.github.com> Brendan Graetz From 7424d7cb9ae06ac74f61da596a5b01e483b9ad27 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 29 Apr 2025 17:59:52 -0700 Subject: [PATCH 03/15] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/stats/base/variancepn/docs/repl.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt index 8adbd83bf654..07152ec4492b 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt @@ -47,15 +47,13 @@ // Using `N` and stride parameters: > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ]; - > var stride = 2; - > {{alias}}( 3, 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 ); - > stride = 2; - > {{alias}}( 3, 1, x1, stride ) + > {{alias}}( 3, 1, x1, 2 ) ~4.3333 From 27f923d8025c8291e0588305133a8e92dd6d9c05 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 29 Apr 2025 18:00:53 -0700 Subject: [PATCH 04/15] docs: fix description Signed-off-by: Athan --- .../@stdlib/stats/base/variancepn/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts index 65054eacede5..b9a35cb64bdd 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts @@ -33,7 +33,7 @@ type InputArray = NumericArray | Collection | AccessorArrayLike; */ interface Routine { /** - * Computes the variance of a strided array using a two-pass algorithm and alternative indexing semantics. + * Computes the variance of a strided array using a two-pass algorithm. * * @param N - number of indexed elements * @param correction - degrees of freedom adjustment From e31df354a8f26bd7aa638822aaf5e04f0d2a4e2b Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 29 Apr 2025 18:01:46 -0700 Subject: [PATCH 05/15] docs: update parameter names Signed-off-by: Athan --- .../stats/base/variancepn/docs/types/index.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts index b9a35cb64bdd..b59ba9a84572 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts @@ -38,7 +38,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 @@ -47,7 +47,7 @@ interface Routine { * var v = variancepn( x.length, 1, x, 1, 0 ); * // returns ~4.3333 */ - ( N: number, correction: number, x: NumericArray | InputArray, stride: number ): number; + ( N: number, correction: number, x: NumericArray | InputArray, strideX: number ): number; /** * Computes the variance of a strided array using a two-pass algorithm and alternative indexing semantics. @@ -55,8 +55,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 @@ -65,7 +65,7 @@ interface Routine { * var v = variancepn.ndarray( x.length, 1, x, 1, 0 ); * // returns ~4.3333 */ - ndarray( N: number, correction: number, x: InputArray, stride: number, offset: number ): number; + ndarray( N: number, correction: number, x: InputArray, strideX: number, offsetX: number ): number; } /** @@ -74,7 +74,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 From c72828e85880bf3d2ab787cdcbed9e4d8846d01c Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 29 Apr 2025 18:02:22 -0700 Subject: [PATCH 06/15] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/stats/base/variancepn/docs/types/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts index b59ba9a84572..35116730f98b 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts @@ -44,10 +44,10 @@ interface Routine { * @example * var x = [ 1.0, -2.0, 2.0 ]; * - * var v = variancepn( x.length, 1, x, 1, 0 ); + * var v = variancepn( x.length, 1, x, 1 ); * // returns ~4.3333 */ - ( N: number, correction: number, x: NumericArray | InputArray, strideX: number ): number; + ( N: number, correction: number, x: InputArray, strideX: number ): number; /** * Computes the variance of a strided array using a two-pass algorithm and alternative indexing semantics. From 724453c08c7e69cf0f46b2db7226b02fdd2cd327 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 29 Apr 2025 18:04:00 -0700 Subject: [PATCH 07/15] Discard changes to lib/node_modules/@stdlib/stats/base/variancepn/test/test.js --- lib/node_modules/@stdlib/stats/base/variancepn/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.js b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.js index 06df5112b985..952358607ce1 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. From a6f440abd1cb4e1dafe97be4e756791b01a42f1b Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Thu, 12 Jun 2025 08:05:59 +0000 Subject: [PATCH 08/15] feat: refactor variancepn implementation --- 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/base/variancepn/lib/accessors.js | 59 +++++++++--------- .../stats/base/variancepn/lib/index.js | 14 +++-- .../@stdlib/stats/base/variancepn/lib/main.js | 33 +++++++++- .../stats/base/variancepn/lib/ndarray.js | 54 ++++++++-------- .../stats/base/variancepn/lib/variancepn.js | 61 ------------------- 5 files changed, 93 insertions(+), 128 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/variancepn/lib/variancepn.js diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js index a611ece5d593..4a0eddf47f02 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js @@ -20,6 +20,9 @@ // MODULES // +var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ).ndarray; + + // MAIN // /** @@ -37,68 +40,62 @@ * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Object} x - input array object +* @param {Collection} x.data - input array data * @param {Array} x.accessors - array element accessors -* @param {integer} stride - stride length -* @param {integer} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * -* var x = toAccessorArray( [ 1.0, -2.0, 2.0 ] ); +* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * -* var v = variancepn( 3, 1, arraylike2object( x ), 1, 0 ); -* // returns ~4.3333 +* var v = variancepn( 4, 1, arraylike2object( x ), 2, 1 ); +* // returns 6.25 */ -function variancepn( N, correction, x, stride, offset ) { +function variancepn( N, correction, x, strideX, offsetX ) { var xbuf; var get; - var sum; var mu; - var M2; var ix; + var M2; var M; var d; var n; var i; - // Cache references to array data: + // Cache reference to array data: xbuf = x.data; - // Cache references to element accessors: + // Cache a reference to the element accessor: get = x.accessors[ 0 ]; - sum = 0.0; - M2 = 0.0; - M = 0.0; - ix = offset; - n = N - correction; - - if ( N <= 0 || n <= 0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { + if ( N === 1 || strideX === 0 ) { return 0.0; } - // Compute the mean: - for ( i = 0; i < N; i++ ) { - sum += get( xbuf, ix ); - ix += stride; - } - mu = sum / N; + // Compute an estimate for the mean: + mu = gsumpw( N, xbuf, strideX, offsetX ) / N; + + n = N - correction; + ix = offsetX; + + // Compute the variance... + M2 = 0.0; + M = 0.0; - // Compute the variance: - ix = offset; for ( i = 0; i < N; i++ ) { d = get( xbuf, ix ) - mu; M2 += d * d; M += d; - ix += stride; + ix += strideX; } - - return ( M2 / n ) - ( ( M / N ) * ( M / n ) ); + return (M2/n) - ((M/N)*(M/n)); } + +// EXPORTS // + module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/index.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/index.js index 9c1e2b197154..0c47634b9930 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/lib/index.js @@ -27,25 +27,29 @@ * var variancepn = require( '@stdlib/stats/base/variancepn' ); * * var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; * -* var v = variancepn( N, 1, x, 1 ); +* var v = variancepn( x.length, 1, x, 1 ); * // returns ~4.3333 * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var variancepn = require( '@stdlib/stats/base/variancepn' ); * * 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 = variancepn.ndarray( N, 1, x, 2, 1 ); +* var v = variancepn.ndarray( 4, 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/variancepn/lib/main.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/main.js index f20dcbfda109..a9378f2693ab 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/lib/main.js @@ -20,14 +20,41 @@ // MODULES // -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var variancepn = require( './variancepn.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); var ndarray = require( './ndarray.js' ); // MAIN // -setReadOnly( variancepn, 'ndarray', ndarray ); +/** +* Computes the variance of a strided array using a two-pass algorithm. +* +* ## Method +* +* - This implementation uses a two-pass approach, as suggested by Neely (1966). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {number} correction - degrees of freedom adjustment +* @param {Object} x - input array object +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {integer} offsetX - starting index +* @returns {number} variance +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = variancepn( x.length, 1, x, 1); +* // returns ~4.3333 +*/ +function variancepn( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +} // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js index 3e4f0be9f900..986d87152a06 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -20,8 +20,8 @@ // MODULES // -var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ).ndarray; +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); var accessors = require( './accessors.js' ); @@ -41,58 +41,56 @@ var accessors = require( './accessors.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment -* @param {Object} x - input array object -* @param {Array} x.accessors - array element accessors -* @param {integer} stride - stride length -* @param {integer} offset - starting index +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * * @example -* var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; * -* var v = variancepn( N, 1, x, 1, 0 ); -* // returns ~4.3333 +* var v = variancepn( 4, 1, x, 2, 1 ); +* // returns 6.25 */ -function variancepn( N, correction, x, stride, offset ) { - var xobj; +function variancepn( N, correction, x, strideX, offsetX ) { var mu; - var M2; var ix; + var M2; + var o; var M; var d; var n; var i; - xobj = arraylike2object( x ); - - if ( xobj.accessorProtocol ) { - return accessors( N, correction, xobj, stride, offset ); - } - n = N - correction; - if ( N <= 0 || n <= 0 ) { + if ( N <= 0 || n <= 0.0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, correction, o, strideX, offsetX ); + } + if ( N === 1 || strideX === 0 ) { return 0.0; } - // Compute the mean: - mu = gsumpw( N, x, stride, offset ) / N; + // Compute an estimate for the mean: + mu = gsumpw( N, x, strideX, offsetX ) / N; - // Compute the variance: - ix = offset; + // Compute the variance... + ix = offsetX; M2 = 0.0; M = 0.0; for ( i = 0; i < N; i++ ) { d = x[ ix ] - mu; M2 += d * d; M += d; - ix += stride; + ix += strideX; } - - return ( M2 / n ) - ( ( M / N ) * ( M / n ) ); + return (M2/n) - ((M/N)*(M/n)); } + +// EXPORTS // + module.exports = variancepn; diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/variancepn.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/variancepn.js deleted file mode 100644 index ab7ae6e28484..000000000000 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/variancepn.js +++ /dev/null @@ -1,61 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -/** -* Computes the variance of a strided array using a two-pass algorithm. -* -* ## Method -* -* - This implementation uses a two-pass approach, as suggested by Neely (1966). -* -* ## References -* -* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). -* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {Object} x - input array object -* @param {Array} x.accessors - array element accessors -* @param {integer} stride - stride length -* @param {integer} offset - starting index -* @returns {number} variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; -* -* var v = variancepn( N, 1, x, 1); -* // returns ~4.3333 -*/ -function variancepn( N, correction, x, stride ) { - var offset = stride2offset( N, stride ); - return ndarray( N, correction, x, stride, offset ); -} - -module.exports = variancepn; From 7428c4941fb0e3620e780cf61c65687ec3456226 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Thu, 12 Jun 2025 08:25:49 +0000 Subject: [PATCH 09/15] fix: correct copyright year in variancepn example --- 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: passed - 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/variancepn/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/examples/index.js b/lib/node_modules/@stdlib/stats/base/variancepn/examples/index.js index de1d865ef6bd..1604300161f2 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. From cbf06fc4e6144ee328b3ab0819cb1b4bcd726a53 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Thu, 12 Jun 2025 08:28:44 +0000 Subject: [PATCH 10/15] fix: update copyright year in benchmark files --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: 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: 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 --- --- .../@stdlib/stats/base/variancepn/benchmark/benchmark.js | 4 ++-- .../stats/base/variancepn/benchmark/benchmark.ndarray.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js index 328bb17d1675..39accf4d64b1 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -25,7 +25,7 @@ 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 variancepn = require( './../lib/variancepn.js' ); +var variancepn = require( './../lib/main.js' ); // VARIABLES // diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.js index 83e16d1bbfd8..95fcc33e9c07 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/benchmark/benchmark.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. From 94f82173880163d287f7a58a9a6a260481d934f8 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Thu, 12 Jun 2025 08:30:09 +0000 Subject: [PATCH 11/15] docs: update docs --- 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: 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: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/variancepn/docs/repl.txt | 10 +++++----- .../stats/base/variancepn/docs/types/index.d.ts | 3 +-- .../@stdlib/stats/base/variancepn/docs/types/test.ts | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt index 07152ec4492b..42cfaca6a2d4 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( N, correction, x, stride ) +{{alias}}( N, correction, x, strideX ) Computes the variance of a strided array using a two-pass algorithm. The `N` and stride parameters determine which elements in the strided array @@ -30,7 +30,7 @@ x: Array|TypedArray Input array. - stride: integer + strideX: integer Stride length. Returns @@ -57,7 +57,7 @@ ~4.3333 -{{alias}}.ndarray( N, correction, x, stride, offset ) +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) Computes the variance of a strided array using a two-pass algorithm and alternative indexing semantics. @@ -85,10 +85,10 @@ x: Array|TypedArray Input array. - stride: integer + strideX: integer Stride length. - offset: integer + offsetX: integer Starting index. Returns diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts index 35116730f98b..067b117ec1b1 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -27,7 +27,6 @@ import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array */ type InputArray = NumericArray | Collection | AccessorArrayLike; - /** * Interface describing `variancepn`. */ diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts index b0cf16808f20..6d421920bf71 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. From 19dd4eceea75a997fe2d21eba60387d990b3ac72 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Thu, 12 Jun 2025 08:36:22 +0000 Subject: [PATCH 12/15] fix: variancepn test files --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: 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 --- --- .../base/variancepn/test/test.ndarray.js | 27 +++++------------ .../base/variancepn/test/test.variancepn.js | 29 +++++-------------- 2 files changed, 15 insertions(+), 41 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js index d65585d1e2bf..2747ec614540 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -21,7 +21,6 @@ // 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 variancepn = require( './../lib/ndarray.js' ); @@ -201,7 +200,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -216,15 +214,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = variancepn( N, 1, x, 2, 0 ); + v = variancepn( 4, 1, x, 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { - var N; var x; var v; @@ -239,15 +235,13 @@ tape( 'the function supports a `stride` parameter (accessor)', function test( t 2.0 ]; - N = floor( x.length / 2 ); - v = variancepn( N, 1, toAccessorArray( x ), 2, 0 ); + v = variancepn( 4, 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; @@ -262,15 +256,13 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = variancepn( N, 1, x, -2, 6 ); + v = variancepn( 4, 1, x, -2, 6 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { - var N; var x; var v; @@ -285,8 +277,7 @@ tape( 'the function supports a negative `stride` parameter (accessor)', function 2.0 ]; - N = floor( x.length / 2 ); - v = variancepn( N, 1, toAccessorArray( x ), -2, 6 ); + v = variancepn( 4, 1, toAccessorArray( x ), -2, 6 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -317,7 +308,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` ( }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -331,16 +321,14 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]; - N = floor( x.length / 2 ); - v = variancepn( N, 1, x, 2, 1 ); + v = variancepn( 4, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports an `offset` parameter (accessor)', function test( t ) { - var N; var x; var v; @@ -354,9 +342,8 @@ tape( 'the function supports an `offset` parameter (accessor)', function test( t 3.0, 4.0 // 3 ]; - N = floor( x.length / 2 ); - v = variancepn( N, 1, toAccessorArray( x ), 2, 1 ); + v = variancepn( 4, 1, toAccessorArray( x ), 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js index ad6df37c9193..985611269c21 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/test/test.variancepn.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -21,11 +21,10 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -var variancepn = require( './../lib/variancepn.js' ); +var variancepn = require( './../lib/main.js' ); // TESTS // @@ -202,7 +201,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -217,15 +215,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = variancepn( N, 1, x, 2 ); + v = variancepn( 4, 1, x, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a `stride` parameter (accessor)', function test( t ) { - var N; var x; var v; @@ -240,15 +236,13 @@ tape( 'the function supports a `stride` parameter (accessor)', function test( t 2.0 ]; - N = floor( x.length / 2 ); - v = variancepn( N, 1, toAccessorArray( x ), 2 ); + v = variancepn( 4, 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; @@ -263,15 +257,13 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = variancepn( N, 1, x, -2 ); + v = variancepn( 4, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) { - var N; var x; var v; @@ -286,8 +278,7 @@ tape( 'the function supports a negative `stride` parameter (accessor)', function 2.0 ]; - N = floor( x.length / 2 ); - v = variancepn( N, 1, toAccessorArray( x ), -2 ); + v = variancepn( 4, 1, toAccessorArray( x ), -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -320,7 +311,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` ( tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -336,9 +326,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 = variancepn( N, 1, x1, 2 ); + v = variancepn( 4, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -347,7 +336,6 @@ tape( 'the function supports view offsets', function test( t ) { tape( 'the function supports view offsets (accessor)', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -363,9 +351,8 @@ tape( 'the function supports view offsets (accessor)', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = variancepn( N, 1, toAccessorArray( x1 ), 2 ); + v = variancepn( 4, 1, toAccessorArray( x1 ), 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From 33d00a8487ce3a38c08a627c7a5b8b1d1bf893e6 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Thu, 12 Jun 2025 08:39:36 +0000 Subject: [PATCH 13/15] fix: correct variancepn README --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: 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/variancepn/README.md | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/README.md b/lib/node_modules/@stdlib/stats/base/variancepn/README.md index 8d458c8a8b62..0bfd12f46a3b 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/variancepn/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +Copyright (c) 2020 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. @@ -98,15 +98,14 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var variancepn = require( '@stdlib/stats/base/variancepn' ); ``` -#### variancepn( N, correction, x, stride ) +#### variancepn( N, correction, x, strideX ) -Computes the [variance][variance] of a strided array `x` using a two-pass algorithm. +Computes the [variance][variance] of a strided array using a two-pass algorithm. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = variancepn( N, 1, x, 1 ); +var v = variancepn( x.length, 1, x, 1 ); // returns ~4.3333 ``` @@ -115,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. 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 ]; -var N = floor( x.length / 2 ); -var v = variancepn( N, 1, x, 2 ); +var v = variancepn( 4, 1, x, 2 ); // returns 6.25 ``` @@ -135,42 +131,35 @@ 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 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = variancepn( N, 1, x1, 2 ); +var v = variancepn( 4, 1, x1, 2 ); // returns 6.25 ``` -#### variancepn.ndarray( N, correction, x, stride, offset ) +#### variancepn.ndarray( N, correction, x, strideX, offsetX ) Computes the [variance][variance] of a strided array using a two-pass algorithm and alternative indexing semantics. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = variancepn.ndarray( N, 1, x, 1, 0 ); +var v = variancepn.ndarray( x.length, 1, x, 1, 0 ); // returns ~4.33333 ``` 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 `x` 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 = variancepn.ndarray( N, 1, x, 2, 1 ); +var v = variancepn.ndarray( 4, 1, x, 2, 1 ); // returns 6.25 ``` @@ -184,6 +173,7 @@ var v = variancepn.ndarray( N, 1, x, 2, 1 ); - If `N <= 0`, both functions return `NaN`. - If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), 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]). - Depending on the environment, the typed versions ([`dvariancepn`][@stdlib/stats/strided/dvariancepn], [`svariancepn`][@stdlib/stats/strided/svariancepn], etc.) are likely to be significantly more performant. @@ -259,6 +249,8 @@ console.log( v ); [@schubert:2018a]: https://doi.org/10.1145/3221269.3223036 +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor + [@stdlib/stats/strided/dvariancepn]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dvariancepn From ee344ba64214b48a5063b4f580db4a65c9cb53f3 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 12 Jun 2025 23:59:04 -0700 Subject: [PATCH 14/15] docs: avoid duplicate declaration Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt index 42cfaca6a2d4..0f5b45ec364c 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/variancepn/docs/repl.txt @@ -104,7 +104,7 @@ ~4.3333 // Using offset parameter: - > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; + > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; > {{alias}}.ndarray( 3, 1, x, 2, 1 ) ~4.3333 From c4f05b56dd803b6bf74bcf7e5ab0cb528fcfe069 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 13 Jun 2025 00:01:53 -0700 Subject: [PATCH 15/15] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/stats/base/variancepn/lib/accessors.js | 4 ---- .../@stdlib/stats/base/variancepn/lib/ndarray.js | 7 +++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js index 4a0eddf47f02..70c77a3760dc 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/lib/accessors.js @@ -72,10 +72,6 @@ function variancepn( N, correction, x, strideX, offsetX ) { // Cache a reference to the element accessor: get = x.accessors[ 0 ]; - if ( N === 1 || strideX === 0 ) { - return 0.0; - } - // Compute an estimate for the mean: mu = gsumpw( N, xbuf, strideX, offsetX ) / N; diff --git a/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js index 986d87152a06..8e032e6811aa 100644 --- a/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/variancepn/lib/ndarray.js @@ -66,14 +66,13 @@ function variancepn( N, correction, x, strideX, offsetX ) { if ( N <= 0 || n <= 0.0 ) { return NaN; } + if ( N === 1 || strideX === 0 ) { + return 0.0; + } o = arraylike2object( x ); if ( o.accessorProtocol ) { return accessors( N, correction, o, strideX, offsetX ); } - if ( N === 1 || strideX === 0 ) { - return 0.0; - } - // Compute an estimate for the mean: mu = gsumpw( N, x, strideX, offsetX ) / N;