From 7034bed734cbd4de7870c049bedc058e7698c652 Mon Sep 17 00:00:00 2001 From: Kanika Date: Wed, 4 Feb 2026 22:19:01 +0530 Subject: [PATCH 1/5] feat: added nanrss for nan handling --- 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: passed - 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/incr/nanrss/README.md | 154 ++++++++++++++++++ .../stats/incr/nanrss/benchmark/benchmark.js | 73 +++++++++ .../img/equation_residual_sum_of_squares.svg | 0 .../@stdlib/stats/incr/nanrss/docs/repl.txt | 31 ++++ .../stats/incr/nanrss/docs/types/index.d.ts | 63 +++++++ .../stats/incr/nanrss/docs/types/test.ts | 74 +++++++++ .../stats/incr/nanrss/examples/index.js | 42 +++++ .../@stdlib/stats/incr/nanrss/lib/index.js | 51 ++++++ .../@stdlib/stats/incr/nanrss/lib/main.js | 79 +++++++++ .../@stdlib/stats/incr/nanrss/package.json | 87 ++++++++++ .../@stdlib/stats/incr/nanrss/test/test.js | 139 ++++++++++++++++ 11 files changed, 793 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/README.md create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/docs/img/equation_residual_sum_of_squares.svg create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/package.json create mode 100644 lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/README.md b/lib/node_modules/@stdlib/stats/incr/nanrss/README.md new file mode 100644 index 000000000000..24f3c70b8081 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/README.md @@ -0,0 +1,154 @@ + + +# incrnanrss + +> Compute the [residual sum of squares][residual-sum-of-squares] (RSS) incrementally, ignoring `NaN` values. + +
+ +The [**residual sum of squares**][residual-sum-of-squares] (also referred to as the **sum of squared residuals** (SSR) and the **sum of squared errors** (SSE)) is defined as + + + +```math +\mathop{\mathrm{RSS}} = \sum_{i=0}^{n-1} (y_i - x_i)^2 +``` + + + + + +
+ + + +
+ +## Usage + +```javascript +var incrnanrss = require( '@stdlib/stats/incr/nanrss' ); +``` + +#### incrnanrss() + +Returns an accumulator `function` which incrementally computes the [residual sum of squares][residual-sum-of-squares], ignoring NaN values. + +```javascript +var accumulator = incrnanrss(); +``` + +#### accumulator( \[x, y] ) + +If provided input values x and y, the accumulator function updates the RSS. If NaN is provided, it is ignored, and the previous RSS is returned. If no arguments are provided, the accumulator function returns the current RSS. + +```javascript +var accumulator = incrnanrss(); + +var r = accumulator( 2.0, 3.0 ); +// returns 1.0 + +r = accumulator( -1.0, -4.0 ); +// returns 10.0 + +r = accumulator( -3.0, 5.0 ); +// returns 74.0 + +r = accumulator( NaN, 3.0 ); +// returns 74.0 + +r = accumulator(); +// returns 74.0 +``` + +
+ + + +
+ +## Notes + +- Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for **all** future invocations. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var incrnanrss = require( '@stdlib/stats/incr/nanrss' ); + +var accumulator; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanrss(); + +// For each simulated datum, update the residual sum of squares... +for ( i = 0; i < 100; i++ ) { + v1 = ( randu()*100.0 ) - 50.0; + v2 = ( randu()*100.0 ) - 50.0; + accumulator( v1, v2 ); + + // NaN values are ignored + accumulator( NaN, v2 ); +} +console.log( accumulator() ); +``` + +
+ + + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js new file mode 100644 index 000000000000..64a46bfdea4e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js @@ -0,0 +1,73 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var incrnanrss = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var f; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f = incrnanrss(); + 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 = incrnanrss(); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + if ( i%10 === 0 ) { + v = acc( NaN, randu()-0.5 ); + } else { + v = acc( randu()-0.5, 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/nanrss/docs/img/equation_residual_sum_of_squares.svg b/lib/node_modules/@stdlib/stats/incr/nanrss/docs/img/equation_residual_sum_of_squares.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/docs/repl.txt b/lib/node_modules/@stdlib/stats/incr/nanrss/docs/repl.txt new file mode 100644 index 000000000000..c29932edcd8b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/docs/repl.txt @@ -0,0 +1,31 @@ +{{alias}}() + Returns an accumulator function which incrementally computes the residual + sum of squares (RSS), ignoring `NaN` values. + + If provided input values, the accumulator function returns an updated + residual sum of squares. If not provided input values, the accumulator + function returns the current residual sum of squares. + + NaN input values are ignored. + + Returns + ------- + acc: Function + Accumulator function. + + Examples + -------- + > var accumulator = {{alias}}(); + > var r = accumulator() + null + > r = accumulator( 2.0, 3.0 ) + 1.0 + > r = accumulator( NaN, 3.0 ) + 1.0 + > r = accumulator( -5.0, 2.0 ) + 50.0 + > r = accumulator() + 50.0 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/incr/nanrss/docs/types/index.d.ts new file mode 100644 index 000000000000..8bcb2558d749 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/docs/types/index.d.ts @@ -0,0 +1,63 @@ +/* +* @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 + +/// + +/** +* If provided arguments, returns an updated residual sum of squares; otherwise, returns the current residual sum of squares. +* +* ## Notes +* +* NaN input values are ignored. +* @returns residual sum of squares +*/ +type accumulator = ( x?: number, y?: number ) => number | null; + +/** +* Returns an accumulator function which incrementally computes the residual sum of squares, ignoring `NaN` values. +* +* @returns accumulator function +* +* @example +* var accumulator = incrnanrss(); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 50.0 +* +* r = accumulator(); +* // returns 50.0 +* r = accumulator( NaN, 3.0 ); +* // 50.0 +* r = accumulator( 5.0, NaN ); +* // 50.0 +*/ +declare function incrnanrss(): accumulator; + + +// EXPORTS // + +export = incrnanrss; + diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/docs/types/test.ts b/lib/node_modules/@stdlib/stats/incr/nanrss/docs/types/test.ts new file mode 100644 index 000000000000..dc856bbcdbfa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/docs/types/test.ts @@ -0,0 +1,74 @@ +/* +* @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. +*/ + +import incrnanrss = require( './index' ); + + +// TESTS // + +// The function returns an accumulator function... +{ + incrnanrss(); // $ExpectType accumulator +} + +// The compiler throws an error if the function is provided arguments... +{ + incrnanrss( '5' ); // $ExpectError + incrnanrss( 5 ); // $ExpectError + incrnanrss( true ); // $ExpectError + incrnanrss( false ); // $ExpectError + incrnanrss( null ); // $ExpectError + incrnanrss( undefined ); // $ExpectError + incrnanrss( [] ); // $ExpectError + incrnanrss( {} ); // $ExpectError + incrnanrss( ( x: number ): number => x ); // $ExpectError +} + +// The function returns an accumulator function which returns an accumulated result... +{ + const acc = incrnanrss(); + + acc( 2.0, 3.0 ); // $ExpectType number | null + acc( NaN, 3.0 ); // ok + acc( 5.0, NaN ); // ok + + acc(); // $ExpectType number | null + acc( 3.14, 2.0 ); // $ExpectType number | null +} + +// The compiler throws an error if the returned accumulator function is provided invalid arguments... +{ + const acc = incrnanrss(); + + acc( '5', 1.0 ); // $ExpectError + acc( true, 1.0 ); // $ExpectError + acc( false, 1.0 ); // $ExpectError + acc( null, 1.0 ); // $ExpectError + acc( [], 1.0 ); // $ExpectError + acc( {}, 1.0 ); // $ExpectError + acc( ( x: number ): number => x, 1.0 ); // $ExpectError + + acc( 3.14, '5' ); // $ExpectError + acc( 3.14, true ); // $ExpectError + acc( 3.14, false ); // $ExpectError + acc( 3.14, null ); // $ExpectError + acc( 3.14, [] ); // $ExpectError + acc( 3.14, {} ); // $ExpectError + acc( 3.14, ( x: number ): number => x ); // $ExpectError +} + diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanrss/examples/index.js new file mode 100644 index 000000000000..c10aa662a5e6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/examples/index.js @@ -0,0 +1,42 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var incrnanrss = require( './../lib' ); + +var accumulator; +var nanrss; +var v1; +var v2; +var i; + +// Initialize an accumulator: +accumulator = incrnanrss(); + +// For each simulated datum, update the residual sum of squares... +console.log( '\nValue\tValue\tRSS\n' ); +for ( i = 0; i < 100; i++ ) { + v1 = ( randu()*100.0 ) - 50.0; + v2 = ( randu()*100.0 ) - 50.0; + nanrss = accumulator( v1, v2 ); + nanrss = accumulator( NaN, v2 );// NaN input values should be ignored + console.log( '%d\t%d\t%d', v1.toFixed( 3 ), v2.toFixed( 3 ), nanrss.toFixed( 3 ) ); +} +console.log( '\nFinal RSS: %d\n', accumulator() ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/lib/index.js b/lib/node_modules/@stdlib/stats/incr/nanrss/lib/index.js new file mode 100644 index 000000000000..b90363b2ad02 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/lib/index.js @@ -0,0 +1,51 @@ +/** +* @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 residual sum of squares incrementally, ignoring `NaN` values. +* +* @module @stdlib/stats/incr/nanrss +* +* @example +* var incrnanrss = require( '@stdlib/stats/incr/nanrss' ); +* +* var accumulator = incrnanrss(); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 50.0 +* +* r = accumulator(); +* // returns 50.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanrss/lib/main.js new file mode 100644 index 000000000000..9ddeb3d92e22 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/lib/main.js @@ -0,0 +1,79 @@ +/** +* @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 incrnansum = require( '@stdlib/stats/incr/nansum' ); + + +// MAIN // + +/** +* Returns an accumulator function which incrementally computes the residual sum of squares, ignoring `NaN` values. +* +* @returns {Function} accumulator function +* +* @example +* var accumulator = incrnanrss(); +* +* var r = accumulator(); +* // returns null +* +* r = accumulator( 2.0, 3.0 ); +* // returns 1.0 +* +* r = accumulator( -5.0, 2.0 ); +* // returns 50.0 +* +* r = accumulator(); +* // returns 50.0 +* +* r = accumulator( NaN, 3.0 ); +* // returns 50.0 +*/ +function incrnanrss() { + var nansum = incrnansum(); + return accumulator; + + /** + * If provided input values, the accumulator function returns an updated residual sum of squares. If not provided input values, the accumulator function returns the current residual sum of squares. + * + * @private + * @param {number} [x] - input value + * @param {number} [y] - input value + * @returns {(number|null)} residual sum of squares or null + */ + function accumulator( x, y ) { + var r; + if ( arguments.length === 0 ) { + return nansum(); + } + if ( x !== x || y !== y ) { + return nansum(); // ignore NaN values + } + r = y - x; + return nansum( r*r ); + } +} + + +// EXPORTS // + +module.exports = incrnanrss; diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/package.json b/lib/node_modules/@stdlib/stats/incr/nanrss/package.json new file mode 100644 index 000000000000..9f62e1a76a6d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/package.json @@ -0,0 +1,87 @@ +{ + "name": "@stdlib/stats/incr/rss", + "version": "0.0.0", + "description": "Compute the residual sum of squares (RSS) incrementally.", + "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", + "error", + "err", + "rss", + "ssr", + "sse", + "residuals", + "deviation", + "difference", + "diff", + "delta", + "incremental", + "accumulator", + "time series", + "timeseries", + "forecasting", + "forecast", + "model", + "selection", + "evaluation", + "prediction", + "manhattan", + "cityblock", + "city-block", + "distance", + "dist", + "nanrss", + "ignorenan" + ] +} + diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js new file mode 100644 index 000000000000..df81b9779aee --- /dev/null +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js @@ -0,0 +1,139 @@ +/** +* @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 abs = require( '@stdlib/math/base/special/abs' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var incrnanrss = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof incrnanrss, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an accumulator function', function test( t ) { + t.strictEqual( typeof incrnanrss(), 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the initial accumulated value is `null`', function test( t ) { + var acc = incrnanrss(); + t.strictEqual( acc(), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the accumulator function incrementally computes the residual sum of squares', function test( t ) { + var expected; + var actual; + var delta; + var data; + var acc; + var sum; + var tol; + var N; + var r; + var x; + var y; + var i; + + data = [ + [ 2.0, 3.0 ], + [ 3.0, -1.0 ], + [ 2.0, 5.0 ], + [ 4.0, -4.0 ], + [ 3.0, 0.0 ], + [ -4.0, 5.0 ] + ]; + N = data.length; + + acc = incrnanrss(); + + sum = 0; + for ( i = 0; i < N; i++ ) { + x = data[ i ][ 0 ]; + y = data[ i ][ 1 ]; + r = y - x; + sum += r * r; + expected = sum; + actual = acc( x, y ); + if ( actual === expected ) { + t.strictEqual( actual, expected, 'returns expected value' ); + } else { + delta = abs( expected - actual ); + tol = 1.0 * EPS * abs( expected ); + t.strictEqual( delta <= tol, true, 'within tolerance. Actual: '+actual+'. Expected: '+expected+'. Delta: '+delta+'. Tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'if not provided an input value, the accumulator function returns the current residual sum of squares', function test( t ) { + var expected; + var actual; + var delta; + var data; + var acc; + var tol; + var i; + + data = [ + [ 2.0, 3.0 ], + [ 3.0, -5.0 ], + [ 1.0, 10.0 ] + ]; + acc = incrnanrss(); + for ( i = 0; i < data.length; i++ ) { + acc( data[ i ][ 0 ], data[ i ][ 1 ] ); + } + actual = acc(); + expected = 1.0 + 64.0 + 81.0; + delta = abs( expected - actual ); + tol = 1.0 * EPS * abs( expected ); + t.strictEqual( delta <= tol, true, 'within tolerance. Actual: '+actual+'. Expected: '+expected+'. Delta: '+delta+'. Tol: '+tol+'.' ); + t.end(); +}); + +tape( 'NaN inputs are ignored', function test( t ) { + var acc = incrnanrss(); + + acc( 2.0, 3.0 ); + acc( NaN, 3.0 ); + acc( 3.0, NaN ); + + t.strictEqual( acc(), 1.0, 'returns expected value' ); + t.end(); +}); + +tape( 'handles NaN values', function test( t ) { + var acc = incrnanrss(); + + acc( 1.0, 2.0 ); // 1 + acc( NaN, NaN ); // ignored + acc( 2.0, 4.0 ); // +4 + + t.strictEqual( acc(), 5.0, 'returns expected value' ); + t.end(); +}); From 8839c7809691150ef2bcef19429cee2e1c3a4fa4 Mon Sep 17 00:00:00 2001 From: Kanika Date: Tue, 17 Feb 2026 17:16:41 +0530 Subject: [PATCH 2/5] feat: added required changes --- 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: passed - task: lint_repl_help status: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanrss/benchmark/benchmark.js | 4 ++-- lib/node_modules/@stdlib/stats/incr/nanrss/examples/index.js | 4 ++-- lib/node_modules/@stdlib/stats/incr/nanrss/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/incr/nanrss/package.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js index 64a46bfdea4e..3a6e0ce8837d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js @@ -56,9 +56,9 @@ bench( pkg+'::accumulator', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { if ( i%10 === 0 ) { - v = acc( NaN, randu()-0.5 ); + v = acc( NaN, randu() -0.5 ); } else { - v = acc( randu()-0.5, randu()-0.5 ); + v = acc( randu() -0.5, randu() -0.5 ); } if ( v !== v ) { b.fail( 'should not return NaN' ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/examples/index.js b/lib/node_modules/@stdlib/stats/incr/nanrss/examples/index.js index c10aa662a5e6..7db9cb1e460d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrss/examples/index.js +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/examples/index.js @@ -33,8 +33,8 @@ accumulator = incrnanrss(); // For each simulated datum, update the residual sum of squares... console.log( '\nValue\tValue\tRSS\n' ); for ( i = 0; i < 100; i++ ) { - v1 = ( randu()*100.0 ) - 50.0; - v2 = ( randu()*100.0 ) - 50.0; + v1 = ( randu() * 100.0 ) - 50.0; + v2 = ( randu() * 100.0 ) - 50.0; nanrss = accumulator( v1, v2 ); nanrss = accumulator( NaN, v2 );// NaN input values should be ignored console.log( '%d\t%d\t%d', v1.toFixed( 3 ), v2.toFixed( 3 ), nanrss.toFixed( 3 ) ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/lib/main.js b/lib/node_modules/@stdlib/stats/incr/nanrss/lib/main.js index 9ddeb3d92e22..37548e9a0fc7 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrss/lib/main.js +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/lib/main.js @@ -69,7 +69,7 @@ function incrnanrss() { return nansum(); // ignore NaN values } r = y - x; - return nansum( r*r ); + return nansum( r * r ); } } diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/package.json b/lib/node_modules/@stdlib/stats/incr/nanrss/package.json index 9f62e1a76a6d..8ba2bc97cc0d 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrss/package.json +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/stats/incr/rss", + "name": "@stdlib/stats/incr/nanrss", "version": "0.0.0", "description": "Compute the residual sum of squares (RSS) incrementally.", "license": "Apache-2.0", From c0a7a293714230e0b710b2531e5cfa0c94d63fd2 Mon Sep 17 00:00:00 2001 From: Kanika Date: Tue, 17 Feb 2026 17:20:13 +0530 Subject: [PATCH 3/5] feat: added changes --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanrss/benchmark/benchmark.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js index 3a6e0ce8837d..de1f7fe8f940 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var randu = require( '@stdlib/random/base/randu' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var incrnanrss = require( './../lib' ); @@ -46,7 +47,7 @@ bench( pkg, function benchmark( b ) { b.end(); }); -bench( pkg+'::accumulator', function benchmark( b ) { +bench( format( '%s::accumulator', pkg ), function benchmark( b ) { var acc; var v; var i; From 889b964a55af2f0f13a4627f706256dba23830a9 Mon Sep 17 00:00:00 2001 From: Kanika Date: Sat, 21 Feb 2026 17:47:29 +0530 Subject: [PATCH 4/5] feat: added some changes --- 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: 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: na - task: lint_license_headers status: passed --- --- .../stats/incr/nanrss/benchmark/benchmark.js | 2 +- .../@stdlib/stats/incr/nanrss/test/test.js | 21 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js index de1f7fe8f940..e3f78e369710 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/benchmark/benchmark.js @@ -56,7 +56,7 @@ bench( format( '%s::accumulator', pkg ), function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - if ( i%10 === 0 ) { + if ( i % 10 === 0 ) { v = acc( NaN, randu() -0.5 ); } else { v = acc( randu() -0.5, randu() -0.5 ); diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js index df81b9779aee..3c488c8c0a48 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js @@ -21,8 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var abs = require( '@stdlib/math/base/special/abs' ); -var EPS = require( '@stdlib/constants/float64/eps' ); +var ulpdiff = require( '@stdlib/number/float64/base/ulp-difference' ); var incrnanrss = require( './../lib' ); @@ -47,17 +46,16 @@ tape( 'the initial accumulated value is `null`', function test( t ) { tape( 'the accumulator function incrementally computes the residual sum of squares', function test( t ) { var expected; + var ulpDiff; var actual; - var delta; var data; var acc; var sum; - var tol; + var i; var N; var r; var x; var y; - var i; data = [ [ 2.0, 3.0 ], @@ -82,9 +80,8 @@ tape( 'the accumulator function incrementally computes the residual sum of squar if ( actual === expected ) { t.strictEqual( actual, expected, 'returns expected value' ); } else { - delta = abs( expected - actual ); - tol = 1.0 * EPS * abs( expected ); - t.strictEqual( delta <= tol, true, 'within tolerance. Actual: '+actual+'. Expected: '+expected+'. Delta: '+delta+'. Tol: '+tol+'.' ); + ulpDiff = ulpdiff( actual, expected ); + t.strictEqual( ulpDiff <= 1, true, 'within 1 ulp. Actual: '+actual+'. Expected: '+expected+'. ULP diff: '+ulpDiff ); } } t.end(); @@ -92,11 +89,10 @@ tape( 'the accumulator function incrementally computes the residual sum of squar tape( 'if not provided an input value, the accumulator function returns the current residual sum of squares', function test( t ) { var expected; + var ulpDiff; var actual; - var delta; var data; var acc; - var tol; var i; data = [ @@ -110,9 +106,8 @@ tape( 'if not provided an input value, the accumulator function returns the curr } actual = acc(); expected = 1.0 + 64.0 + 81.0; - delta = abs( expected - actual ); - tol = 1.0 * EPS * abs( expected ); - t.strictEqual( delta <= tol, true, 'within tolerance. Actual: '+actual+'. Expected: '+expected+'. Delta: '+delta+'. Tol: '+tol+'.' ); + ulpDiff = ulpdiff( actual, expected ); + t.strictEqual( ulpDiff <= 1, true, 'within 1 ulp. Actual: '+actual+'. Expected: '+expected+'. ULP diff: '+ulpDiff ); t.end(); }); From 220ba5e6298eed09db01c746979267fc29d1dbde Mon Sep 17 00:00:00 2001 From: Kanika Date: Mon, 23 Feb 2026 09:39:07 +0530 Subject: [PATCH 5/5] feat: added ulpdiff --- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/incr/nanrss/test/test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js b/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js index 3c488c8c0a48..3dd4471bf2b7 100644 --- a/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js +++ b/lib/node_modules/@stdlib/stats/incr/nanrss/test/test.js @@ -46,8 +46,8 @@ tape( 'the initial accumulated value is `null`', function test( t ) { tape( 'the accumulator function incrementally computes the residual sum of squares', function test( t ) { var expected; - var ulpDiff; var actual; + var diff; var data; var acc; var sum; @@ -80,8 +80,8 @@ tape( 'the accumulator function incrementally computes the residual sum of squar if ( actual === expected ) { t.strictEqual( actual, expected, 'returns expected value' ); } else { - ulpDiff = ulpdiff( actual, expected ); - t.strictEqual( ulpDiff <= 1, true, 'within 1 ulp. Actual: '+actual+'. Expected: '+expected+'. ULP diff: '+ulpDiff ); + diff = ulpdiff( actual, expected ); + t.strictEqual( diff <= 1, true, 'within 1 ulp. Actual: '+actual+'. Expected: '+expected+'. ULP diff: '+diff ); } } t.end(); @@ -89,8 +89,8 @@ tape( 'the accumulator function incrementally computes the residual sum of squar tape( 'if not provided an input value, the accumulator function returns the current residual sum of squares', function test( t ) { var expected; - var ulpDiff; var actual; + var diff; var data; var acc; var i; @@ -106,8 +106,8 @@ tape( 'if not provided an input value, the accumulator function returns the curr } actual = acc(); expected = 1.0 + 64.0 + 81.0; - ulpDiff = ulpdiff( actual, expected ); - t.strictEqual( ulpDiff <= 1, true, 'within 1 ulp. Actual: '+actual+'. Expected: '+expected+'. ULP diff: '+ulpDiff ); + diff = ulpdiff( actual, expected ); + t.strictEqual( diff <= 1, true, 'within 1 ulp. Actual: '+actual+'. Expected: '+expected+'. ULP diff: '+diff ); t.end(); });