From e1c443582087dc9a2c0fe3d9cd9dc1dd0f1e4945 Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 16 Dec 2025 12:13:59 +0530 Subject: [PATCH 1/5] initial changes --- .../blas/ext/base/ndarray/gsumpw/README.md | 122 +++++++++++++ .../ndarray/gsumpw/benchmark/benchmark.js | 102 +++++++++++ .../ext/base/ndarray/gsumpw/docs/repl.txt | 32 ++++ .../base/ndarray/gsumpw/docs/types/index.d.ts | 45 +++++ .../base/ndarray/gsumpw/docs/types/test.ts | 57 ++++++ .../ext/base/ndarray/gsumpw/examples/index.js | 33 ++++ .../blas/ext/base/ndarray/gsumpw/lib/index.js | 44 +++++ .../blas/ext/base/ndarray/gsumpw/lib/main.js | 55 ++++++ .../blas/ext/base/ndarray/gsumpw/package.json | 66 +++++++ .../blas/ext/base/ndarray/gsumpw/test/test.js | 172 ++++++++++++++++++ 10 files changed, 728 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md new file mode 100644 index 000000000000..79ded6455db3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md @@ -0,0 +1,122 @@ + + +# gsumpw + +> Compute the sum of all elements in a one-dimensional ndarray using pairwise summation. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gsumpw= require( '@stdlib/blas/ext/base/ndarray/gsumpw' ); +``` + +#### gsumpw( arrays ) + +Computes the sum of all elements in a one-dimensional ndarray using pairwise summation. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var v = gsumpw( [ x ] ); +// returns 10.0 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing a one-dimensional input ndarray. + +
+ + + +
+ +## Notes + +- If provided an empty real-valued one-dimensional ndarray, the function returns `0.0`. +- 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. + +
+ + + +
+ +## 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 gsumpw= require( '@stdlib/blas/ext/base/ndarray/gsumpw' ); + +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 = gsumpw( [ x ] ); +console.log( v ); +``` + +
+ + + +
+ +- 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]. + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/benchmark/benchmark.js new file mode 100644 index 000000000000..9e99d09fbcd1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/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 gsumors = 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 = gsumors( [ 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/gsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/repl.txt new file mode 100644 index 000000000000..db5474290996 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( arrays ) + Computes the sum of all elements in a one-dimensional ndarray 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, 3.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 ] ) + 6.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/index.d.ts new file mode 100644 index 000000000000..3be7016c67b5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/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 all elements in a one-dimensional ndarray 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, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = gsumors( [ x ] ); +* // returns 10.0 +*/ +declare function gsumors = typedndarray>( arrays: [ T ] ): number; + + +// EXPORTS // + +export = gsumors; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/test.ts new file mode 100644 index 000000000000..984714d7863c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/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 gsumors = require( './index' ); + + +// TESTS // + +// The function returns a sum... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + gsumors( [ x ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + gsumors( '10' ); // $ExpectError + gsumors( 10 ); // $ExpectError + gsumors( true ); // $ExpectError + gsumors( false ); // $ExpectError + gsumors( null ); // $ExpectError + gsumors( undefined ); // $ExpectError + gsumors( [] ); // $ExpectError + gsumors( {} ); // $ExpectError + gsumors( ( 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' + }); + + gsumors(); // $ExpectError + gsumors( [ x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/examples/index.js new file mode 100644 index 000000000000..0ad3c2d3b8dd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/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 gsumors = 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 = gsumors( [ x ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/index.js new file mode 100644 index 000000000000..df9cca6edd91 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/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 all elements in a one-dimensional ndarray using ordinary recursive summation. +* +* @module @stdlib/blas/ext/base/ndarray/gsumors +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var gsumors = require( '@stdlib/blas/ext/base/ndarray/gsumors' ); +* +* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = gsumors( [ x ] ); +* // returns 10.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/main.js new file mode 100644 index 000000000000..f767bc97b03b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/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/gsumors' ).ndarray; + + +// MAIN // + +/** +* Computes the sum of all elements in a one-dimensional ndarray 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, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = gsumors( [ x ] ); +* // returns 10.0 +*/ +function gsumors( 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 = gsumors; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/package.json new file mode 100644 index 000000000000..a34bb235dffd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/gsumors", + "version": "0.0.0", + "description": "Compute the sum of all elements in a one-dimensional ndarray 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", + "summation", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js new file mode 100644 index 000000000000..d4f0f9d59d17 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js @@ -0,0 +1,172 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gsumors = 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 gsumors, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( gsumors.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function computes the sum of all elements in a one-dimensional ndarray using ordinary recursive summation', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = gsumors( [ vector( x, 6, 1, 0 ) ] ); + t.strictEqual( v, 3.0, 'returns expected value' ); + + x = [ -4.0, -5.0 ]; + v = gsumors( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( v, -9.0, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + v = gsumors( [ vector( x, 3, 1, 0 ) ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = gsumors( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = gsumors( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, '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 = gsumors( [ 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 = gsumors( [ 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 = gsumors( [ 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 = gsumors( [ 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 = gsumors( [ vector( x, 4, 2, 1 ) ] ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + t.end(); +}); From de3ba9d16fa8835a25d357d30d9812b6d1f47e8b Mon Sep 17 00:00:00 2001 From: kaustubh Date: Tue, 16 Dec 2025 12:30:30 +0530 Subject: [PATCH 2/5] feat: add blas/ext/base/ndarray/gsumpw --- .../ndarray/gsumpw/benchmark/benchmark.js | 4 +-- .../ext/base/ndarray/gsumpw/docs/repl.txt | 4 +-- .../base/ndarray/gsumpw/docs/types/index.d.ts | 8 +++--- .../base/ndarray/gsumpw/docs/types/test.ts | 26 ++++++++--------- .../ext/base/ndarray/gsumpw/examples/index.js | 4 +-- .../blas/ext/base/ndarray/gsumpw/lib/index.js | 8 +++--- .../blas/ext/base/ndarray/gsumpw/lib/main.js | 10 +++---- .../blas/ext/base/ndarray/gsumpw/package.json | 5 ++-- .../blas/ext/base/ndarray/gsumpw/test/test.js | 28 +++++++++---------- 9 files changed, 49 insertions(+), 48 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/benchmark/benchmark.js index 9e99d09fbcd1..cb47895bdf27 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/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 gsumors = require( './../lib' ); +var gsumpw = require( './../lib' ); // VARIABLES // @@ -60,7 +60,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = gsumors( [ x ] ); + v = gsumpw( [ x ] ); if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/repl.txt index db5474290996..ab2092b8fd0b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( arrays ) - Computes the sum of all elements in a one-dimensional ndarray using ordinary - recursive summation. + Computes the sum of all elements in a one-dimensional ndarray using pairwise + summation. If provided an empty ndarray, the function returns `0.0`. diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/index.d.ts index 3be7016c67b5..973c86e6248b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/index.d.ts @@ -23,7 +23,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; /** -* Computes the sum of all elements in a one-dimensional ndarray using ordinary recursive summation. +* Computes the sum of all elements in a one-dimensional ndarray 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, 3.0, 4.0, 2.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var v = gsumors( [ x ] ); +* var v = gsumpw( [ x ] ); * // returns 10.0 */ -declare function gsumors = typedndarray>( arrays: [ T ] ): number; +declare function gsumpw = typedndarray>( arrays: [ T ] ): number; // EXPORTS // -export = gsumors; +export = gsumpw; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/test.ts index 984714d7863c..69e5f4d50316 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/docs/types/test.ts @@ -19,7 +19,7 @@ /* eslint-disable space-in-parens */ import zeros = require( '@stdlib/ndarray/zeros' ); -import gsumors = require( './index' ); +import gsumpw = require( './index' ); // TESTS // @@ -30,20 +30,20 @@ import gsumors = require( './index' ); 'dtype': 'float64' }); - gsumors( [ x ] ); // $ExpectType number + gsumpw( [ x ] ); // $ExpectType number } // The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... { - gsumors( '10' ); // $ExpectError - gsumors( 10 ); // $ExpectError - gsumors( true ); // $ExpectError - gsumors( false ); // $ExpectError - gsumors( null ); // $ExpectError - gsumors( undefined ); // $ExpectError - gsumors( [] ); // $ExpectError - gsumors( {} ); // $ExpectError - gsumors( ( x: number ): number => x ); // $ExpectError + gsumpw( '10' ); // $ExpectError + gsumpw( 10 ); // $ExpectError + gsumpw( true ); // $ExpectError + gsumpw( false ); // $ExpectError + gsumpw( null ); // $ExpectError + gsumpw( undefined ); // $ExpectError + gsumpw( [] ); // $ExpectError + gsumpw( {} ); // $ExpectError + gsumpw( ( 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 gsumors = require( './index' ); 'dtype': 'float64' }); - gsumors(); // $ExpectError - gsumors( [ x ], {} ); // $ExpectError + gsumpw(); // $ExpectError + gsumpw( [ x ], {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/examples/index.js index 0ad3c2d3b8dd..cd1eb1daea48 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/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 gsumors = require( './../lib' ); +var gsumpw = 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 = gsumors( [ x ] ); +var v = gsumpw( [ x ] ); console.log( v ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/index.js index df9cca6edd91..914456a439c8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/index.js @@ -19,18 +19,18 @@ 'use strict'; /** -* Compute the sum of all elements in a one-dimensional ndarray using ordinary recursive summation. +* Compute the sum of all elements in a one-dimensional ndarray using pairwise summation. * -* @module @stdlib/blas/ext/base/ndarray/gsumors +* @module @stdlib/blas/ext/base/ndarray/gsumpw * * @example * var ndarray = require( '@stdlib/ndarray/base/ctor' ); -* var gsumors = require( '@stdlib/blas/ext/base/ndarray/gsumors' ); +* var gsumpw = require( '@stdlib/blas/ext/base/ndarray/gsumpw' ); * * var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var v = gsumors( [ x ] ); +* var v = gsumpw( [ x ] ); * // returns 10.0 */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/main.js index f767bc97b03b..a53f4bfec2a9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/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/gsumors' ).ndarray; +var strided = require( '@stdlib/blas/ext/base/gsumpw' ).ndarray; // MAIN // /** -* Computes the sum of all elements in a one-dimensional ndarray using ordinary recursive summation. +* Computes the sum of all elements in a one-dimensional ndarray 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/gsumors' ).ndarray; * var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var v = gsumors( [ x ] ); +* var v = gsumpw( [ x ] ); * // returns 10.0 */ -function gsumors( arrays ) { +function gsumpw( 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 gsumors( arrays ) { // EXPORTS // -module.exports = gsumors; +module.exports = gsumpw; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/package.json index a34bb235dffd..11969d76b949 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/blas/ext/base/ndarray/gsumors", + "name": "@stdlib/blas/ext/base/ndarray/gsumpw", "version": "0.0.0", - "description": "Compute the sum of all elements in a one-dimensional ndarray using ordinary recursive summation.", + "description": "Compute the sum of all elements in a one-dimensional ndarray using pairwise summation.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -59,6 +59,7 @@ "extended", "sum", "total", + "pairwise", "summation", "ndarray" ], diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js index d4f0f9d59d17..cf5e46aa7852 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js @@ -24,7 +24,7 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var gsumors = require( './../lib' ); +var gsumpw = require( './../lib' ); // FUNCTIONS // @@ -48,37 +48,37 @@ function vector( buffer, length, stride, offset ) { tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof gsumors, 'function', 'main export is a function' ); + t.strictEqual( typeof gsumpw, 'function', 'main export is a function' ); t.end(); }); tape( 'the function has an arity of 1', function test( t ) { - t.strictEqual( gsumors.length, 1, 'has expected arity' ); + t.strictEqual( gsumpw.length, 1, 'has expected arity' ); t.end(); }); -tape( 'the function computes the sum of all elements in a one-dimensional ndarray using ordinary recursive summation', function test( t ) { +tape( 'the function computes the sum of all elements in a one-dimensional ndarray using pairwise summation.', function test( t ) { var x; var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = gsumors( [ vector( x, 6, 1, 0 ) ] ); + v = gsumpw( [ vector( x, 6, 1, 0 ) ] ); t.strictEqual( v, 3.0, 'returns expected value' ); x = [ -4.0, -5.0 ]; - v = gsumors( [ vector( x, 2, 1, 0 ) ] ); + v = gsumpw( [ vector( x, 2, 1, 0 ) ] ); t.strictEqual( v, -9.0, 'returns expected value' ); x = [ -0.0, 0.0, -0.0 ]; - v = gsumors( [ vector( x, 3, 1, 0 ) ] ); + v = gsumpw( [ vector( x, 3, 1, 0 ) ] ); t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); x = [ NaN ]; - v = gsumors( [ vector( x, 1, 1, 0 ) ] ); + v = gsumpw( [ vector( x, 1, 1, 0 ) ] ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - v = gsumors( [ vector( x, 2, 1, 0 ) ] ); + v = gsumpw( [ vector( x, 2, 1, 0 ) ] ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); @@ -90,7 +90,7 @@ tape( 'if provided an empty ndarray, the function returns `0.0`', function test( x = []; - v = gsumors( [ vector( x, 0, 1, 0 ) ] ); + v = gsumpw( [ vector( x, 0, 1, 0 ) ] ); t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); t.end(); @@ -102,7 +102,7 @@ tape( 'if provided a ndarray containing a single element, the function returns t x = [ 1.0 ]; - v = gsumors( [ vector( x, 1, 1, 0 ) ] ); + v = gsumpw( [ vector( x, 1, 1, 0 ) ] ); t.strictEqual( v, 1.0, 'returns expected value' ); t.end(); @@ -123,7 +123,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', 2.0 ]; - v = gsumors( [ vector( x, 4, 2, 0 ) ] ); + v = gsumpw( [ vector( x, 4, 2, 0 ) ] ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -144,7 +144,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', 2.0 ]; - v = gsumors( [ vector( x, 4, -2, 6 ) ] ); + v = gsumpw( [ vector( x, 4, -2, 6 ) ] ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -165,7 +165,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', 4.0 // 3 ]; - v = gsumors( [ vector( x, 4, 2, 1 ) ] ); + v = gsumpw( [ vector( x, 4, 2, 1 ) ] ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); From f831caa28e2ccd7413b955d62157e57991b741a7 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 15 Dec 2025 23:36:09 -0800 Subject: [PATCH 3/5] style: fix missing space Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md index 79ded6455db3..c10682bdb368 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md @@ -33,7 +33,7 @@ limitations under the License. ## Usage ```javascript -var gsumpw= require( '@stdlib/blas/ext/base/ndarray/gsumpw' ); +var gsumpw = require( '@stdlib/blas/ext/base/ndarray/gsumpw' ); ``` #### gsumpw( arrays ) From 698608286518f111d3cef6298675160215e81f9b Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 15 Dec 2025 23:38:10 -0800 Subject: [PATCH 4/5] test: fix description Signed-off-by: Athan --- .../@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js index cf5e46aa7852..95677e3efbbd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/test/test.js @@ -57,7 +57,7 @@ tape( 'the function has an arity of 1', function test( t ) { t.end(); }); -tape( 'the function computes the sum of all elements in a one-dimensional ndarray using pairwise summation.', function test( t ) { +tape( 'the function computes the sum of all elements in a one-dimensional ndarray using pairwise summation', function test( t ) { var x; var v; From 6630580c819d18971840b6be3e52d16b9cda07f2 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 15 Dec 2025 23:43:02 -0800 Subject: [PATCH 5/5] style: fix missing space Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md index c10682bdb368..a11e6c3270df 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsumpw/README.md @@ -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 gsumpw= require( '@stdlib/blas/ext/base/ndarray/gsumpw' ); +var gsumpw = require( '@stdlib/blas/ext/base/ndarray/gsumpw' ); var xbuf = discreteUniform( 10, -50, 50, { 'dtype': 'generic'