diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/README.md new file mode 100644 index 000000000000..7e501b40895c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/README.md @@ -0,0 +1,127 @@ + + +# snanvariance + +> Compute the sample variance of a one-dimensional single-precision floating-point ndarray, ignoring `NaN` values. + +
+ +The **sample variance** of a set of values is defined as + +```math +\sigma^2 = \frac{1}{n - c} \sum_{i=0}^{n-1} (x_i - \bar{x})^2 +``` + +
+ + + +
+ +## Usage + +```javascript +var snanvariance = require( '@stdlib/stats/base/ndarray/snanvariance' ); +``` + +#### snanvariance( arrays, correction ) + +Computes the sample variance of a one-dimensional single-precision floating-point ndarray, ignoring `NaN` values. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float32Array( [ 1.0, 2.0, NaN, 3.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var v = snanvariance( [ x ], 1 ); +// returns 1.0 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing a one-dimensional input ndarray. +- **correction**: degrees of freedom adjustment. + +
+ + + +
+ +## Notes + +- If provided an empty one-dimensional ndarray, the function returns `NaN`. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var snanvariance = require( '@stdlib/stats/base/ndarray/snanvariance' ); + +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + +var xbuf = filledarrayBy( 10, 'float32', rand ); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + +console.log( ndarray2array( x ) ); + +var v = snanvariance( [ x ], 1 ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/benchmark/benchmark.js new file mode 100644 index 000000000000..3fe3c0aa8cdc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/benchmark/benchmark.js @@ -0,0 +1,117 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var snanvariance = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a random number. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var x; + + xbuf = filledarrayBy( len, 'float32', rand ); + x = new ndarray( 'float32', xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = snanvariance( [ x ], 1 ); + } + b.toc(); + + // NaN is allowed for variance: + if ( isnanf( v ) ) { + b.pass( 'returned NaN (allowed)' ); + } else { + b.pass( 'returned a number' ); + } + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/img/equation_arithmetic_mean.svg b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/img/equation_arithmetic_mean.svg new file mode 100644 index 000000000000..c31439606fb6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/img/equation_arithmetic_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/repl.txt new file mode 100644 index 000000000000..3197d8281e1a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}( arrays, correction ) + Computes the sample variance of a one-dimensional ndarray, ignoring `NaN` + values. + + If the number of non-NaN elements minus the correction is less than or equal + to zero, the function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + correction: number + Degrees of freedom adjustment. + + Returns + ------- + out: number + Sample variance. + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, NaN, 3.0 ] ); + > var dt = 'float32'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > {{alias}}( [ x ], 1 ) + 1 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/types/index.d.ts new file mode 100644 index 000000000000..28576608364e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/types/index.d.ts @@ -0,0 +1,50 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { float32ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the sample variance of a one-dimensional ndarray, ignoring `NaN` values. +* +* @param arrays - array-like object containing an input ndarray +* @param correction - degrees of freedom adjustment +* @returns sample variance +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float32Array( [ 1.0, 2.0, NaN, 3.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = snanvariance( [ x ], 1 ); +* // returns 1.0 +*/ +declare function snanvariance( + arrays: [ float32ndarray ], + correction: number +): number; + + +// EXPORTS // + +export = snanvariance; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/types/test.ts new file mode 100644 index 000000000000..a83def5a9e1c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/docs/types/test.ts @@ -0,0 +1,60 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import snanvariance = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + + snanvariance( [ x ], 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + snanvariance( '10', 1 ); // $ExpectError + snanvariance( 10, 1 ); // $ExpectError + snanvariance( true, 1 ); // $ExpectError + snanvariance( false, 1 ); // $ExpectError + snanvariance( null, 1 ); // $ExpectError + snanvariance( undefined, 1 ); // $ExpectError + snanvariance( [], 1 ); // $ExpectError + snanvariance( {}, 1 ); // $ExpectError + snanvariance( ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid correction argument... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + + snanvariance( [ x ] ); // $ExpectError + snanvariance( [ x ], '1' ); // $ExpectError + snanvariance( [ x ], {} ); // $ExpectError + snanvariance( [ x ], null ); // $ExpectError + snanvariance( [ x ], undefined ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/examples/index.js new file mode 100644 index 000000000000..f179e88b8aaf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var snanvariance = require( './../lib' ); + +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + +var xbuf = filledarrayBy( 10, 'float32', rand ); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + +console.log( 'Input ndarray:' ); +console.log( ndarray2array( x ) ); + +// Compute sample variance (correction = 1): +var v = snanvariance( [ x ], 1 ); +console.log( 'Sample variance (ignoring NaNs):', v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/lib/index.js new file mode 100644 index 000000000000..2331d97db392 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/lib/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Compute the sample variance of a one-dimensional single-precision floating-point ndarray, ignoring `NaN` values. +* +* @module @stdlib/stats/base/ndarray/snanvariance +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var snanvariance = require( '@stdlib/stats/base/ndarray/snanvariance' ); +* +* var xbuf = new Float32Array( [ 1.0, 2.0, NaN, 3.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = snanvariance( [ x ], 1 ); +* // returns 1.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/lib/main.js new file mode 100644 index 000000000000..162163207d46 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/lib/main.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Computes the sample variance of a one-dimensional single-precision floating-point ndarray, ignoring `NaN` values. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray +* @param {number} correction - degrees of freedom adjustment +* @returns {number} sample variance +*/ +function snanvariance( arrays, correction ) { + var stride; + var offset; + var sumsq; + var count; + var data; + var mean; + var ix; + var x; + var N; + var i; + var v; + + x = arrays[ 0 ]; + + N = numelDimension( x, 0 ); + data = getData( x ); + stride = getStride( x, 0 ); + offset = getOffset( x ); + + mean = 0.0; + sumsq = 0.0; + count = 0; + + // First pass: compute mean of non-NaN values: + ix = offset; + for ( i = 0; i < N; i++ ) { + v = data[ ix ]; + if ( !isnan( v ) ) { + mean += v; + count += 1; + } + ix += stride; + } + + if ( count - correction <= 0 ) { + return NaN; + } + + mean /= count; + + // Second pass: compute squared deviations: + ix = offset; + for ( i = 0; i < N; i++ ) { + v = data[ ix ]; + if ( !isnan( v ) ) { + v -= mean; + sumsq += v * v; + } + ix += stride; + } + + return sumsq / ( count - correction ); +} + + +// EXPORTS // + +module.exports = snanvariance; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/package.json new file mode 100644 index 000000000000..05f6d75884a4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/stats/base/ndarray/snanvariance", + "version": "0.0.0", + "description": "Compute the sample variance of a one-dimensional ndarray, ignoring `NaN` values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "variance", + "sample variance", + "dispersion", + "spread", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/test/test.js new file mode 100644 index 000000000000..a3a8f5b5f9cc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/snanvariance/test/test.js @@ -0,0 +1,162 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 tape = require( 'tape' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var snanvariance = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float32', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof snanvariance, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 2', function test( t ) { + t.strictEqual( snanvariance.length, 2, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the sample variance of a one-dimensional ndarray', function test( t ) { + var x; + var v; + + // [1, 2, 3] → variance = 1 + x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); + v = snanvariance( [ vector( x, 3, 1, 0 ) ], 1 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + // [-4, -5] → variance = 0.5 + x = new Float32Array( [ -4.0, -5.0 ] ); + v = snanvariance( [ vector( x, 2, 1, 0 ) ], 1 ); + t.strictEqual( v, 0.5, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function ignores NaN values', function test( t ) { + var x; + var v; + + // [1, NaN, 2, 3] → [1,2,3] + x = new Float32Array( [ 1.0, NaN, 2.0, 3.0 ] ); + v = snanvariance( [ vector( x, 4, 1, 0 ) ], 1 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns NaN if insufficient non-NaN values are available', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 2.0 ] ); + v = snanvariance( [ vector( x, 1, 1, 0 ) ], 1 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + x = new Float32Array( [ NaN, NaN ] ); + v = snanvariance( [ vector( x, 2, 1, 0 ) ], 1 ); + t.strictEqual( isnanf( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays with non-unit strides', function test( t ) { + var x; + var v; + + // Values accessed: [1, 2, 3] + x = new Float32Array([ + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0, // 2 + 0.0 + ]); + + v = snanvariance( [ vector( x, 3, 2, 0 ) ], 1 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays with negative strides', function test( t ) { + var x; + var v; + + // Values accessed (reverse): [1,2,3] + x = new Float32Array([ + 3.0, // 2 + 0.0, + 2.0, // 1 + 0.0, + 1.0, // 0 + 0.0 + ]); + + v = snanvariance( [ vector( x, 3, -2, 4 ) ], 1 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays with non-zero offsets', function test( t ) { + var x; + var v; + + // Values accessed: [1,2,3] + x = new Float32Array([ + 0.0, + 1.0, // 0 + 0.0, + 2.0, // 1 + 0.0, + 3.0 // 2 + ]); + + v = snanvariance( [ vector( x, 3, 2, 1 ) ], 1 ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +});