From 3437c9c1428b990d7ee59cd4b1a002fddb602350 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta Date: Sat, 8 Mar 2025 16:02:15 -0500 Subject: [PATCH 01/18] feat: add protocol support to stats/base/varianceyc --- 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 --- --- .../@stdlib/stats/base/varianceyc/README.md | 40 +++--- .../base/varianceyc/benchmark/benchmark.js | 17 +-- .../varianceyc/benchmark/benchmark.ndarray.js | 17 +-- .../stats/base/varianceyc/docs/repl.txt | 34 ++--- .../base/varianceyc/docs/types/index.d.ts | 21 ++- .../stats/base/varianceyc/docs/types/test.ts | 3 + .../stats/base/varianceyc/examples/index.js | 14 +- .../stats/base/varianceyc/lib/accessors.js | 94 +++++++++++++ .../stats/base/varianceyc/lib/index.js | 4 +- .../stats/base/varianceyc/lib/ndarray.js | 27 +++- .../stats/base/varianceyc/lib/varianceyc.js | 42 ++---- .../base/varianceyc/test/test.ndarray.js | 124 +++++++++++++++-- .../base/varianceyc/test/test.varianceyc.js | 131 ++++++++++++++++-- 13 files changed, 429 insertions(+), 139 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md index aa2f84f74d2f..2241d6a17dfc 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md @@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var varianceyc = require( '@stdlib/stats/base/varianceyc' ); ``` -#### varianceyc( N, correction, x, stride ) +#### varianceyc( N, correction, x, strideX ) Computes the [variance][variance] of a strided array `x` using a one-pass algorithm proposed by Youngs and Cramer. @@ -114,17 +114,16 @@ 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 = varianceyc( N, 1, x, 2 ); +var v = varianceyc( 4, 1, x, 2 ); // returns 6.25 ``` @@ -139,13 +138,11 @@ 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 = varianceyc( N, 1, x1, 2 ); +var v = varianceyc( 4, 1, x1, 2 ); // returns 6.25 ``` -#### varianceyc.ndarray( N, correction, x, stride, offset ) +#### varianceyc.ndarray( N, correction, x, strideX, offsetX ) Computes the [variance][variance] of a strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. @@ -158,17 +155,14 @@ var v = varianceyc.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 value in `x` starting from the second value ```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 = varianceyc.ndarray( N, 1, x, 2, 1 ); +var v = varianceyc.ndarray( 4, 1, x, 2, 1 ); // returns 6.25 ``` @@ -183,6 +177,7 @@ var v = varianceyc.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`. - Depending on the environment, the typed versions ([`dvarianceyc`][@stdlib/stats/base/dvarianceyc], [`svarianceyc`][@stdlib/stats/base/svarianceyc], etc.) are likely to be significantly more performant. +- 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]). @@ -195,18 +190,13 @@ var v = varianceyc.ndarray( N, 1, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var uniform = require( '@stdlib/random/array/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); var varianceyc = require( '@stdlib/stats/base/varianceyc' ); -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 = uniform( 10, -50.0, 50.0, { + 'dtype': 'float64' +}); console.log( x ); var v = varianceyc( x.length, 1, x, 1 ); @@ -256,6 +246,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 + [@stdlib/stats/base/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svarianceyc [@youngs:1971a]: https://doi.org/10.1080/00401706.1971.10488826 diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js index c07e4bfca71e..64a74e906749 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js @@ -21,13 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var uniform = require( '@stdlib/random/array/uniform' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; var varianceyc = require( './../lib/varianceyc.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var varianceyc = require( './../lib/varianceyc.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.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js index 3f404dbf88e5..a338cc0a19d9 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/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 varianceyc = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var varianceyc = 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.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt index 6b92bcf4f75c..e95fe789ed40 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, correction, x, stride ) +{{alias}}( N, correction, x, strideX ) Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. - 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,8 +31,8 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -46,27 +46,24 @@ > {{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 using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a + buffer, the offset parameter supports indexing semantics based on a starting index. Parameters @@ -89,10 +86,10 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -109,8 +106,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/varianceyc/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts index 51da248e2f8d..3248ca80217a 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts @@ -20,7 +20,14 @@ /// -import { NumericArray } from '@stdlib/types/array'; +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + + +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; + /** * Interface describing `varianceyc`. @@ -32,7 +39,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 for `x` * @returns variance * * @example @@ -41,7 +48,7 @@ interface Routine { * var v = varianceyc( x.length, 1, x, 1 ); * // returns ~4.3333 */ - ( N: number, correction: number, x: NumericArray, stride: number ): number; + ( N: number, correction: number, x: InputArray, stride: number ): number; /** * Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. @@ -49,8 +56,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 for `x` + * @param offsetX - starting index * @returns variance * * @example @@ -59,7 +66,7 @@ interface Routine { * var v = varianceyc.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; } /** @@ -68,7 +75,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/varianceyc/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts index e93995ba93eb..67017ee24cb0 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts @@ -16,6 +16,7 @@ * limitations under the License. */ +import AccessorArray = require( '@stdlib/array/base/accessor' ); import varianceyc = require( './index' ); @@ -26,6 +27,7 @@ import varianceyc = require( './index' ); const x = new Float64Array( 10 ); varianceyc( x.length, 1, x, 1 ); // $ExpectType number + varianceyc( 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 varianceyc = require( './index' ); const x = new Float64Array( 10 ); varianceyc.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number + varianceyc.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/varianceyc/examples/index.js b/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js index 965b058878dd..1f207d645c69 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js @@ -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 uniform = require( '@stdlib/random/array/uniform' ); var varianceyc = 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 = uniform( 10, -50.0, 50.0, { + 'dtype': 'float64' +}); console.log( x ); var v = varianceyc( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js new file mode 100644 index 000000000000..e44f9af6522d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js @@ -0,0 +1,94 @@ +/** +* @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'; + +// MAIN // + +/** +* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +* +* ## Method +* +* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). +* +* ## References +* +* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). +* +* @private +* @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} strideX - stride length for `x` +* @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 v = varianceyc( x.length, 1, arraylike2object( x ), 1, 0 ); +* // returns ~4.3333 +*/ +function varianceyc( N, correction, x, strideX, offsetX ) { + var xbuf; + var xget; + var sum; + var ix; + var S; + var v; + var d; + var n; + var i; + + n = N - correction; + if ( N <= 0 || n <= 0.0 ) { + return NaN; + } + if ( N === 1 || strideX === 0 ) { + return 0.0; + } + + // Cache references to array data: + xbuf = x.data; + + // Cache references to element accessors: + xget = x.accessors[ 0 ]; + + sum = xget( xbuf, offsetX ); + ix = offsetX + strideX; + S = 0.0; + for ( i = 2; i <= N; i++ ) { + v = xget( xbuf, ix ); + sum += v; + d = (i*v) - sum; + S += (1.0/(i*(i-1))) * d * d; + ix += strideX; + } + return S / n; +} + + +// EXPORTS // + +module.exports = varianceyc; diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js index e90497e57e78..7067ffdefbb3 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js @@ -33,13 +33,11 @@ * // returns ~4.3333 * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var varianceyc = require( '@stdlib/stats/base/varianceyc' ); * * 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 = varianceyc.ndarray( N, 1, x, 2, 1 ); +* var v = varianceyc.ndarray( 4, 1, x, 2, 1 ); * // returns 6.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js index da23fbd21f16..4b4251935b4e 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + // MAIN // /** @@ -34,8 +40,8 @@ * @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 for `x` +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * * @example @@ -47,7 +53,7 @@ * var v = varianceyc( N, 1, x, 2, 1 ); * // returns 6.25 */ -function varianceyc( N, correction, x, stride, offset ) { +function varianceyc( N, correction, x, strideX, offsetX ) { var sum; var ix; var S; @@ -55,23 +61,30 @@ function varianceyc( N, correction, x, stride, offset ) { var d; var n; var i; + var o; n = N - correction; if ( N <= 0 || n <= 0.0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { + if ( N === 1 || strideX === 0 ) { return 0.0; } - sum = x[ offset ]; - ix = offset + stride; + + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, correction, o, strideX, offsetX ); + } + + sum = x[ offsetX ]; + ix = offsetX + strideX; S = 0.0; for ( i = 2; i <= N; i++ ) { v = x[ ix ]; sum += v; d = (i*v) - sum; S += (1.0/(i*(i-1))) * d * d; - ix += stride; + ix += strideX; } return S / n; } diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/varianceyc.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/varianceyc.js index 6d76e638e816..11b29c27bc88 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/varianceyc.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/varianceyc.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + // MAIN // /** @@ -34,7 +40,7 @@ * @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 {integer} strideX - stride length for `x` * @returns {number} variance * * @example @@ -43,38 +49,8 @@ * var v = varianceyc( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function varianceyc( N, correction, x, stride ) { - var sum; - var ix; - var S; - var v; - 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; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - sum = x[ ix ]; - ix += stride; - S = 0.0; - for ( i = 2; i <= N; i++ ) { - v = x[ ix ]; - sum += v; - d = (i*v) - sum; - S += (1.0/(i*(i-1))) * d * d; - ix += stride; - } - return S / n; +function varianceyc( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js index d479be840e45..1f443fccb51f 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js @@ -21,7 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var varianceyc = require( './../lib/ndarray.js' ); @@ -58,6 +58,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 = varianceyc( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( 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 +96,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 = varianceyc( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 1, toAccessorArray( x ), 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( 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; @@ -120,7 +158,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; @@ -135,15 +172,34 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = varianceyc( N, 1, x, 2, 0 ); + v = varianceyc( 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 x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = varianceyc( 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; @@ -158,8 +214,28 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = varianceyc( N, 1, x, -2, 6 ); + v = varianceyc( 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 x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = varianceyc( 4, 1, toAccessorArray( x ), -2, 6 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -177,8 +253,19 @@ 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 = varianceyc( 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; var v; @@ -192,10 +279,27 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]; - N = floor( x.length / 2 ); - v = varianceyc( N, 1, x, 2, 1 ); + v = varianceyc( 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 x; + var v; + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + v = varianceyc( 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/varianceyc/test/test.varianceyc.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js index 4ff7dd76fcf8..7745bb5fc2ab 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js @@ -21,7 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var varianceyc = require( './../lib/varianceyc.js' ); @@ -59,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 = varianceyc( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/x.length, 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 0, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( 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 +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 = varianceyc( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = varianceyc( x.length, 1, toAccessorArray( x ), 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = varianceyc( 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; @@ -121,7 +159,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; @@ -136,15 +173,34 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = varianceyc( N, 1, x, 2 ); + v = varianceyc( 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 x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = varianceyc( 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; @@ -159,8 +215,28 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = varianceyc( N, 1, x, -2 ); + v = varianceyc( 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 x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = varianceyc( 4, 1, toAccessorArray( x ), -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -178,10 +254,21 @@ 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 = varianceyc( 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; - var N; var v; x0 = new Float64Array([ @@ -197,9 +284,33 @@ 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 = varianceyc( N, 1, x1, 2 ); + v = varianceyc( 4, 1, x1, 2 ); + t.strictEqual( v, 6.25, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (accessor)', function test( t ) { + var x0; + var x1; + 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 + + v = varianceyc( 4, 1, toAccessorArray( x1 ), 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From eaf388a4db52dffda98b20d162205ece048bad39 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta Date: Sat, 8 Mar 2025 16:34:48 -0500 Subject: [PATCH 02/18] fixup! feat: add protocol support to stats/base/varianceyc --- 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/varianceyc/test/test.ndarray.js | 42 +++++++++++++++++++ .../base/varianceyc/test/test.varianceyc.js | 42 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js index 1f443fccb51f..3b3cef63ce3c 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js @@ -130,6 +130,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 = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + + v = varianceyc( 0, 1, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( -1, 1, 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; @@ -142,6 +157,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 = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + + v = varianceyc( 1, 0, 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; @@ -157,6 +184,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 = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + + v = varianceyc( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( x.length, x.length+1, 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; diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js index 7745bb5fc2ab..ef9f06dc4561 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js @@ -131,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 = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + + v = varianceyc( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( -1, 1, 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; @@ -143,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 = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + + v = varianceyc( 1, 0, 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; @@ -158,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 = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + + v = varianceyc( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = varianceyc( x.length, x.length+1, 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 37729ad103569e5f2a211aed1f3d17aed51b90a0 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta Date: Sat, 8 Mar 2025 17:06:52 -0500 Subject: [PATCH 03/18] fixup! fixup! feat: add protocol support to stats/base/varianceyc --- 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/varianceyc/test/test.ndarray.js | 43 ++++++++++++++++++- .../base/varianceyc/test/test.varianceyc.js | 43 ++++++++++++++++++- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js index 3b3cef63ce3c..0bbef6a46ca4 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js @@ -142,6 +142,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu v = varianceyc( -1, 1, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); + x = toAccessorArray([ 10.0 ]); + v = varianceyc( 0, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value when N = 0 with a single value' ); + t.end(); }); @@ -166,6 +170,10 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat v = varianceyc( 1, 0, x, 1, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); + x = toAccessorArray([ 5.0 ]); + v = varianceyc( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value with a single value' ); + t.end(); }); @@ -191,10 +199,14 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or x = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); v = varianceyc( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnan( v ), true, 'returns expected value when n = 0' ); v = varianceyc( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnan( v ), true, 'returns expected value when n < 0' ); + + x = toAccessorArray([ 7.0, 8.0, 9.0 ]); + v = varianceyc( x.length, x.length, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns expected value when n = 0 with different data' ); t.end(); }); @@ -304,6 +316,10 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` ( v = varianceyc( x.length, 1, toAccessorArray( x ), 0, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); + x = toAccessorArray([ 10.0 ]); + v = varianceyc( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value with a single value' ); + t.end(); }); @@ -345,3 +361,26 @@ tape( 'the function supports an `offset` parameter (accessor)', function test( t t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); + +tape( 'the function handles specific accessor cases for coverage', function test( t ) { + var x; + var v; + + x = toAccessorArray([ 999.0 ]); + v = varianceyc( 1, 0, x, 1, 0 ); + t.strictEqual( v, 0.0, 'returns expected value for N === 1' ); + + x = toAccessorArray([ 999.0, 888.0, 777.0 ]); + v = varianceyc( x.length, 1, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value for strideX === 0' ); + + x = toAccessorArray([ 10.0, 20.0, 30.0 ]); + v = varianceyc( 3, 3, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns NaN when n === 0' ); + + x = toAccessorArray([ 1.0 ]); + v = varianceyc( 0, 0, x, 1, 0 ); + t.strictEqual( isnan( v ), true, 'returns NaN when N === 0' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js index ef9f06dc4561..724356a49503 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js @@ -143,6 +143,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu v = varianceyc( -1, 1, x, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); + x = toAccessorArray([ 10.0 ]); + v = varianceyc( 0, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value when N = 0 with a single value' ); + t.end(); }); @@ -167,6 +171,10 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat v = varianceyc( 1, 0, x, 1 ); t.strictEqual( v, 0.0, 'returns expected value' ); + x = toAccessorArray([ 5.0 ]); + v = varianceyc( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value with a single value' ); + t.end(); }); @@ -192,10 +200,14 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or x = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); v = varianceyc( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnan( v ), true, 'returns expected value when n = 0' ); v = varianceyc( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.strictEqual( isnan( v ), true, 'returns expected value when n < 0' ); + + x = toAccessorArray([ 7.0, 8.0, 9.0 ]); + v = varianceyc( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value when n = 0 with different data' ); t.end(); }); @@ -305,6 +317,10 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` ( v = varianceyc( x.length, 1, toAccessorArray( x ), 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); + x = toAccessorArray([ 10.0 ]); + v = varianceyc( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value with a single value' ); + t.end(); }); @@ -357,3 +373,26 @@ tape( 'the function supports view offsets (accessor)', function test( t ) { t.end(); }); + +tape( 'the function handles specific accessor cases for complete branch coverage', function test( t ) { + var x; + var v; + + x = toAccessorArray([ 999.0 ]); + v = varianceyc( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value for N === 1' ); + + x = toAccessorArray([ 999.0, 888.0, 777.0 ]); + v = varianceyc( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value for strideX === 0' ); + + x = toAccessorArray([ 10.0, 20.0, 30.0 ]); + v = varianceyc( 3, 3, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns NaN when n === 0' ); + + x = toAccessorArray([ 1.0 ]); + v = varianceyc( 0, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns NaN when N === 0' ); + + t.end(); +}); From 78f64b4fc8b0cd5065350be7bfcd4dde43b2813e Mon Sep 17 00:00:00 2001 From: Pulkit Gupta Date: Sat, 8 Mar 2025 17:09:49 -0500 Subject: [PATCH 04/18] fixup! fixup! fixup! feat: add protocol support to stats/base/varianceyc --- 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 --- --- .../@stdlib/stats/base/varianceyc/test/test.ndarray.js | 4 ---- .../@stdlib/stats/base/varianceyc/test/test.varianceyc.js | 4 ---- 2 files changed, 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js index 0bbef6a46ca4..99dae347f53e 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js @@ -316,10 +316,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` ( v = varianceyc( x.length, 1, toAccessorArray( x ), 0, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); - x = toAccessorArray([ 10.0 ]); - v = varianceyc( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value with a single value' ); - t.end(); }); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js index 724356a49503..79a432560964 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js @@ -317,10 +317,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` ( v = varianceyc( x.length, 1, toAccessorArray( x ), 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); - x = toAccessorArray([ 10.0 ]); - v = varianceyc( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value with a single value' ); - t.end(); }); From 0921de1b94b6ba25f8f440598aae399abba589d6 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta Date: Sat, 8 Mar 2025 17:16:04 -0500 Subject: [PATCH 05/18] fixup! fixup! fixup! fixup! feat: add protocol support to stats/base/varianceyc --- 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 --- --- .../@stdlib/stats/base/varianceyc/lib/ndarray.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js index 4b4251935b4e..f86e3c56828a 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js @@ -63,6 +63,11 @@ function varianceyc( N, correction, x, strideX, offsetX ) { var i; var o; + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, correction, o, strideX, offsetX ); + } + n = N - correction; if ( N <= 0 || n <= 0.0 ) { return NaN; @@ -71,11 +76,6 @@ function varianceyc( N, correction, x, strideX, offsetX ) { return 0.0; } - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - return accessors( N, correction, o, strideX, offsetX ); - } - sum = x[ offsetX ]; ix = offsetX + strideX; S = 0.0; From 2ed48eb1f6e6ffbda011ddc91012c56fcaa07387 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> Date: Thu, 20 Mar 2025 08:19:18 -0400 Subject: [PATCH 06/18] Update lib/node_modules/@stdlib/stats/base/varianceyc/README.md Co-authored-by: Athan Signed-off-by: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/varianceyc/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md index 2241d6a17dfc..87f695ebe5c6 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md @@ -116,7 +116,7 @@ The function has the following parameters: - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. - **strideX**: stride length for `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`, +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' ); From 26bf6f1c8a0b4a963c8fd68f7306d6e9ddafc820 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> Date: Thu, 20 Mar 2025 08:19:40 -0400 Subject: [PATCH 07/18] Update lib/node_modules/@stdlib/stats/base/varianceyc/README.md Co-authored-by: Athan Signed-off-by: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/varianceyc/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md index 87f695ebe5c6..57e6d2df7321 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md @@ -119,8 +119,6 @@ The function has the following parameters: 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 v = varianceyc( 4, 1, x, 2 ); From 833cd7675e2c3ec4846cfd2f8dbce84c0b95314d Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> Date: Thu, 20 Mar 2025 08:20:01 -0400 Subject: [PATCH 08/18] Update lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts Co-authored-by: Athan Signed-off-by: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> --- .../@stdlib/stats/base/varianceyc/docs/types/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts index 3248ca80217a..cdb75497c388 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts @@ -22,7 +22,6 @@ import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; - /** * Input array. */ From f36aff0c41dc6fcdb9495911493103e86ebdfcb4 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> Date: Thu, 20 Mar 2025 08:20:44 -0400 Subject: [PATCH 09/18] Update lib/node_modules/@stdlib/stats/base/varianceyc/README.md Co-authored-by: Athan Signed-off-by: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/varianceyc/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md index 57e6d2df7321..46a7774cc39b 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md @@ -193,7 +193,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var varianceyc = require( '@stdlib/stats/base/varianceyc' ); var x = uniform( 10, -50.0, 50.0, { - 'dtype': 'float64' + 'dtype': 'generic' }); console.log( x ); From 8e04ff4f40ec2b96ddbe151839cac5ed9602fa53 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> Date: Thu, 20 Mar 2025 08:20:55 -0400 Subject: [PATCH 10/18] Update lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js Co-authored-by: Athan Signed-off-by: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> --- .../@stdlib/stats/base/varianceyc/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js b/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js index 1f207d645c69..b3139abfc0a2 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js @@ -22,7 +22,7 @@ var uniform = require( '@stdlib/random/array/uniform' ); var varianceyc = require( './../lib' ); var x = uniform( 10, -50.0, 50.0, { - 'dtype': 'float64' + 'dtype': 'generic' }); console.log( x ); From 37d4cbd019b0f10df51774cb8f08dabffb5aaa02 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> Date: Thu, 20 Mar 2025 08:21:23 -0400 Subject: [PATCH 11/18] Update lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js Co-authored-by: Athan Signed-off-by: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> --- .../@stdlib/stats/base/varianceyc/test/test.ndarray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js index 99dae347f53e..21f2dbba5597 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js @@ -134,7 +134,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu var x; var v; - x = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = varianceyc( 0, 1, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); From 91bfbdd7cb6421bb211aa1ae1a4e9625aca831da Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> Date: Thu, 20 Mar 2025 08:21:33 -0400 Subject: [PATCH 12/18] Update lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js Co-authored-by: Athan Signed-off-by: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> --- .../@stdlib/stats/base/varianceyc/test/test.ndarray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js index 21f2dbba5597..ec8da043a757 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js @@ -142,7 +142,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu v = varianceyc( -1, 1, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = toAccessorArray([ 10.0 ]); + x = toAccessorArray( [ 10.0 ] ); v = varianceyc( 0, 0, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value when N = 0 with a single value' ); From cf804251d6e733ebc9cde0798a0568c223fff2d9 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta Date: Sun, 23 Mar 2025 16:37:01 -0400 Subject: [PATCH 13/18] fixup! refactor: updated 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: 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: 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/varianceyc/README.md | 1 - .../stats/base/varianceyc/docs/repl.txt | 6 +-- .../base/varianceyc/docs/types/index.d.ts | 5 +-- .../base/varianceyc/test/test.ndarray.js | 41 ++++------------- .../base/varianceyc/test/test.varianceyc.js | 45 +++++-------------- 5 files changed, 25 insertions(+), 73 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md index 46a7774cc39b..248edfcb38b0 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md @@ -131,7 +131,6 @@ 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 diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt index e95fe789ed40..0c0670cb41f8 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt @@ -32,7 +32,7 @@ Input array. strideX: integer - Stride length. + Stride length for `x`. Returns ------- @@ -87,10 +87,10 @@ Input array. strideX: integer - Stride length. + Stride length for `x`. offsetX: integer - Starting index. + Starting index for `x`. Returns ------- diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts index cdb75497c388..3d49901e740b 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts @@ -27,7 +27,6 @@ import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array */ type InputArray = NumericArray | Collection | AccessorArrayLike; - /** * Interface describing `varianceyc`. */ @@ -56,7 +55,7 @@ interface Routine { * @param correction - degrees of freedom adjustment * @param x - input array * @param strideX - stride length for `x` - * @param offsetX - starting index + * @param offsetX - starting index for `x` * @returns variance * * @example @@ -74,7 +73,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array -* @param strideX - stride length +* @param strideX - stride length for `x` * @returns variance * * @example diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js index ec8da043a757..d6ede53dda55 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js @@ -144,7 +144,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu x = toAccessorArray( [ 10.0 ] ); v = varianceyc( 0, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value when N = 0 with a single value' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -165,14 +165,14 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat var x; var v; - x = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = varianceyc( 1, 0, x, 1, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); - x = toAccessorArray([ 5.0 ]); + x = toAccessorArray( [ 5.0 ] ); v = varianceyc( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value with a single value' ); + t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); }); @@ -196,17 +196,17 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or var x; var v; - x = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = varianceyc( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value when n = 0' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); v = varianceyc( x.length, x.length+1, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value when n < 0' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = toAccessorArray([ 7.0, 8.0, 9.0 ]); + x = toAccessorArray( [ 7.0, 8.0, 9.0 ] ); v = varianceyc( x.length, x.length, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns expected value when n = 0 with different data' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -357,26 +357,3 @@ tape( 'the function supports an `offset` parameter (accessor)', function test( t t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); - -tape( 'the function handles specific accessor cases for coverage', function test( t ) { - var x; - var v; - - x = toAccessorArray([ 999.0 ]); - v = varianceyc( 1, 0, x, 1, 0 ); - t.strictEqual( v, 0.0, 'returns expected value for N === 1' ); - - x = toAccessorArray([ 999.0, 888.0, 777.0 ]); - v = varianceyc( x.length, 1, x, 0, 0 ); - t.strictEqual( v, 0.0, 'returns expected value for strideX === 0' ); - - x = toAccessorArray([ 10.0, 20.0, 30.0 ]); - v = varianceyc( 3, 3, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns NaN when n === 0' ); - - x = toAccessorArray([ 1.0 ]); - v = varianceyc( 0, 0, x, 1, 0 ); - t.strictEqual( isnan( v ), true, 'returns NaN when N === 0' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js index 79a432560964..ff543f703060 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js @@ -135,7 +135,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu var x; var v; - x = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = varianceyc( 0, 1, x, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -143,9 +143,9 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu v = varianceyc( -1, 1, x, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = toAccessorArray([ 10.0 ]); + x = toAccessorArray( [ 10.0 ] ); v = varianceyc( 0, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value when N = 0 with a single value' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -166,14 +166,14 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat var x; var v; - x = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = varianceyc( 1, 0, x, 1 ); t.strictEqual( v, 0.0, 'returns expected value' ); - x = toAccessorArray([ 5.0 ]); + x = toAccessorArray( [ 5.0 ] ); v = varianceyc( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value with a single value' ); + t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); }); @@ -197,17 +197,17 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or var x; var v; - x = toAccessorArray([ 1.0, -2.0, -4.0, 5.0, 3.0 ]); + x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = varianceyc( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value when n = 0' ); + t.strictEqual( isnan( v ), true, 'returns expected' ); v = varianceyc( x.length, x.length+1, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value when n < 0' ); + t.strictEqual( isnan( v ), true, 'returns expected' ); - x = toAccessorArray([ 7.0, 8.0, 9.0 ]); + x = toAccessorArray( [ 7.0, 8.0, 9.0 ] ); v = varianceyc( x.length, x.length, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns expected value when n = 0 with different data' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); @@ -369,26 +369,3 @@ tape( 'the function supports view offsets (accessor)', function test( t ) { t.end(); }); - -tape( 'the function handles specific accessor cases for complete branch coverage', function test( t ) { - var x; - var v; - - x = toAccessorArray([ 999.0 ]); - v = varianceyc( 1, 0, x, 1 ); - t.strictEqual( v, 0.0, 'returns expected value for N === 1' ); - - x = toAccessorArray([ 999.0, 888.0, 777.0 ]); - v = varianceyc( x.length, 1, x, 0 ); - t.strictEqual( v, 0.0, 'returns expected value for strideX === 0' ); - - x = toAccessorArray([ 10.0, 20.0, 30.0 ]); - v = varianceyc( 3, 3, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns NaN when n === 0' ); - - x = toAccessorArray([ 1.0 ]); - v = varianceyc( 0, 0, x, 1 ); - t.strictEqual( isnan( v ), true, 'returns NaN when N === 0' ); - - t.end(); -}); From d55df5e0a588ff3e7abbf2c6ee9500b924b7fc6c Mon Sep 17 00:00:00 2001 From: Pulkit Gupta Date: Sun, 23 Mar 2025 17:02:42 -0400 Subject: [PATCH 14/18] fixup! refactor: updated accessor implemntation to avoid duplication --- 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 --- --- .../@stdlib/stats/base/varianceyc/lib/accessors.js | 10 ++-------- .../@stdlib/stats/base/varianceyc/lib/ndarray.js | 10 +++++----- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js index e44f9af6522d..f088f9ebe84e 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js @@ -45,10 +45,10 @@ * 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( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); * * var v = varianceyc( x.length, 1, arraylike2object( x ), 1, 0 ); -* // returns ~4.3333 +* // returns 10.7 */ function varianceyc( N, correction, x, strideX, offsetX ) { var xbuf; @@ -62,12 +62,6 @@ function varianceyc( N, correction, x, strideX, offsetX ) { var i; n = N - correction; - if ( N <= 0 || n <= 0.0 ) { - return NaN; - } - if ( N === 1 || strideX === 0 ) { - return 0.0; - } // Cache references to array data: xbuf = x.data; diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js index f86e3c56828a..4b4251935b4e 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js @@ -63,11 +63,6 @@ function varianceyc( N, correction, x, strideX, offsetX ) { var i; var o; - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - return accessors( N, correction, o, strideX, offsetX ); - } - n = N - correction; if ( N <= 0 || n <= 0.0 ) { return NaN; @@ -76,6 +71,11 @@ function varianceyc( N, correction, x, strideX, offsetX ) { return 0.0; } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, correction, o, strideX, offsetX ); + } + sum = x[ offsetX ]; ix = offsetX + strideX; S = 0.0; From 81fc3ba02b0a6582558d27855040f248ae683378 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> Date: Mon, 31 Mar 2025 16:56:26 -0400 Subject: [PATCH 15/18] refac: formatting changes Signed-off-by: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/varianceyc/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md index 0e64eeaaf566..015944e9fa41 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md @@ -173,11 +173,9 @@ var v = varianceyc.ndarray( 4, 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`. - - Depending on the environment, the typed versions ([`dvarianceyc`][@stdlib/stats/strided/dvarianceyc], [`svarianceyc`][@stdlib/stats/strided/svarianceyc], etc.) are likely to be significantly more performant. - 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]). - From e61999a9fb13219a1061610b0e603c6836b952f8 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> Date: Mon, 31 Mar 2025 16:59:47 -0400 Subject: [PATCH 16/18] refac: formatting changes Signed-off-by: Pulkit Gupta <65711278+pulkitgupta2@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/varianceyc/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md index 015944e9fa41..98b985f71a4b 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md @@ -244,7 +244,7 @@ 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 - + [@stdlib/stats/strided/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/svarianceyc [@youngs:1971a]: https://doi.org/10.1080/00401706.1971.10488826 From 6153de390a6776dea248e3dfde66158621a67a2d Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 10 Apr 2025 00:58:32 -0700 Subject: [PATCH 17/18] chore: clean-up --- 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 --- --- .../@stdlib/stats/base/varianceyc/README.md | 17 ++- .../base/varianceyc/benchmark/benchmark.js | 4 +- .../varianceyc/benchmark/benchmark.ndarray.js | 2 +- .../stats/base/varianceyc/docs/repl.txt | 10 +- .../base/varianceyc/docs/types/index.d.ts | 12 +- .../stats/base/varianceyc/docs/types/test.ts | 134 +++++++++--------- .../stats/base/varianceyc/examples/index.js | 2 +- .../stats/base/varianceyc/lib/accessors.js | 8 +- .../stats/base/varianceyc/lib/index.js | 12 +- .../@stdlib/stats/base/varianceyc/lib/main.js | 30 +++- .../stats/base/varianceyc/lib/ndarray.js | 7 +- .../stats/base/varianceyc/lib/varianceyc.js | 59 -------- .../test/{test.varianceyc.js => test.main.js} | 58 ++++---- .../base/varianceyc/test/test.ndarray.js | 56 ++++---- 14 files changed, 189 insertions(+), 222 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/varianceyc/lib/varianceyc.js rename lib/node_modules/@stdlib/stats/base/varianceyc/test/{test.varianceyc.js => test.main.js} (85%) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md index 98b985f71a4b..a05b606f4f10 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/README.md +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/README.md @@ -100,12 +100,12 @@ var varianceyc = require( '@stdlib/stats/base/varianceyc' ); #### varianceyc( N, correction, x, strideX ) -Computes the [variance][variance] of a strided array `x` using a one-pass algorithm proposed by Youngs and Cramer. +Computes the [variance][variance] of a strided array using a one-pass algorithm proposed by Youngs and Cramer. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var v = varianceyc( x.length, 1, x, 1 ); +var v = varianceyc( x.length, 1.0, x, 1 ); // returns ~4.3333 ``` @@ -121,7 +121,7 @@ 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 ]; -var v = varianceyc( 4, 1, x, 2 ); +var v = varianceyc( 4, 1.0, x, 2 ); // returns 6.25 ``` @@ -135,7 +135,7 @@ 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 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var v = varianceyc( 4, 1, x1, 2 ); +var v = varianceyc( 4, 1.0, x1, 2 ); // returns 6.25 ``` @@ -146,7 +146,7 @@ Computes the [variance][variance] of a strided array using a one-pass algorithm ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var v = varianceyc.ndarray( x.length, 1, x, 1, 0 ); +var v = varianceyc.ndarray( x.length, 1.0, x, 1, 0 ); // returns ~4.33333 ``` @@ -154,12 +154,12 @@ The function has the following additional parameters: - **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 x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -var v = varianceyc.ndarray( 4, 1, x, 2, 1 ); +var v = varianceyc.ndarray( 4, 1.0, x, 2, 1 ); // returns 6.25 ``` @@ -188,7 +188,6 @@ var v = varianceyc.ndarray( 4, 1, x, 2, 1 ); ```javascript var uniform = require( '@stdlib/random/array/uniform' ); -var Float64Array = require( '@stdlib/array/float64' ); var varianceyc = require( '@stdlib/stats/base/varianceyc' ); var x = uniform( 10, -50.0, 50.0, { @@ -196,7 +195,7 @@ var x = uniform( 10, -50.0, 50.0, { }); console.log( x ); -var v = varianceyc( x.length, 1, x, 1 ); +var v = varianceyc( x.length, 1.0, x, 1 ); console.log( v ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js index 64a74e906749..4cf64da5f3d4 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.js @@ -25,7 +25,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var uniform = require( '@stdlib/random/array/uniform' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; -var varianceyc = require( './../lib/varianceyc.js' ); +var varianceyc = require( './../lib' ); // VARIABLES // @@ -54,7 +54,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = varianceyc( x.length, 1, x, 1 ); + v = varianceyc( x.length, 1.0, x, 1 ); if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js index a338cc0a19d9..c760ff42df7f 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/benchmark/benchmark.ndarray.js @@ -54,7 +54,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = varianceyc( x.length, 1, x, 1, 0 ); + v = varianceyc( x.length, 1.0, x, 1, 0 ); if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt index 0c0670cb41f8..2511d4ec7df5 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt @@ -43,18 +43,18 @@ -------- // Standard Usage: > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}( x.length, 1, x, 1 ) + > {{alias}}( x.length, 1.0, x, 1 ) ~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 ) + > {{alias}}( 3, 1.0, 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 ); - > {{alias}}( 3, 1, x1, 2 ) + > {{alias}}( 3, 1.0, x1, 2 ) ~4.3333 @@ -101,12 +101,12 @@ -------- // Standard Usage: > var x = [ 1.0, -2.0, 2.0 ]; - > {{alias}}.ndarray( x.length, 1, x, 1, 0 ) + > {{alias}}.ndarray( x.length, 1.0, x, 1, 0 ) ~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 ) + > {{alias}}.ndarray( 3, 1.0, x, 2, 1 ) ~4.3333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts index 3d49901e740b..de3b1949ee4b 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/index.d.ts @@ -43,10 +43,10 @@ interface Routine { * @example * var x = [ 1.0, -2.0, 2.0 ]; * - * var v = varianceyc( x.length, 1, x, 1 ); + * var v = varianceyc( x.length, 1.0, x, 1 ); * // returns ~4.3333 */ - ( N: number, correction: number, x: InputArray, stride: number ): number; + ( N: number, correction: number, x: InputArray, strideX: number ): number; /** * Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics. @@ -61,10 +61,10 @@ interface Routine { * @example * var x = [ 1.0, -2.0, 2.0 ]; * - * var v = varianceyc.ndarray( x.length, 1, x, 1, 0 ); + * var v = varianceyc.ndarray( x.length, 1.0, 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; } /** @@ -79,13 +79,13 @@ interface Routine { * @example * var x = [ 1.0, -2.0, 2.0 ]; * -* var v = varianceyc( x.length, 1, x, 1 ); +* var v = varianceyc( x.length, 1.0, x, 1 ); * // returns ~4.3333 * * @example * var x = [ 1.0, -2.0, 2.0 ]; * -* var v = varianceyc.ndarray( x.length, 1, x, 1, 0 ); +* var v = varianceyc.ndarray( x.length, 1.0, x, 1, 0 ); * // returns ~4.3333 */ declare var varianceyc: Routine; diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts index 67017ee24cb0..cae7d268af9d 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/test.ts @@ -26,22 +26,22 @@ import varianceyc = require( './index' ); { const x = new Float64Array( 10 ); - varianceyc( x.length, 1, x, 1 ); // $ExpectType number - varianceyc( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number + varianceyc( x.length, 1.0, x, 1 ); // $ExpectType number + varianceyc( x.length, 1.0, new AccessorArray( x ), 1 ); // $ExpectType number } // The compiler throws an error if the function is provided a first argument which is not a number... { const x = new Float64Array( 10 ); - varianceyc( '10', 1, x, 1 ); // $ExpectError - varianceyc( true, 1, x, 1 ); // $ExpectError - varianceyc( false, 1, x, 1 ); // $ExpectError - varianceyc( null, 1, x, 1 ); // $ExpectError - varianceyc( undefined, 1, x, 1 ); // $ExpectError - varianceyc( [], 1, x, 1 ); // $ExpectError - varianceyc( {}, 1, x, 1 ); // $ExpectError - varianceyc( ( x: number ): number => x, 1, x, 1 ); // $ExpectError + varianceyc( '10', 1.0, x, 1 ); // $ExpectError + varianceyc( true, 1.0, x, 1 ); // $ExpectError + varianceyc( false, 1.0, x, 1 ); // $ExpectError + varianceyc( null, 1.0, x, 1 ); // $ExpectError + varianceyc( undefined, 1.0, x, 1 ); // $ExpectError + varianceyc( [], 1.0, x, 1 ); // $ExpectError + varianceyc( {}, 1.0, x, 1 ); // $ExpectError + varianceyc( ( x: number ): number => x, 1.0, x, 1 ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not a number... @@ -62,29 +62,29 @@ import varianceyc = require( './index' ); { const x = new Float64Array( 10 ); - varianceyc( x.length, 1, 10, 1 ); // $ExpectError - varianceyc( x.length, 1, '10', 1 ); // $ExpectError - varianceyc( x.length, 1, true, 1 ); // $ExpectError - varianceyc( x.length, 1, false, 1 ); // $ExpectError - varianceyc( x.length, 1, null, 1 ); // $ExpectError - varianceyc( x.length, 1, undefined, 1 ); // $ExpectError - varianceyc( x.length, 1, [ '1' ], 1 ); // $ExpectError - varianceyc( x.length, 1, {}, 1 ); // $ExpectError - varianceyc( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError + varianceyc( x.length, 1.0, 10, 1 ); // $ExpectError + varianceyc( x.length, 1.0, '10', 1 ); // $ExpectError + varianceyc( x.length, 1.0, true, 1 ); // $ExpectError + varianceyc( x.length, 1.0, false, 1 ); // $ExpectError + varianceyc( x.length, 1.0, null, 1 ); // $ExpectError + varianceyc( x.length, 1.0, undefined, 1 ); // $ExpectError + varianceyc( x.length, 1.0, [ '1' ], 1 ); // $ExpectError + varianceyc( x.length, 1.0, {}, 1 ); // $ExpectError + varianceyc( x.length, 1.0, ( x: number ): number => x, 1 ); // $ExpectError } // The compiler throws an error if the function is provided a fourth argument which is not a number... { const x = new Float64Array( 10 ); - varianceyc( x.length, 1, x, '10' ); // $ExpectError - varianceyc( x.length, 1, x, true ); // $ExpectError - varianceyc( x.length, 1, x, false ); // $ExpectError - varianceyc( x.length, 1, x, null ); // $ExpectError - varianceyc( x.length, 1, x, undefined ); // $ExpectError - varianceyc( x.length, 1, x, [] ); // $ExpectError - varianceyc( x.length, 1, x, {} ); // $ExpectError - varianceyc( x.length, 1, x, ( x: number ): number => x ); // $ExpectError + varianceyc( x.length, 1.0, x, '10' ); // $ExpectError + varianceyc( x.length, 1.0, x, true ); // $ExpectError + varianceyc( x.length, 1.0, x, false ); // $ExpectError + varianceyc( x.length, 1.0, x, null ); // $ExpectError + varianceyc( x.length, 1.0, x, undefined ); // $ExpectError + varianceyc( x.length, 1.0, x, [] ); // $ExpectError + varianceyc( x.length, 1.0, x, {} ); // $ExpectError + varianceyc( x.length, 1.0, x, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... @@ -93,9 +93,9 @@ import varianceyc = require( './index' ); varianceyc(); // $ExpectError varianceyc( x.length ); // $ExpectError - varianceyc( x.length, 1 ); // $ExpectError - varianceyc( x.length, 1, x ); // $ExpectError - varianceyc( x.length, 1, x, 1, 10 ); // $ExpectError + varianceyc( x.length, 1.0 ); // $ExpectError + varianceyc( x.length, 1.0, x ); // $ExpectError + varianceyc( x.length, 1.0, x, 1, 10 ); // $ExpectError } // Attached to main export is an `ndarray` method which returns a number... @@ -110,14 +110,14 @@ import varianceyc = require( './index' ); { const x = new Float64Array( 10 ); - varianceyc.ndarray( '10', 1, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( true, 1, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( false, 1, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( null, 1, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( [], 1, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( {}, 1, x, 1, 0 ); // $ExpectError - varianceyc.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( '10', 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( true, 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( false, 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( null, 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( undefined, 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( [], 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( {}, 1.0, x, 1, 0 ); // $ExpectError + varianceyc.ndarray( ( x: number ): number => x, 1.0, x, 1, 0 ); // $ExpectError } // The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... @@ -138,43 +138,43 @@ import varianceyc = require( './index' ); { const x = new Float64Array( 10 ); - varianceyc.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, [ '1' ], 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, 10, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, '10', 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, true, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, false, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, null, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, undefined, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, [ '1' ], 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, {}, 1, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, ( x: number ): number => x, 1, 0 ); // $ExpectError } // The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... { const x = new Float64Array( 10 ); - varianceyc.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, true, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, false, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, null, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, [], 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, '10', 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, true, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, false, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, null, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, undefined, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, [], 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, {}, 0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, ( x: number ): number => x, 0 ); // $ExpectError } // The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... { const x = new Float64Array( 10 ); - varianceyc.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, 1, true ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, 1, false ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, 1, null ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, 1, [] ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, 1, {} ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, '10' ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, true ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, false ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, null ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, undefined ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, [] ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, {} ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... @@ -183,8 +183,8 @@ import varianceyc = require( './index' ); varianceyc.ndarray(); // $ExpectError varianceyc.ndarray( x.length ); // $ExpectError - varianceyc.ndarray( x.length, 1 ); // $ExpectError - varianceyc.ndarray( x.length, 1, x ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, 1 ); // $ExpectError - varianceyc.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1 ); // $ExpectError + varianceyc.ndarray( x.length, 1.0, x, 1, 0, 10 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js b/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js index b3139abfc0a2..d659f7f2aa7f 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js @@ -26,5 +26,5 @@ var x = uniform( 10, -50.0, 50.0, { }); console.log( x ); -var v = varianceyc( x.length, 1, x, 1 ); +var v = varianceyc( x.length, 1.0, x, 1 ); console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js index f088f9ebe84e..0406525482d6 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/accessors.js @@ -37,7 +37,7 @@ * @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 for `x` +* @param {integer} strideX - stride length * @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * @@ -47,7 +47,7 @@ * * var x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); * -* var v = varianceyc( x.length, 1, arraylike2object( x ), 1, 0 ); +* var v = varianceyc( x.length, 1.0, arraylike2object( x ), 1, 0 ); * // returns 10.7 */ function varianceyc( N, correction, x, strideX, offsetX ) { @@ -63,10 +63,10 @@ function varianceyc( N, correction, x, strideX, offsetX ) { n = N - correction; - // Cache references to array data: + // Cache a reference to array data: xbuf = x.data; - // Cache references to element accessors: + // Cache a reference to an element accessor: xget = x.accessors[ 0 ]; sum = xget( xbuf, offsetX ); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js index 7067ffdefbb3..51c01687fbb2 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/index.js @@ -27,9 +27,8 @@ * var varianceyc = require( '@stdlib/stats/base/varianceyc' ); * * var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; * -* var v = varianceyc( N, 1, x, 1 ); +* var v = varianceyc( 3, 1.0, x, 1 ); * // returns ~4.3333 * * @example @@ -37,13 +36,20 @@ * * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; * -* var v = varianceyc.ndarray( 4, 1, x, 2, 1 ); +* var v = varianceyc.ndarray( 4, 1.0, 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/varianceyc/lib/main.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/main.js index 5a6b2f4f75cf..4dfe7440899e 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/main.js @@ -20,14 +20,38 @@ // MODULES // -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var varianceyc = require( './varianceyc.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); var ndarray = require( './ndarray.js' ); // MAIN // -setReadOnly( varianceyc, 'ndarray', ndarray ); +/** +* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer. +* +* ## Method +* +* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). +* +* ## References +* +* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). +* +* @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, 2.0 ]; +* +* var v = varianceyc( x.length, 1.0, x, 1 ); +* // returns ~4.3333 +*/ +function varianceyc( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +} // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js index 4b4251935b4e..11c3f0cfa0e5 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/ndarray.js @@ -40,17 +40,14 @@ var accessors = require( './accessors.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {NumericArray} x - input array -* @param {integer} strideX - stride length for `x` +* @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 ]; -* var N = floor( x.length / 2 ); * -* var v = varianceyc( N, 1, x, 2, 1 ); +* var v = varianceyc( 4, 1.0, x, 2, 1 ); * // returns 6.25 */ function varianceyc( N, correction, x, strideX, offsetX ) { diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/varianceyc.js b/lib/node_modules/@stdlib/stats/base/varianceyc/lib/varianceyc.js deleted file mode 100644 index 11b29c27bc88..000000000000 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/lib/varianceyc.js +++ /dev/null @@ -1,59 +0,0 @@ -/** -* @license Apache-2.0 -* -* 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. -* 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 one-pass algorithm proposed by Youngs and Cramer. -* -* ## Method -* -* - This implementation uses a one-pass algorithm, as proposed by Youngs and Cramer (1971). -* -* ## References -* -* - Youngs, Edward A., and Elliot M. Cramer. 1971. "Some Results Relevant to Choice of Sum and Sum-of-Product Algorithms." _Technometrics_ 13 (3): 657–65. doi:[10.1080/00401706.1971.10488826](https://doi.org/10.1080/00401706.1971.10488826). -* -* @param {PositiveInteger} N - number of indexed elements -* @param {number} correction - degrees of freedom adjustment -* @param {NumericArray} x - input array -* @param {integer} strideX - stride length for `x` -* @returns {number} variance -* -* @example -* var x = [ 1.0, -2.0, 2.0 ]; -* -* var v = varianceyc( x.length, 1, x, 1 ); -* // returns ~4.3333 -*/ -function varianceyc( N, correction, x, strideX ) { - return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); -} - - -// EXPORTS // - -module.exports = varianceyc; diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.js similarity index 85% rename from lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js rename to lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.js index ff543f703060..3272798a5a45 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.varianceyc.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.js @@ -24,7 +24,7 @@ var tape = require( 'tape' ); var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); -var varianceyc = require( './../lib/varianceyc.js' ); +var varianceyc = require( './../lib' ); // TESTS // @@ -45,15 +45,15 @@ tape( 'the function calculates the population variance of a strided array', func var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 0, x, 1 ); + v = varianceyc( x.length, 0.0, x, 1 ); t.strictEqual( v, 53.5/x.length, 'returns expected value' ); x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 0, x, 1 ); + v = varianceyc( x.length, 0.0, x, 1 ); t.strictEqual( v, 0.0, 'returns expected value' ); x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 0, x, 1 ); + v = varianceyc( x.length, 0.0, x, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -64,15 +64,15 @@ tape( 'the function calculates the population variance of a strided array (acces var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 0, toAccessorArray( x ), 1 ); + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1 ); t.strictEqual( v, 53.5/x.length, 'returns expected value' ); x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 0, toAccessorArray( x ), 1 ); + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1 ); t.strictEqual( v, 0.0, 'returns expected value' ); x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 0, toAccessorArray( x ), 1 ); + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -83,15 +83,15 @@ tape( 'the function calculates the sample variance of a strided array', function var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 1, x, 1 ); + v = varianceyc( x.length, 1.0, x, 1 ); t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 1, x, 1 ); + v = varianceyc( x.length, 1.0, x, 1 ); t.strictEqual( v, 0.0, 'returns expected value' ); x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 1, x, 1 ); + v = varianceyc( x.length, 1.0, x, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -102,15 +102,15 @@ tape( 'the function calculates the sample variance of a strided array (accessor) var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 1, toAccessorArray( x ), 1 ); + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1 ); t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 1, toAccessorArray( x ), 1 ); + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1 ); t.strictEqual( v, 0.0, 'returns expected value' ); x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 1, toAccessorArray( x ), 1 ); + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -122,10 +122,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - v = varianceyc( 0, 1, x, 1 ); + v = varianceyc( 0, 1.0, x, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - v = varianceyc( -1, 1, x, 1 ); + v = varianceyc( -1, 1.0, x, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -137,14 +137,14 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - v = varianceyc( 0, 1, x, 1 ); + v = varianceyc( 0, 1.0, x, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - v = varianceyc( -1, 1, x, 1 ); + v = varianceyc( -1, 1.0, x, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = toAccessorArray( [ 10.0 ] ); - v = varianceyc( 0, 0, x, 1 ); + v = varianceyc( 0, 0.0, x, 1 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -156,7 +156,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - v = varianceyc( 1, 0, x, 1 ); + v = varianceyc( 1, 0.0, x, 1 ); t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); @@ -168,11 +168,11 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - v = varianceyc( 1, 0, x, 1 ); + v = varianceyc( 1, 0.0, x, 1 ); t.strictEqual( v, 0.0, 'returns expected value' ); x = toAccessorArray( [ 5.0 ] ); - v = varianceyc( 1, 0, x, 1 ); + v = varianceyc( 1, 0.0, x, 1 ); t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); @@ -227,7 +227,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - v = varianceyc( 4, 1, x, 2 ); + v = varianceyc( 4, 1.0, x, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -248,7 +248,7 @@ tape( 'the function supports a `stride` parameter (accessor)', function test( t 2.0 ]; - v = varianceyc( 4, 1, toAccessorArray( x ), 2 ); + v = varianceyc( 4, 1.0, toAccessorArray( x ), 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -269,7 +269,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - v = varianceyc( 4, 1, x, -2 ); + v = varianceyc( 4, 1.0, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -290,7 +290,7 @@ tape( 'the function supports a negative `stride` parameter (accessor)', function 2.0 ]; - v = varianceyc( 4, 1, toAccessorArray( x ), -2 ); + v = varianceyc( 4, 1.0, toAccessorArray( x ), -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -302,7 +302,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - v = varianceyc( x.length, 1, x, 0 ); + v = varianceyc( x.length, 1.0, x, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); @@ -314,7 +314,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` ( x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - v = varianceyc( x.length, 1, toAccessorArray( x ), 0 ); + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); @@ -339,7 +339,7 @@ tape( 'the function supports view offsets', function test( t ) { x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - v = varianceyc( 4, 1, x1, 2 ); + v = varianceyc( 4, 1.0, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -364,7 +364,7 @@ tape( 'the function supports view offsets (accessor)', function test( t ) { x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - v = varianceyc( 4, 1, toAccessorArray( x1 ), 2 ); + v = varianceyc( 4, 1.0, toAccessorArray( x1 ), 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js index d6ede53dda55..65440b321483 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarray.js @@ -44,15 +44,15 @@ tape( 'the function calculates the population variance of a strided array', func var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 0, x, 1, 0 ); + v = varianceyc( x.length, 0.0, x, 1, 0 ); t.strictEqual( v, 53.5/x.length, 'returns expected value' ); x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 0, x, 1, 0 ); + v = varianceyc( x.length, 0.0, x, 1, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 0, x, 1, 0 ); + v = varianceyc( x.length, 0.0, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -63,15 +63,15 @@ tape( 'the function calculates the population variance of a strided array (acces var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 0, toAccessorArray( x ), 1, 0 ); + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1, 0 ); t.strictEqual( v, 53.5/x.length, 'returns expected value' ); x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 0, toAccessorArray( x ), 1, 0 ); + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 0, toAccessorArray( x ), 1, 0 ); + v = varianceyc( x.length, 0.0, toAccessorArray( x ), 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -82,15 +82,15 @@ tape( 'the function calculates the sample variance of a strided array', function var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 1, x, 1, 0 ); + v = varianceyc( x.length, 1.0, x, 1, 0 ); t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 1, x, 1, 0 ); + v = varianceyc( x.length, 1.0, x, 1, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 1, x, 1, 0 ); + v = varianceyc( x.length, 1.0, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -101,15 +101,15 @@ tape( 'the function calculates the sample variance of a strided array (accessor) var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = varianceyc( x.length, 1, toAccessorArray( x ), 1, 0 ); + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1, 0 ); t.strictEqual( v, 53.5/(x.length-1), 'returns expected value' ); x = [ -4.0, -4.0 ]; - v = varianceyc( x.length, 1, toAccessorArray( x ), 1, 0 ); + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); x = [ NaN, 4.0 ]; - v = varianceyc( x.length, 1, toAccessorArray( x ), 1, 0 ); + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -121,10 +121,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - v = varianceyc( 0, 1, x, 1, 0 ); + v = varianceyc( 0, 1.0, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - v = varianceyc( -1, 1, x, 1, 0 ); + v = varianceyc( -1, 1.0, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -136,14 +136,14 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - v = varianceyc( 0, 1, x, 1, 0 ); + v = varianceyc( 0, 1.0, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - v = varianceyc( -1, 1, x, 1, 0 ); + v = varianceyc( -1, 1.0, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = toAccessorArray( [ 10.0 ] ); - v = varianceyc( 0, 0, x, 1, 0 ); + v = varianceyc( 0, 0.0, x, 1, 0 ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -155,7 +155,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - v = varianceyc( 1, 0, x, 1, 0 ); + v = varianceyc( 1, 0.0, x, 1, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); @@ -167,11 +167,11 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); - v = varianceyc( 1, 0, x, 1, 0 ); + v = varianceyc( 1, 0.0, x, 1, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); x = toAccessorArray( [ 5.0 ] ); - v = varianceyc( 1, 0, x, 1, 0 ); + v = varianceyc( 1, 0.0, x, 1, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); @@ -226,7 +226,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - v = varianceyc( 4, 1, x, 2, 0 ); + v = varianceyc( 4, 1.0, x, 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -247,7 +247,7 @@ tape( 'the function supports a `stride` parameter (accessor)', function test( t 2.0 ]; - v = varianceyc( 4, 1, toAccessorArray( x ), 2, 0 ); + v = varianceyc( 4, 1.0, toAccessorArray( x ), 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -268,7 +268,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - v = varianceyc( 4, 1, x, -2, 6 ); + v = varianceyc( 4, 1.0, x, -2, 6 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -289,7 +289,7 @@ tape( 'the function supports a negative `stride` parameter (accessor)', function 2.0 ]; - v = varianceyc( 4, 1, toAccessorArray( x ), -2, 6 ); + v = varianceyc( 4, 1.0, toAccessorArray( x ), -2, 6 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -301,7 +301,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - v = varianceyc( x.length, 1, x, 0, 0 ); + v = varianceyc( x.length, 1.0, x, 0, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); @@ -313,7 +313,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` ( x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - v = varianceyc( x.length, 1, toAccessorArray( x ), 0, 0 ); + v = varianceyc( x.length, 1.0, toAccessorArray( x ), 0, 0 ); t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); @@ -334,7 +334,7 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 4.0 // 3 ]; - v = varianceyc( 4, 1, x, 2, 1 ); + v = varianceyc( 4, 1.0, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -353,7 +353,7 @@ tape( 'the function supports an `offset` parameter (accessor)', function test( t 3.0, 4.0 // 3 ]; - v = varianceyc( 4, 1, toAccessorArray( x ), 2, 1 ); + v = varianceyc( 4, 1.0, toAccessorArray( x ), 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); From dac959503f1adbac35e00029a7174a35406f7899 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Thu, 10 Apr 2025 08:04:34 +0000 Subject: [PATCH 18/18] chore: update copyright years --- .../@stdlib/stats/base/varianceyc/test/test.main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.js b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.js index 3272798a5a45..f3335f77fef8 100644 --- a/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/base/varianceyc/test/test.main.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.