From 05ee4d92c4fd348e3eeda7f73326962efec6f8cb Mon Sep 17 00:00:00 2001 From: kaustubh Date: Fri, 19 Dec 2025 11:07:11 +0530 Subject: [PATCH 1/4] feat: add blas/ext/base/ndarray/gnansumors --- .../ext/base/ndarray/gnansumors/README.md | 112 +++++++++++ .../ndarray/gnansumors/benchmark/benchmark.js | 102 ++++++++++ .../ext/base/ndarray/gnansumors/docs/repl.txt | 32 +++ .../ndarray/gnansumors/docs/types/index.d.ts | 45 +++++ .../ndarray/gnansumors/docs/types/test.ts | 57 ++++++ .../base/ndarray/gnansumors/examples/index.js | 33 ++++ .../ext/base/ndarray/gnansumors/lib/index.js | 44 +++++ .../ext/base/ndarray/gnansumors/lib/main.js | 55 ++++++ .../ext/base/ndarray/gnansumors/package.json | 67 +++++++ .../ext/base/ndarray/gnansumors/test/test.js | 183 ++++++++++++++++++ 10 files changed, 730 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/README.md new file mode 100644 index 000000000000..134749fa176d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/README.md @@ -0,0 +1,112 @@ + + +# gnansumors + +> Compute the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gnansumors = require( '@stdlib/blas/ext/base/ndarray/gnansumors' ); +``` + +#### gnansumors( arrays ) + +Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var v = gnansumors( [ x ] ); +// returns 1.0 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing a one-dimensional input ndarray. + +
+ + + +
+ +## Notes + +- If provided an empty one-dimensional ndarray, the function returns `0.0`. +- Ordinary recursive summation (i.e., a "simple" sum) is performant, but can incur significant numerical error. If performance is paramount and error tolerated, using ordinary recursive summation is acceptable; in all other cases, exercise due caution. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var gnansumors = require( '@stdlib/blas/ext/base/ndarray/gnansumors' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = gnansumors( [ x ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/benchmark/benchmark.js new file mode 100644 index 000000000000..e1242a97a746 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/benchmark/benchmark.js @@ -0,0 +1,102 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var gnansumors = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var x; + + xbuf = uniform( len, -10.0, 10.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = gnansumors( [ x ] ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + 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( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/repl.txt new file mode 100644 index 000000000000..f30ec7aea617 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( arrays ) + Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using + ordinary recursive summation. + + If provided an empty ndarray, the function returns `0.0`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + Returns + ------- + out: number + Sum. + + Examples + -------- + > var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; + > var dt = 'generic'; + > 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.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/index.d.ts new file mode 100644 index 000000000000..b20fdadc7f8b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation. +* +* @param arrays - array-like object containing an input ndarray +* @returns sum +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = gnansumors( [ x ] ); +* // returns 1.0 +*/ +declare function gnansumors = typedndarray>( arrays: [ T ] ): number; + + +// EXPORTS // + +export = gnansumors; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/test.ts new file mode 100644 index 000000000000..f6c0d5389517 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/test.ts @@ -0,0 +1,57 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import gnansumors = require( './index' ); + + +// TESTS // + +// The function returns a sum... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + gnansumors( [ x ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + gnansumors( '10' ); // $ExpectError + gnansumors( 10 ); // $ExpectError + gnansumors( true ); // $ExpectError + gnansumors( false ); // $ExpectError + gnansumors( null ); // $ExpectError + gnansumors( undefined ); // $ExpectError + gnansumors( [] ); // $ExpectError + gnansumors( {} ); // $ExpectError + gnansumors( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + gnansumors(); // $ExpectError + gnansumors( [ x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/examples/index.js new file mode 100644 index 000000000000..e20848d62379 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var gnansumors = require( './../lib' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = gnansumors( [ x ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/index.js new file mode 100644 index 000000000000..fb245e0d3fb2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/index.js @@ -0,0 +1,44 @@ +/** +* @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 the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation. +* +* @module @stdlib/blas/ext/base/ndarray/gnansumors +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var gnansumors = require( '@stdlib/blas/ext/base/ndarray/gnansumors' ); +* +* var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = gnansumors( [ x ] ); +* // returns 1.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/main.js new file mode 100644 index 000000000000..93fc1378ffb2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/main.js @@ -0,0 +1,55 @@ +/** +* @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 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 strided = require( '@stdlib/blas/ext/base/gnansumors' ).ndarray; + + +// MAIN // + +/** +* Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray +* @returns {number} sum +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = gnansumors( [ x ] ); +* // returns 1.0 +*/ +function gnansumors( arrays ) { + var x = arrays[ 0 ]; + return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gnansumors; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/package.json new file mode 100644 index 000000000000..5c8e3b05aede --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/gnansumors", + "version": "0.0.0", + "description": "Compute the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation.", + "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", + "blas", + "extended", + "sum", + "total", + "recursive", + "summation", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/test/test.js new file mode 100644 index 000000000000..31813b8d4152 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/test/test.js @@ -0,0 +1,183 @@ +/** +* @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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gnansumors = 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( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gnansumors, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( gnansumors.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, NaN, 3.0, 0.0, -3.0, 3.0 ]; + v = gnansumors( [ vector( x, 10, 1, 0 ) ] ); + t.strictEqual( v, 3.0, 'returns expected value' ); + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; + v = gnansumors( [ vector( x, 7, 1, 0 ) ] ); + t.strictEqual( v, 3.0, 'returns expected value' ); + + x = [ -4.0, NaN, -4.0 ]; + v = gnansumors( [ vector( x, 3, 1, 0 ) ] ); + t.strictEqual( v, -8.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = gnansumors( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( v, 4.0, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + v = gnansumors( [ vector( x, 3, 1, 0 ) ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = gnansumors( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN ]; + v = gnansumors( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ 1.0, 1.0e100, 1.0, -1.0e100 ]; + v = gnansumors( [ vector( x, 4, 1, 0 ) ] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty ndarray, the function returns `0.0`', function test( t ) { + var x; + var v; + + x = []; + + v = gnansumors( [ vector( x, 0, 1, 0 ) ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a ndarray containing a single element, the function returns that element', function test( t ) { + var x; + var v; + + x = [ 1.0 ]; + + v = gnansumors( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', 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 = gnansumors( [ vector( x, 4, 2, 0 ) ] ); + + t.strictEqual( v, 5.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', 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 = gnansumors( [ vector( x, 4, -2, 6 ) ] ); + + t.strictEqual( v, 5.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 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 = gnansumors( [ vector( x, 4, 2, 1 ) ] ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + t.end(); +}); From 6f84536f7f19eb079c3c3bde52ebd6d0d7c33ab7 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Fri, 19 Dec 2025 11:39:32 +0530 Subject: [PATCH 2/4] feat: add blas/ext/base/ndarray/gnansumpw --- .../{gnansumors => gnansumpw}/README.md | 18 +++++----- .../benchmark/benchmark.js | 4 +-- .../{gnansumors => gnansumpw}/docs/repl.txt | 4 +-- .../docs/types/index.d.ts | 8 ++--- .../docs/types/test.ts | 26 +++++++------- .../examples/index.js | 4 +-- .../{gnansumors => gnansumpw}/lib/index.js | 8 ++--- .../{gnansumors => gnansumpw}/lib/main.js | 10 +++--- .../{gnansumors => gnansumpw}/package.json | 6 ++-- .../{gnansumors => gnansumpw}/test/test.js | 34 +++++++++---------- 10 files changed, 61 insertions(+), 61 deletions(-) rename lib/node_modules/@stdlib/blas/ext/base/ndarray/{gnansumors => gnansumpw}/README.md (71%) rename lib/node_modules/@stdlib/blas/ext/base/ndarray/{gnansumors => gnansumpw}/benchmark/benchmark.js (96%) rename lib/node_modules/@stdlib/blas/ext/base/ndarray/{gnansumors => gnansumpw}/docs/repl.txt (92%) rename lib/node_modules/@stdlib/blas/ext/base/ndarray/{gnansumors => gnansumpw}/docs/types/index.d.ts (84%) rename lib/node_modules/@stdlib/blas/ext/base/ndarray/{gnansumors => gnansumpw}/docs/types/test.ts (67%) rename lib/node_modules/@stdlib/blas/ext/base/ndarray/{gnansumors => gnansumpw}/examples/index.js (93%) rename lib/node_modules/@stdlib/blas/ext/base/ndarray/{gnansumors => gnansumpw}/lib/index.js (83%) rename lib/node_modules/@stdlib/blas/ext/base/ndarray/{gnansumors => gnansumpw}/lib/main.js (87%) rename lib/node_modules/@stdlib/blas/ext/base/ndarray/{gnansumors => gnansumpw}/package.json (90%) rename lib/node_modules/@stdlib/blas/ext/base/ndarray/{gnansumors => gnansumpw}/test/test.js (80%) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/README.md similarity index 71% rename from lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/README.md rename to lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/README.md index 134749fa176d..c8f365e82ded 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# gnansumors +# gnansumpw -> Compute the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation. +> Compute the sum of a one-dimensional ndarray, ignoring `NaN` values and using pairwise summation.
@@ -33,12 +33,12 @@ limitations under the License. ## Usage ```javascript -var gnansumors = require( '@stdlib/blas/ext/base/ndarray/gnansumors' ); +var gnansumpw = require( '@stdlib/blas/ext/base/ndarray/gnansumpw' ); ``` -#### gnansumors( arrays ) +#### gnansumpw( arrays ) -Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation. +Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using pairwise summation. ```javascript var ndarray = require( '@stdlib/ndarray/base/ctor' ); @@ -46,7 +46,7 @@ var ndarray = require( '@stdlib/ndarray/base/ctor' ); var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); -var v = gnansumors( [ x ] ); +var v = gnansumpw( [ x ] ); // returns 1.0 ``` @@ -63,7 +63,7 @@ The function has the following parameters: ## Notes - If provided an empty one-dimensional ndarray, the function returns `0.0`. -- Ordinary recursive summation (i.e., a "simple" sum) is performant, but can incur significant numerical error. If performance is paramount and error tolerated, using ordinary recursive summation is acceptable; in all other cases, exercise due caution. +- In general, pairwise summation is more numerically stable than ordinary recursive summation (i.e., "simple" summation), with slightly worse performance. While not the most numerically stable summation technique (e.g., compensated summation techniques such as the Kahan–Babuška-Neumaier algorithm are generally more numerically stable), pairwise summation strikes a reasonable balance between numerical stability and performance. If either numerical stability or performance is more desirable for your use case, consider alternative summation techniques.
@@ -79,7 +79,7 @@ The function has the following parameters: var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var gnansumors = require( '@stdlib/blas/ext/base/ndarray/gnansumors' ); +var gnansumpw = require( '@stdlib/blas/ext/base/ndarray/gnansumpw' ); var xbuf = discreteUniform( 10, -50, 50, { 'dtype': 'generic' @@ -87,7 +87,7 @@ var xbuf = discreteUniform( 10, -50, 50, { var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); -var v = gnansumors( [ x ] ); +var v = gnansumpw( [ x ] ); console.log( v ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/benchmark/benchmark.js similarity index 96% rename from lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/benchmark/benchmark.js rename to lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/benchmark/benchmark.js index e1242a97a746..0054a3e6100d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/benchmark/benchmark.js @@ -26,7 +26,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var pkg = require( './../package.json' ).name; -var gnansumors = require( './../lib' ); +var gnansumpw = require( './../lib' ); // VARIABLES // @@ -60,7 +60,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = gnansumors( [ x ] ); + v = gnansumpw( [ x ] ); if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/repl.txt similarity index 92% rename from lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/repl.txt rename to lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/repl.txt index f30ec7aea617..2d55ab93b2de 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( arrays ) - Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using - ordinary recursive summation. + Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and + using pairwise summation. If provided an empty ndarray, the function returns `0.0`. diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/index.d.ts similarity index 84% rename from lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/index.d.ts rename to lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/index.d.ts index b20fdadc7f8b..ade1214c76a3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/index.d.ts @@ -23,7 +23,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; /** -* Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation. +* Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using pairwise summation. * * @param arrays - array-like object containing an input ndarray * @returns sum @@ -34,12 +34,12 @@ import { typedndarray } from '@stdlib/types/ndarray'; * var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var v = gnansumors( [ x ] ); +* var v = gnansumpw( [ x ] ); * // returns 1.0 */ -declare function gnansumors = typedndarray>( arrays: [ T ] ): number; +declare function gnansumpw = typedndarray>( arrays: [ T ] ): number; // EXPORTS // -export = gnansumors; +export = gnansumpw; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/test.ts similarity index 67% rename from lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/test.ts rename to lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/test.ts index f6c0d5389517..27a61e86beba 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/test.ts @@ -19,7 +19,7 @@ /* eslint-disable space-in-parens */ import zeros = require( '@stdlib/ndarray/zeros' ); -import gnansumors = require( './index' ); +import gnansumpw = require( './index' ); // TESTS // @@ -30,20 +30,20 @@ import gnansumors = require( './index' ); 'dtype': 'float64' }); - gnansumors( [ x ] ); // $ExpectType number + gnansumpw( [ x ] ); // $ExpectType number } // The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... { - gnansumors( '10' ); // $ExpectError - gnansumors( 10 ); // $ExpectError - gnansumors( true ); // $ExpectError - gnansumors( false ); // $ExpectError - gnansumors( null ); // $ExpectError - gnansumors( undefined ); // $ExpectError - gnansumors( [] ); // $ExpectError - gnansumors( {} ); // $ExpectError - gnansumors( ( x: number ): number => x ); // $ExpectError + gnansumpw( '10' ); // $ExpectError + gnansumpw( 10 ); // $ExpectError + gnansumpw( true ); // $ExpectError + gnansumpw( false ); // $ExpectError + gnansumpw( null ); // $ExpectError + gnansumpw( undefined ); // $ExpectError + gnansumpw( [] ); // $ExpectError + gnansumpw( {} ); // $ExpectError + gnansumpw( ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... @@ -52,6 +52,6 @@ import gnansumors = require( './index' ); 'dtype': 'float64' }); - gnansumors(); // $ExpectError - gnansumors( [ x ], {} ); // $ExpectError + gnansumpw(); // $ExpectError + gnansumpw( [ x ], {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/examples/index.js similarity index 93% rename from lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/examples/index.js rename to lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/examples/index.js index e20848d62379..e043575cfeda 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/examples/index.js @@ -21,7 +21,7 @@ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var gnansumors = require( './../lib' ); +var gnansumpw = require( './../lib' ); var xbuf = discreteUniform( 10, -50, 50, { 'dtype': 'generic' @@ -29,5 +29,5 @@ var xbuf = discreteUniform( 10, -50, 50, { var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); -var v = gnansumors( [ x ] ); +var v = gnansumpw( [ x ] ); console.log( v ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/lib/index.js similarity index 83% rename from lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/index.js rename to lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/lib/index.js index fb245e0d3fb2..1c95c5f335e3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/lib/index.js @@ -19,18 +19,18 @@ 'use strict'; /** -* Compute the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation. +* Compute the sum of a one-dimensional ndarray, ignoring `NaN` values and using pairwise summation. * -* @module @stdlib/blas/ext/base/ndarray/gnansumors +* @module @stdlib/blas/ext/base/ndarray/gnansumpw * * @example * var ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var gnansumors = require( '@stdlib/blas/ext/base/ndarray/gnansumors' ); +* var gnansumpw = require( '@stdlib/blas/ext/base/ndarray/gnansumpw' ); * * var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var v = gnansumors( [ x ] ); +* var v = gnansumpw( [ x ] ); * // returns 1.0 */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/lib/main.js similarity index 87% rename from lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/main.js rename to lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/lib/main.js index 93fc1378ffb2..b61a5d20f418 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/lib/main.js @@ -24,13 +24,13 @@ 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 strided = require( '@stdlib/blas/ext/base/gnansumors' ).ndarray; +var strided = require( '@stdlib/blas/ext/base/gnansumpw' ).ndarray; // MAIN // /** -* Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation. +* Computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using pairwise summation. * * @param {ArrayLikeObject} arrays - array-like object containing an input ndarray * @returns {number} sum @@ -41,10 +41,10 @@ var strided = require( '@stdlib/blas/ext/base/gnansumors' ).ndarray; * var xbuf = [ 1.0, -2.0, NaN, 2.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var v = gnansumors( [ x ] ); +* var v = gnansumpw( [ x ] ); * // returns 1.0 */ -function gnansumors( arrays ) { +function gnansumpw( arrays ) { var x = arrays[ 0 ]; return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len } @@ -52,4 +52,4 @@ function gnansumors( arrays ) { // EXPORTS // -module.exports = gnansumors; +module.exports = gnansumpw; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/package.json similarity index 90% rename from lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/package.json rename to lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/package.json index 5c8e3b05aede..e93a8404a471 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/blas/ext/base/ndarray/gnansumors", + "name": "@stdlib/blas/ext/base/ndarray/gnansumpw", "version": "0.0.0", - "description": "Compute the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation.", + "description": "Compute the sum of a one-dimensional ndarray, ignoring `NaN` values and using pairwise summation.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -59,7 +59,7 @@ "extended", "sum", "total", - "recursive", + "pairwise", "summation", "ndarray" ], diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/test/test.js similarity index 80% rename from lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/test/test.js rename to lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/test/test.js index 31813b8d4152..29f1f6f5b666 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumors/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/test/test.js @@ -23,7 +23,7 @@ var tape = require( 'tape' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var gnansumors = require( './../lib' ); +var gnansumpw = require( './../lib' ); // FUNCTIONS // @@ -47,49 +47,49 @@ function vector( buffer, length, stride, offset ) { tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof gnansumors, 'function', 'main export is a function' ); + t.strictEqual( typeof gnansumpw, 'function', 'main export is a function' ); t.end(); }); tape( 'the function has an arity of 1', function test( t ) { - t.strictEqual( gnansumors.length, 1, 'has expected arity' ); + t.strictEqual( gnansumpw.length, 1, 'has expected arity' ); t.end(); }); -tape( 'the function computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using ordinary recursive summation', function test( t ) { +tape( 'the function computes the sum of a one-dimensional ndarray, ignoring `NaN` values and using pairwise summation', function test( t ) { var x; var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, NaN, 3.0, 0.0, -3.0, 3.0 ]; - v = gnansumors( [ vector( x, 10, 1, 0 ) ] ); + v = gnansumpw( [ vector( x, 10, 1, 0 ) ] ); t.strictEqual( v, 3.0, 'returns expected value' ); x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, 3.0 ]; - v = gnansumors( [ vector( x, 7, 1, 0 ) ] ); + v = gnansumpw( [ vector( x, 7, 1, 0 ) ] ); t.strictEqual( v, 3.0, 'returns expected value' ); x = [ -4.0, NaN, -4.0 ]; - v = gnansumors( [ vector( x, 3, 1, 0 ) ] ); + v = gnansumpw( [ vector( x, 3, 1, 0 ) ] ); t.strictEqual( v, -8.0, 'returns expected value' ); x = [ NaN, 4.0 ]; - v = gnansumors( [ vector( x, 2, 1, 0 ) ] ); + v = gnansumpw( [ vector( x, 2, 1, 0 ) ] ); t.strictEqual( v, 4.0, 'returns expected value' ); x = [ -0.0, 0.0, -0.0 ]; - v = gnansumors( [ vector( x, 3, 1, 0 ) ] ); + v = gnansumpw( [ vector( x, 3, 1, 0 ) ] ); t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - v = gnansumors( [ vector( x, 2, 1, 0 ) ] ); + v = gnansumpw( [ vector( x, 2, 1, 0 ) ] ); t.strictEqual( v, 0.0, 'returns expected value' ); x = [ NaN ]; - v = gnansumors( [ vector( x, 1, 1, 0 ) ] ); + v = gnansumpw( [ vector( x, 1, 1, 0 ) ] ); t.strictEqual( v, 0.0, 'returns expected value' ); x = [ 1.0, 1.0e100, 1.0, -1.0e100 ]; - v = gnansumors( [ vector( x, 4, 1, 0 ) ] ); + v = gnansumpw( [ vector( x, 4, 1, 0 ) ] ); t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); @@ -101,7 +101,7 @@ tape( 'if provided an empty ndarray, the function returns `0.0`', function test( x = []; - v = gnansumors( [ vector( x, 0, 1, 0 ) ] ); + v = gnansumpw( [ vector( x, 0, 1, 0 ) ] ); t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); @@ -113,7 +113,7 @@ tape( 'if provided a ndarray containing a single element, the function returns t x = [ 1.0 ]; - v = gnansumors( [ vector( x, 1, 1, 0 ) ] ); + v = gnansumpw( [ vector( x, 1, 1, 0 ) ] ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); @@ -134,7 +134,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', 2.0 ]; - v = gnansumors( [ vector( x, 4, 2, 0 ) ] ); + v = gnansumpw( [ vector( x, 4, 2, 0 ) ] ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -155,7 +155,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', 2.0 ]; - v = gnansumors( [ vector( x, 4, -2, 6 ) ] ); + v = gnansumpw( [ vector( x, 4, -2, 6 ) ] ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -176,7 +176,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 4.0 // 3 ]; - v = gnansumors( [ vector( x, 4, 2, 1 ) ] ); + v = gnansumpw( [ vector( x, 4, 2, 1 ) ] ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); From 4d070a7b7aa73fa997654d9e3076ecba1d0a8e3b Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 19 Dec 2025 00:05:38 -0800 Subject: [PATCH 3/4] docs: fix comment Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/test.ts index 27a61e86beba..f6ebbe8eafac 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/docs/types/test.ts @@ -24,7 +24,7 @@ import gnansumpw = require( './index' ); // TESTS // -// The function returns a sum... +// The function returns a number... { const x = zeros( [ 10 ], { 'dtype': 'float64' From 979cb2abfed683b592541fff45a3525adb5d1232 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Fri, 19 Dec 2025 13:41:48 +0530 Subject: [PATCH 4/4] Added missing reference --- .../blas/ext/base/ndarray/gnansumpw/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/README.md index c8f365e82ded..6aaf803fe7e2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gnansumpw/README.md @@ -95,6 +95,16 @@ console.log( v ); +
+ +## References + +- Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050][@higham:1993a]. + +
+ + +