diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/README.md b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/README.md new file mode 100644 index 000000000000..06b27f58d9d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/README.md @@ -0,0 +1,180 @@ + + +# incrnanmsumabs2 + +> Compute a moving sum of squared absolute values incrementally, ignoring NaN values. + +
+ +For a window of size `W`, the moving sum of squared absolute values is defined as + + + +```math +s = \sum_{\substack{i=0\\x_i \neq \mathrm{NaN}}}^{W-1} x_i^2 +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanmsumabs2 = require( '@stdlib/stats/incr/nanmsumabs2' ); +``` + +#### incrnanmsumabs2( window ) + +Returns an accumulator `function` which incrementally computes a moving sum of squared absolute values, ignoring `NaN` values. The `window` parameter defines the number of values over which to compute the moving sum. + +```javascript +var accumulator = incrnanmsumabs2( 3 ); +``` + +#### accumulator( \[x] ) + +If provided an input value `x`, the accumulator function returns an updated sum. If not provided an input value `x`, the accumulator function returns the current sum. + +```javascript +var accumulator = incrnanmsumabs2( 3 ); + +var sum = accumulator(); +// returns null + +// Fill the window... +sum = accumulator( 2.0 ); // [2.0] +// returns 4.0 + +sum = accumulator( -1.0 ); // [2.0, -1.0] +// returns 5.0 + +sum = accumulator( NaN ); // [2.0, -1.0] +// returns 5.0 + +sum = accumulator( 3.0 ); // [2.0, -1.0, 3.0] +// returns 14.0 + +// Window begins sliding... +sum = accumulator( -7.0 ); // [-1.0, 3.0, -7.0] +// returns 59.0 + +sum = accumulator( NaN ); // [3.0, -7.0] +// returns 59.0 + +sum = accumulator(); +// returns 59.0 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. +- `NaN` values are ignored. +- As `W` values (excluding `NaN` values) are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values (excluding `NaN` values). + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmsumabs2 = require( '@stdlib/stats/incr/nanmsumabs2' ); + +var accumulator; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmsumabs2( 5 ); + +// For each simulated datum, update the moving sum... +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = ( randu()*100.0 ) - 50.0; + } + accumulator( v ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/benchmark/benchmark.js new file mode 100644 index 000000000000..d319f7bf589c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/benchmark/benchmark.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var pkg = require( '@stdlib/stats/incr/nanmsumabs2/package.json' ).name; +var incrnanmsumabs2 = require( '@stdlib/stats/incr/nanmsumabs2/lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanmsumabs2( (i%5)+1 ); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof f !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::accumulator', function benchmark( b ) { + var acc; + var v; + var i; + + acc = incrnanmsumabs2( 5 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = acc( randu()-0.5 ); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( v !== v ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/img/equation_moving_sum_squared_absolute_values.svg b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/img/equation_moving_sum_squared_absolute_values.svg new file mode 100644 index 000000000000..a550903e807e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/img/equation_moving_sum_squared_absolute_values.svg @@ -0,0 +1,37 @@ + +s equals sigma-summation Underscript i equals 0 Overscript upper W minus 1 Endscripts x Subscript i Superscript 2 + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/repl.text b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/repl.text new file mode 100644 index 000000000000..f120e18f31b3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/repl.text @@ -0,0 +1,47 @@ +{{alias}}( W ) + Returns an accumulator function which incrementally computes a moving sum of + squared absolute values, ignoring NaN values. + + The `W` parameter defines the number of values over which to compute the + moving sum. + + If provided a value, the accumulator function returns an updated moving sum. + If not provided a value, the accumulator function returns the current moving + sum. + + As `W` values are needed to fill the window buffer, the first `W-1` returned + values are calculated from smaller sample sizes. Until the window is full, + each returned value is calculated from all provided values. + + NaN values are ignored. If the window consists solely of NaN values, the + function returns the current sum. + + Parameters + ---------- + W: integer + Window size. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}( 3 ); + > var s = accumulator() + null + > s = accumulator( 2.0 ) + 4.0 + > s = accumulator( -5.0 ) + 29.0 + > s = accumulator( NaN ) + 29.0 + > s = accumulator( 3.0 ) + 34.0 + > s = accumulator() + 34.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/types/index.d.ts new file mode 100644 index 000000000000..a73f4c634246 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/types/index.d.ts @@ -0,0 +1,74 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/// + +/** +* If provided a value, returns an updated sum of squared absolute values; otherwise, returns the current sum of squared absolute values. +* +* ## Notes +* +* - NaN values are ignored. +* +* @param x - value +* @returns sum of squared absolute values +*/ +type accumulator = ( x?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes a moving sum of squared absolute values, ignoring NaN values. +* +* ## Notes +* +* - The `W` parameter defines the number of values over which to compute the moving sum. +* - As `W` values are needed to fill the window buffer, the first `W-1` returned values are calculated from smaller sample sizes. Until the window is full, each returned value is calculated from all provided values. +* - NaN values are ignored. +* +* @param W - window size +* @throws must provide a positive integer +* @returns accumulator function +* +* @example +* var accumulator = incrnanmsumabs2( 3 ); +* +* var sum = accumulator(); +* // returns null +* +* sum = accumulator( 2.0 ); +* // returns 4.0 +* +* sum = accumulator( -5.0 ); +* // returns 29.0 +* +* sum = accumulator( NaN ); +* // returns 29.0 +* +* sum = accumulator( 3.0 ); +* // returns 34.0 +* +* sum = accumulator(); +* // returns 34.0 +*/ +declare function incrnanmsumabs2( W: number ): accumulator; + + +// EXPORTS // + +export = incrnanmsumabs2; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/types/test.ts new file mode 100644 index 000000000000..3116afbb680b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/docs/types/test.ts @@ -0,0 +1,60 @@ +/* +* @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. +*/ + +import incrnanmsumabs2 from './index'; + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanmsumabs2( 3 ); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided an argument that is not a number... +{ + incrnanmsumabs2( '5' ); // $ExpectError + incrnanmsumabs2( true ); // $ExpectError + incrnanmsumabs2( false ); // $ExpectError + incrnanmsumabs2( null ); // $ExpectError + incrnanmsumabs2( undefined ); // $ExpectError + incrnanmsumabs2( [] ); // $ExpectError + incrnanmsumabs2( {} ); // $ExpectError + incrnanmsumabs2( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanmsumabs2( 3 ); + + acc(); // $ExpectType number | null + acc( 3.14 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned function is provided invalid arguments... +{ + const acc = incrnanmsumabs2( 3 ); + + acc( '5' ); // $ExpectError + acc( true ); // $ExpectError + acc( false ); // $ExpectError + acc( null ); // $ExpectError + acc( [] ); // $ExpectError + acc( {} ); // $ExpectError + acc( ( x: number ): number => x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/examples/index.js new file mode 100644 index 000000000000..ebc3aa943da4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/examples/index.js @@ -0,0 +1,45 @@ +/** +* @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'; + +var randu = require( '@stdlib/random/base/randu' ); +var incrnanmsumabs2 = require( './../lib' ); + +var accumulator; +var sum; +var v; +var i; + +// Initialize an accumulator: +accumulator = incrnanmsumabs2( 5 ); + +// For each simulated datum, update the moving sum... + +console.log( '\nValue\tSum\n' ); + +for ( i = 0; i < 100; i++ ) { + if ( randu() < 0.2 ) { + v = NaN; + } else { + v = ( randu() * 100.0 ) - 50.0; + } + + sum = accumulator( v ); + console.log( '%s\t%s', v.toString(), (sum) ? sum.toFixed(3) : 'null' ); +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/lib/index.js new file mode 100644 index 000000000000..37a157db3e14 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/lib/index.js @@ -0,0 +1,58 @@ +/** +* @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'; + +/** +* Compute a moving sum of squared absolute values incrementally, ignoring NaN values. +* +* @module @stdlib/stats/incr/nanmsumabs2 +* +* @example +* var incrnanmsumabs2 = require( '@stdlib/stats/incr/nanmsumabs2' ); +* +* var accumulator = incrnanmsumabs2( 3 ); +* +* var sum = accumulator(); +* // returns null +* +* sum = accumulator( 2.0 ); +* // returns 4.0 +* +* sum = accumulator( -5.0 ); +* // returns 29.0 +* +* sum = accumulator( NaN ); +* // returns 29.0 +* +* sum = accumulator( 3.0 ); +* // returns 34.0 +* +* sum = accumulator(); +* // returns 34.0 +*/ + + +// MODULES // + +var incrnanmsumabs2 = require( './main.js' ); + + +// EXPORTS // + +module.exports = incrnanmsumabs2; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/lib/main.js new file mode 100644 index 000000000000..f5441ed15e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/lib/main.js @@ -0,0 +1,88 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var incrmsum = require( '@stdlib/stats/incr/msum' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes a moving sum of squared absolute values, ignoring NaN values. +* +* @param {PositiveInteger} W - window size +* @throws {TypeError} must provide a positive integer +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanmsumabs2( 3 ); +* +* var sum = accumulator(); +* // returns null +* +* sum = accumulator( 2.0 ); +* // returns 4.0 +* +* sum = accumulator( -5.0 ); +* // returns 29.0 +* +* sum = accumulator( NaN ); +* // returns 29.0 +* +* sum = accumulator( 3.0 ); +* // returns 38.0 +* +* sum = accumulator(); +* // returns 38.0 +*/ +function incrnanmsumabs2( W ) { + var sum; + if ( !isPositiveInteger( W ) ) { + throw new TypeError( format( 'invalid argument. Must provide a positive integer. Value: `%s`.', W ) ); + } + sum = incrmsum( W ); + return accumulator; + + /** + * If provided a value, the accumulator function returns an updated sum. If not provided a value, the accumulator function returns the current sum. + * + * @private + * @param {number} [x] - input value + * @returns {(number|null)} sum or null + */ + function accumulator( x ) { + if ( arguments.length === 0 ) { + return sum(); + } + if ( isnan( x ) ) { + return sum(); + } + return sum( x*x ); + } +} + + +// EXPORTS // + +module.exports = incrnanmsumabs2; diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/package.json b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/package.json new file mode 100644 index 000000000000..4d30728df79b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/package.json @@ -0,0 +1,77 @@ +{ + "name": "@stdlib/stats/incr/nanmsumabs2", + "version": "0.0.0", + "description": "Compute a moving sum of squared absolute values incrementally, 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", + "sum", + "total", + "incremental", + "accumulator", + "moving sum", + "sliding window", + "sliding", + "window", + "moving", + "rolling", + "absolute", + "value", + "abs", + "abs2", + "math.abs", + "magnitude", + "squared", + "nan" + ] +} diff --git a/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/test/test.js new file mode 100644 index 000000000000..79460f2efb0e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanmsumabs2/test/test.js @@ -0,0 +1,208 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var incrnanmsumabs2 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanmsumabs2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a positive integer', function test( t ) { + var values; + var i; + + values = [ + '5', + -5.0, + 0.0, + 3.14, + true, + null, + void 0, + NaN, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + incrnanmsumabs2( value ); + }; + } +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.equal( typeof incrnanmsumabs2( 3 ), 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the accumulator function computes a moving sum of squared absolute values incrementally', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, -3.0, 2.0, -4.0, 3.0, -4.0 ]; + N = data.length; + + acc = incrnanmsumabs2( 3 ); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + } + expected = [ 4.0, 13.0, 17.0, 29.0, 29.0, 41.0 ]; + + t.deepEqual( actual, expected, 'returns expected incremental results' ); + t.end(); +}); + +tape( 'the accumulator function correctly handles NaN values by ignoring them', function test( t ) { + var expected; + var actual; + var data; + var acc; + var N; + var i; + + data = [ 2.0, NaN, -3.0, NaN, 2.0, -4.0, 3.0, NaN, -4.0 ]; + N = data.length; + + acc = incrnanmsumabs2( 3 ); + + actual = []; + for ( i = 0; i < N; i++ ) { + actual.push( acc( data[ i ] ) ); + } + expected = [ 4.0, 4.0, 13.0, 13.0, 17.0, 29.0, 29.0, 29.0, 41.0 ]; + + t.deepEqual( actual, expected, 'returns expected incremental results when handling NaN values' ); + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current sum', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, -3.0, -5.0 ]; + acc = incrnanmsumabs2( 2 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 34.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if data has yet to be provided, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmsumabs2( 3 ); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); + +tape( 'if only provided `NaN` values, the accumulator function returns `null`', function test( t ) { + var acc = incrnanmsumabs2( 3 ); + acc( NaN ); + acc( NaN ); + acc( NaN ); + t.equal( acc(), null, 'returns null' ); + t.end(); +}); + +tape( 'the accumulator function does not include `NaN` values in the window size count', function test( t ) { + var data; + var acc; + var i; + + data = [ 2.0, -3.0, NaN, 5.0 ]; + acc = incrnanmsumabs2( 3 ); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ] ); + } + t.equal( acc(), 38.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function can handle a mixture of `NaN` and non-`NaN` values', function test( t ) { + var expected; + var actual; + var data; + var acc; + var i; + + data = [ + NaN, // null (no values) + 3.14, // 9.8596 + NaN, // still 9.8596 + 3.14, // 19.7192 + NaN, // still 19.7192 + NaN, // still 19.7192 + 3.14, // 29.5788 + 3.14, // 29.5788 (3.14, 3.14, 3.14) + NaN, // 29.5788 + 3.14 // 29.5788 (3.14, 3.14, 3.14) + ]; + + expected = [ + null, + 9.8596, + 9.8596, + 19.7192, + 19.7192, + 19.7192, + 29.5788, + 29.5788, + 29.5788, + 29.5788 + ]; + + acc = incrnanmsumabs2( 3 ); + + actual = []; + for ( i = 0; i < data.length; i++ ) { + actual.push( acc( data[ i ] ) ); + } + + for ( i = 0; i < expected.length; i++ ) { + if ( expected[i] === null ) { + t.equal( actual[i], null, 'returns expected value for index ' + i ); + } else { + t.equal( actual[i], expected[i], 'returns expected value for index ' + i ); + } + } + + t.end(); +});