From dc8035a428fa4ade1428e625ea7e8288c54a2609 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 10 Nov 2025 20:15:46 +0530 Subject: [PATCH 01/16] add stats base ndarray range by --- .../stats/base/ndarray/range-by/README.md | 119 ++++++++++++ .../ndarray/range-by/benchmark/benchmark.js | 113 ++++++++++++ .../stats/base/ndarray/range-by/docs/repl.txt | 41 +++++ .../ndarray/range-by/docs/types/index.d.ts | 50 ++++++ .../base/ndarray/range-by/docs/types/test.ts | 70 ++++++++ .../base/ndarray/range-by/example/index.js | 40 +++++ .../stats/base/ndarray/range-by/lib/index.js | 48 +++++ .../stats/base/ndarray/range-by/lib/main.js | 67 +++++++ .../stats/base/ndarray/range-by/package.json | 67 +++++++ .../stats/base/ndarray/range-by/test/test.js | 170 ++++++++++++++++++ 10 files changed, 785 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md new file mode 100644 index 000000000000..ccffc891dcc2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md @@ -0,0 +1,119 @@ + + +# rangeBy + +> Compute the range of a one-dimensional ndarray via a callback function. + +
+ +
+ + + +
+ +## Usage + +```javascript +var rangeBy = require( '@stdlib/stats/base/ndarray/range-by' ); +``` + +#### rangeBy( arrays ) + +Computes the range of a one-dimensional ndarray via a callback function. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +function accessor( v ) { + return v * 2.0; +} + +var xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + +var v = rangeBy( [ x, accessor ] ); +// returns 18.0 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing a one-dimensional input ndarray and a callback function. + +
+ + + +
+ +## Notes + +- If provided an empty one-dimensional ndarray, the function returns `NaN`. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var rangeBy = require( '@stdlib/stats/base/ndarray/range-by' ); + +function accessor( v ) { + return v * 2.0; +} + +var options = { + 'dtype': 'float64' +}; + +var xbuf = uniform( 10, -10.0, 10.0, options ); +var x = new ndarray( options.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = rangeBy( [ x, accessor ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js new file mode 100644 index 000000000000..790b58bd2a4a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js @@ -0,0 +1,113 @@ +/** +* @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 rangeBy = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Accessor function. +* +* @private +* @param {number} value - array element +* @returns {number} accessed value +*/ +function accessor( value ) { + return value * 2.0; +} + +/** +* 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 y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = rangeBy( [ x, accessor ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + 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+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt new file mode 100644 index 000000000000..175a7ab8a013 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt @@ -0,0 +1,41 @@ +{{alias}}( arrays ) + Computes the range of a one-dimensional numeric ndarray via a callback function. + + If provided an empty ndarray, the function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + Returns + ------- + out: number + Range. + + Examples + -------- + > function accessor( v ) { return v * 2.0; }; + > var xbuf = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); + > var dt = 'float64'; + > 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, accessor ] ) + 18.0 + + // Using a subset of elements via stride and offset: + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > var dt = 'float64'; + > var sh = [ 3 ]; + > var sx = [ 2 ]; + > var ox = 1; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > {{alias}}( [ x, accessor ] ) + 8.0 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts new file mode 100644 index 000000000000..cdf3547229f4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts @@ -0,0 +1,50 @@ +/* +* @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 { ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the range of a one-dimensional numeric ndarray via a callback function. +* +* @param arrays - array-like object containing an input ndarray and a callback function +* @returns range +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* function accessor( v ) { +* return v * 2.0; +* } +* +* var xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* +* var v = rangeBy( [ x, accessor ] ); +* // returns 18.0 +*/ +declare function rangeBy( arrays: [ ndarray, Function ] ): number; + + +// EXPORTS // + +export = rangeBy; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/test.ts new file mode 100644 index 000000000000..443c7f91757c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/test.ts @@ -0,0 +1,70 @@ +/* +* @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' ); // eslint-disable-line import/no-unresolved +import rangeBy = require( './index' ); // eslint-disable-line import/no-unresolved + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + function accessor( v: number ): number { + return v * 2.0; + } + + rangeBy( [ x, accessor ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object containing an ndarray and a function... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + rangeBy( '10' ); // $ExpectError + rangeBy( 10 ); // $ExpectError + rangeBy( true ); // $ExpectError + rangeBy( false ); // $ExpectError + rangeBy( null ); // $ExpectError + rangeBy( undefined ); // $ExpectError + rangeBy( [] ); // $ExpectError + rangeBy( [ x ] ); // $ExpectError + rangeBy( {} ); // $ExpectError + rangeBy( ( 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' + }); + + function accessor( v: number ): number { + return v * 2.0; + } + + rangeBy(); // $ExpectError + rangeBy( [ x, accessor ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js new file mode 100644 index 000000000000..880aa7b6b5af --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js @@ -0,0 +1,40 @@ +/** +* @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 linspace = require( '@stdlib/array/base/linspace' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var rangeBy = require( './../lib' ); + +// Create a data buffer: +var xbuf = linspace( -5.0, 5.0, 10 ); + +// Create an ndarray: +var x = new ndarray( 'generic', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +// Define an accessor function: +function accessor( v ) { + return v * 2.0; +} + +// Compute the range: +var v = rangeBy( [ x, accessor ] ); +console.log( 'range: %d', v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js new file mode 100644 index 000000000000..27ad90a43756 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js @@ -0,0 +1,48 @@ +/** +* @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 range of an ndarray via a callback function. +* +* @module @stdlib/stats/base/ndarray/range-by +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var rangeBy = require( '@stdlib/stats/base/ndarray/range-by' ); +* +* function accessor( v ) { +* return v * 2.0; +* } +* +* var xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 8 ], [ 1 ], 0, 'row-major' ); +* +* var v = rangeBy( [ x, accessor ] ); +* // returns 18.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js new file mode 100644 index 000000000000..6ef106ca02fb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js @@ -0,0 +1,67 @@ +/** +* @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/stats/strided/range-by' ).ndarray; + + +// MAIN // + +/** +* Computes the range of a one-dimensional numeric ndarray via a callback function. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray and a callback function +* @returns {number} range +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* function accessor( v ) { +* return v * 2.0; +* } +* +* var xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* +* var v = rangeBy( [ x, accessor ] ); +* // returns 18.0 +*/ +function rangeBy( arrays ) { + var x = arrays[ 0 ]; + var clbk = arrays[ 1 ]; + return strided( + numelDimension( x, 0 ), + getData( x ), + getStride( x, 0 ), + getOffset( x ), + clbk + ); +} + + +// EXPORTS // + +module.exports = rangeBy; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json new file mode 100644 index 000000000000..be12900db7d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/base/ndarray/range-by", + "version": "0.0.0", + "description": "Compute the range of an ndarray via a callback function.", + "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": "./example", + "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", + "range", + "ndarray", + "callback", + "accessor", + "extent", + "domain", + "spread" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js new file mode 100644 index 000000000000..ef9c002bc59c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js @@ -0,0 +1,170 @@ +/** +* @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 rangeBy = 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' ); +} + +function accessor( v ) { + if ( v === void 0 ) { + return; + } + return v * 2.0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rangeBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( rangeBy.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the range of a one-dimensional ndarray via a callback function', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = rangeBy( [ vector( x, 6, 1, 0 ), accessor ] ); + t.strictEqual( v, 18.0, 'returns expected value' ); + + x = [ -4.0, -5.0 ]; + v = rangeBy( [ vector( x, 2, 1, 0 ), accessor ] ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + v = rangeBy( [ vector( x, 3, 1, 0 ), accessor ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = rangeBy( [ vector( x, 1, 1, 0 ), accessor ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = rangeBy( [ vector( x, 2, 1, 0 ), accessor ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Array( 5 ); + v = rangeBy( [ vector( x, 5, 1, 0 ), accessor ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Array( 5 ); + x[ 2 ] = 1.0; + v = rangeBy( [ vector( x, 5, 1, 0 ), accessor ] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports 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 = rangeBy( [ vector( x, 4, 2, 0 ), accessor ] ); + t.strictEqual( v, 12.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports 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 = rangeBy( [ vector( x, 4, -2, 6 ), accessor ] ); + t.strictEqual( v, 12.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports non-zero offsets', function test( t ) { + var x; + var v; + + x = [ + 1.0, + -2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + -6.0 // 2 + ]; + v = rangeBy( [ vector( x, 3, 2, 1 ), accessor ] ); + t.strictEqual( v, 20.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an empty array, the function returns `NaN`', function test( t ) { + var x = []; + var v = rangeBy( [ vector( x, 0, 1, 0 ), accessor ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a single element, the function returns `0`', function test( t ) { + var x = [ 5.0 ]; + var v = rangeBy( [ vector( x, 1, 1, 0 ), accessor ] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + t.end(); +}); From 07eda8251ed99a0123ea066a48f6ed8fed3ccf34 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 10 Nov 2025 20:28:16 +0530 Subject: [PATCH 02/16] lint issues in repl.txt --- .../stats/base/ndarray/range-by/docs/repl.txt | 9 ++++++--- .../base/ndarray/range-by/example/index.js | 19 +++++++++++++------ .../stats/base/ndarray/range-by/package.json | 1 - 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt index 175a7ab8a013..9c6f56f01fb5 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt @@ -1,5 +1,6 @@ {{alias}}( arrays ) - Computes the range of a one-dimensional numeric ndarray via a callback function. + Computes the range of a one-dimensional numeric ndarray via a callback + function. If provided an empty ndarray, the function returns `NaN`. @@ -16,7 +17,8 @@ Examples -------- > function accessor( v ) { return v * 2.0; }; - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); + > var xbuf = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, + ... 4.0, -1.0, -3.0 ] ); > var dt = 'float64'; > var sh = [ xbuf.length ]; > var sx = [ 1 ]; @@ -27,7 +29,8 @@ 18.0 // Using a subset of elements via stride and offset: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, + ... -4.0, 5.0, -6.0 ] ); > var dt = 'float64'; > var sh = [ 3 ]; > var sx = [ 2 ]; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js index 880aa7b6b5af..ce4ff9fc526a 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js @@ -23,18 +23,25 @@ var ndarray = require( '@stdlib/ndarray/base/ctor' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var rangeBy = require( './../lib' ); +/** +* Accessor function. +* +* @private +* @param {number} v - array element +* @returns {number} accessed value +*/ +function accessor( v ) { + return v * 2.0; +} + // Create a data buffer: var xbuf = linspace( -5.0, 5.0, 10 ); // Create an ndarray: var x = new ndarray( 'generic', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); -console.log( ndarray2array( x ) ); - -// Define an accessor function: -function accessor( v ) { - return v * 2.0; -} // Compute the range: var v = rangeBy( [ x, accessor ] ); + +console.log( ndarray2array( x ) ); console.log( 'range: %d', v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json index be12900db7d2..92eec8495a58 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json @@ -17,7 +17,6 @@ "directories": { "benchmark": "./benchmark", "doc": "./docs", - "example": "./example", "lib": "./lib", "test": "./test" }, From e9c07f03bc06fdecc38c623b169c2d084d8feffa Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 10 Nov 2025 20:44:40 +0530 Subject: [PATCH 03/16] fixed lint errors --- .../base/ndarray/range-by/example/index.js | 9 ++-- .../base/ndarray/range-by/examples/index.js | 47 +++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js index ce4ff9fc526a..ab09a8391fe7 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js @@ -22,6 +22,9 @@ var linspace = require( '@stdlib/array/base/linspace' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var rangeBy = require( './../lib' ); +var xbuf; +var x; +var v; /** * Accessor function. @@ -35,13 +38,13 @@ function accessor( v ) { } // Create a data buffer: -var xbuf = linspace( -5.0, 5.0, 10 ); +xbuf = linspace( -5.0, 5.0, 10 ); // Create an ndarray: -var x = new ndarray( 'generic', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); +x = new ndarray( 'generic', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); // Compute the range: -var v = rangeBy( [ x, accessor ] ); +v = rangeBy( [ x, accessor ] ); console.log( ndarray2array( x ) ); console.log( 'range: %d', v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js new file mode 100644 index 000000000000..064592e4c2b0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js @@ -0,0 +1,47 @@ +/** +* @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 linspace = require( '@stdlib/array/base/linspace' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var rangeBy = require( '@stdlib/stats/base/ndarray/range-by/lib' ); + +/** +* Accessor function. +* +* @private +* @param {number} v - array element +* @returns {number} accessed value +*/ +function accessor( v ) { + return v * 2.0; +} + +// Create a data buffer: +var xbuf = linspace( -5.0, 5.0, 10 ); + +// Create an ndarray: +var x = new ndarray( 'generic', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); + +// Compute the range: +var v = rangeBy( [ x, accessor ] ); + +console.log( ndarray2array( x ) ); +console.log( 'range: %d', v ); From e0ab74afd659330da2424ec5a6b588a06e7fa414 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 10 Nov 2025 20:53:47 +0530 Subject: [PATCH 04/16] fixed lint errors --- .../base/ndarray/range-by/example/index.js | 50 ------------------- .../stats/base/ndarray/range-by/lib/main.js | 10 +--- .../stats/base/ndarray/range-by/package.json | 1 + 3 files changed, 3 insertions(+), 58 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js deleted file mode 100644 index ab09a8391fe7..000000000000 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/example/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @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 linspace = require( '@stdlib/array/base/linspace' ); -var ndarray = require( '@stdlib/ndarray/base/ctor' ); -var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var rangeBy = require( './../lib' ); -var xbuf; -var x; -var v; - -/** -* Accessor function. -* -* @private -* @param {number} v - array element -* @returns {number} accessed value -*/ -function accessor( v ) { - return v * 2.0; -} - -// Create a data buffer: -xbuf = linspace( -5.0, 5.0, 10 ); - -// Create an ndarray: -x = new ndarray( 'generic', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - -// Compute the range: -v = rangeBy( [ x, accessor ] ); - -console.log( ndarray2array( x ) ); -console.log( 'range: %d', v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js index 6ef106ca02fb..fa723a4c3322 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js @@ -50,15 +50,9 @@ var strided = require( '@stdlib/stats/strided/range-by' ).ndarray; * // returns 18.0 */ function rangeBy( arrays ) { - var x = arrays[ 0 ]; var clbk = arrays[ 1 ]; - return strided( - numelDimension( x, 0 ), - getData( x ), - getStride( x, 0 ), - getOffset( x ), - clbk - ); + var x = arrays[ 0 ]; + return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ), clbk ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json index 92eec8495a58..4a6a2a348d67 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json @@ -17,6 +17,7 @@ "directories": { "benchmark": "./benchmark", "doc": "./docs", + "example": "./examples", "lib": "./lib", "test": "./test" }, From 94af9466ed77c5c791f51b2cb6853ce2ca0c080c Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 10 Nov 2025 21:26:01 +0530 Subject: [PATCH 05/16] minor lint errors --- .../@stdlib/stats/base/ndarray/range-by/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js index 064592e4c2b0..ce4ff9fc526a 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js @@ -21,7 +21,7 @@ var linspace = require( '@stdlib/array/base/linspace' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var rangeBy = require( '@stdlib/stats/base/ndarray/range-by/lib' ); +var rangeBy = require( './../lib' ); /** * Accessor function. From 2c3848362ca7c322e38a760f9b7e4647e3c6fec1 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Mon, 10 Nov 2025 21:33:12 +0530 Subject: [PATCH 06/16] lint errors fixed --- .../@stdlib/stats/base/ndarray/range-by/test/test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js index ef9c002bc59c..5fa9141ec59d 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js @@ -88,11 +88,13 @@ tape( 'the function calculates the range of a one-dimensional ndarray via a call v = rangeBy( [ vector( x, 2, 1, 0 ), accessor ] ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); + x = []; + x.length = 5; v = rangeBy( [ vector( x, 5, 1, 0 ), accessor ] ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); + x = []; + x.length = 5; x[ 2 ] = 1.0; v = rangeBy( [ vector( x, 5, 1, 0 ), accessor ] ); t.strictEqual( v, 0.0, 'returns expected value' ); From 4265c227c5fdf8e1753d444529ffaa616e4b5833 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Tue, 11 Nov 2025 01:13:03 +0530 Subject: [PATCH 07/16] complete pr rechecked --- .../stats/base/ndarray/range-by/README.md | 75 ++++++-- .../ndarray/range-by/benchmark/benchmark.js | 22 +-- .../stats/base/ndarray/range-by/docs/repl.txt | 48 ++--- .../ndarray/range-by/docs/types/index.d.ts | 69 +++++-- .../base/ndarray/range-by/docs/types/test.ts | 83 +++++--- .../base/ndarray/range-by/examples/index.js | 32 ++-- .../stats/base/ndarray/range-by/lib/index.js | 16 +- .../stats/base/ndarray/range-by/lib/main.js | 40 ++-- .../stats/base/ndarray/range-by/package.json | 12 +- .../stats/base/ndarray/range-by/test/test.js | 177 +++++++++++++----- 10 files changed, 387 insertions(+), 187 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md index ccffc891dcc2..107bd53becbd 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md @@ -1,4 +1,5 @@ # rangeBy -> Compute the range of a one-dimensional ndarray via a callback function. +> Calculate the [range][range] of a one-dimensional ndarray via a callback function.
+The [**range**][range] is defined as the difference between the maximum and minimum values. +
@@ -34,27 +38,58 @@ limitations under the License. var rangeBy = require( '@stdlib/stats/base/ndarray/range-by' ); ``` -#### rangeBy( arrays ) +#### rangeBy( arrays, clbk\[, thisArg ] ) -Computes the range of a one-dimensional ndarray via a callback function. +Computes the [range][range] of a one-dimensional ndarray via a callback function. ```javascript var ndarray = require( '@stdlib/ndarray/base/ctor' ); -function accessor( v ) { - return v * 2.0; +function clbk( value ) { + return value * 2.0; } -var xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; -var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); -var v = rangeBy( [ x, accessor ] ); -// returns 18.0 +var v = rangeBy( [ x ], clbk ); +// returns 6.0 ``` The function has the following parameters: -- **arrays**: array-like object containing a one-dimensional input ndarray and a callback function. +- **arrays**: array-like object containing a one-dimensional input ndarray. +- **clbk**: callback function. +- **thisArg**: callback execution context (_optional_). + +The invoked callback is provided three arguments: + +- **value**: current array element. +- **idx**: current array element index. +- **array**: input ndarray. + +To set the callback execution context, provide a `thisArg`. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +function clbk( value ) { + this.count += 1; + return value * 2.0; +} + +var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +var ctx = { + 'count': 0 +}; + +var v = rangeBy( [ x ], clbk, ctx ); +// returns 6.0 + +var count = ctx.count; +// returns 4 +``` @@ -65,6 +100,8 @@ The function has the following parameters: ## Notes - If provided an empty one-dimensional ndarray, the function returns `NaN`. +- A provided callback function should return a numeric value. +- If a provided callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is **ignored**. @@ -77,24 +114,22 @@ The function has the following parameters: ```javascript -var uniform = require( '@stdlib/random/array/uniform' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var rangeBy = require( '@stdlib/stats/base/ndarray/range-by' ); -function accessor( v ) { - return v * 2.0; +function clbk( value ) { + return value * 2.0; } -var options = { - 'dtype': 'float64' -}; - -var xbuf = uniform( 10, -10.0, 10.0, options ); -var x = new ndarray( options.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +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 = rangeBy( [ x, accessor ] ); +var v = rangeBy( [ x ], clbk ); console.log( v ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js index 790b58bd2a4a..72c9461ea84f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js @@ -25,27 +25,27 @@ 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 rangeBy = require( './../lib' ); +var pkg = require( '@stdlib/stats/base/ndarray/range-by/package.json' ).name; +var rangeBy = require( '@stdlib/stats/base/ndarray/range-by/lib' ); // VARIABLES // var options = { - 'dtype': 'float64' + 'dtype': 'generic' }; // FUNCTIONS // /** -* Accessor function. +* Callback function. * * @private * @param {number} value - array element -* @returns {number} accessed value +* @returns {number} callback result */ -function accessor( value ) { +function clbk( value ) { return value * 2.0; } @@ -66,18 +66,18 @@ function createBenchmark( len ) { return benchmark; function benchmark( b ) { - var y; + var v; var i; b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = rangeBy( [ x, accessor ] ); - if ( isnan( y ) ) { + v = rangeBy( [ x ], clbk ); + if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( isnan( y ) ) { + if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); @@ -106,7 +106,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg+':ndarray:len='+len, f ); + bench( pkg+':len='+len, f ); } } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt index 9c6f56f01fb5..534b9cedfb98 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt @@ -1,44 +1,50 @@ -{{alias}}( arrays ) - Computes the range of a one-dimensional numeric ndarray via a callback + +{{alias}}( arrays, clbk[, thisArg] ) + Computes the maximum value of a one-dimensional ndarray via a callback function. If provided an empty ndarray, the function returns `NaN`. + The callback function is provided three arguments: + + - value: current array element. + - index: current array index. + - array: the input ndarray. + + The callback function should return a numeric value. + + If the callback function does not return any value (or equivalently, + explicitly returns `undefined`), the value is ignored. + Parameters ---------- arrays: ArrayLikeObject Array-like object containing a one-dimensional input ndarray. + clbk: Function + Callback function. + + thisArg: any (optional) + Callback execution context. + Returns ------- out: number - Range. + Maximum value. Examples -------- - > function accessor( v ) { return v * 2.0; }; - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, - ... 4.0, -1.0, -3.0 ] ); - > var dt = 'float64'; + > var xbuf = [ 1.0, -2.0, 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, accessor ] ) - 18.0 - - // Using a subset of elements via stride and offset: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, - ... -4.0, 5.0, -6.0 ] ); - > var dt = 'float64'; - > var sh = [ 3 ]; - > var sx = [ 2 ]; - > var ox = 1; - > var ord = 'row-major'; - > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); - > {{alias}}( [ x, accessor ] ) - 8.0 + > function f ( v ) { return v * 2.0; }; + > {{alias}}( [ x ], f ) + 4.0 See Also -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts index cdf3547229f4..053bae9d9f76 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts @@ -20,29 +20,74 @@ /// -import { ndarray } from '@stdlib/types/ndarray'; +import { typedndarray } from '@stdlib/types/ndarray'; /** -* Computes the range of a one-dimensional numeric ndarray via a callback function. +* Returns the result of callback function. * -* @param arrays - array-like object containing an input ndarray and a callback function -* @returns range +* @returns result +*/ +type Nullary = ( this: ThisArg ) => number | void; + +/** +* Returns the result of callback function. +* +* @param value - current array element +* @returns result +*/ +type Unary = ( this: ThisArg, value: T ) => number | void; + +/** +* Returns the result of callback function. +* +* @param value - current array element +* @param index - current array element index +* @returns result +*/ +type Binary = ( this: ThisArg, value: T, index: number ) => number | void; + +/** +* Returns the result of callback function. +* +* @param value - current array element +* @param index - current array element index +* @param array - input ndarray +* @returns result +*/ +type Ternary = ( this: ThisArg, value: T, index: number, array: U ) => number | void; + +/** +* Returns the result of callback function. +* +* @param value - current array element +* @param index - current array element index +* @param array - input ndarray +* @returns result +*/ +type Callback = Nullary | Unary | Binary | Ternary; + +/** +* Computes the maximum value of a one-dimensional ndarray via a callback function. +* +* @param arrays - array-like object containing an input ndarray +* @param clbk - callback function +* @param thisArg - callback execution context +* @returns maximum value * * @example -* var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/base/ctor' ); * -* function accessor( v ) { -* return v * 2.0; +* function clbk( value ) { +* return value * 2.0; * } * -* var xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); -* var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var v = rangeBy( [ x, accessor ] ); -* // returns 18.0 +* var v = rangeBy( [ x ], clbk ); +* // returns 8.0 */ -declare function rangeBy( arrays: [ ndarray, Function ] ): number; +declare function rangeBy = typedndarray, ThisArg = unknown>( arrays: [ U ], clbk: Callback, thisArg?: ThisParameterType> ): number; // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/test.ts index 443c7f91757c..dc224867370f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/test.ts @@ -18,8 +18,18 @@ /* eslint-disable space-in-parens */ -import zeros = require( '@stdlib/ndarray/zeros' ); // eslint-disable-line import/no-unresolved -import rangeBy = require( './index' ); // eslint-disable-line import/no-unresolved +import zeros = require( '@stdlib/ndarray/zeros' ); +import rangeBy = require( './index' ); + +/** +* Callback function. +* +* @param value - ndarray element +* @returns result +*/ +function clbk( value: any ): number { + return value * 2.0; +} // TESTS // @@ -27,44 +37,67 @@ import rangeBy = require( './index' ); // eslint-disable-line import/no-unresolv // The function returns a number... { const x = zeros( [ 10 ], { - 'dtype': 'float64' + 'dtype': 'generic' }); - function accessor( v: number ): number { - return v * 2.0; - } + rangeBy( [ x ], clbk ); // $ExpectType number + rangeBy( [ x ], clbk, {} ); // $ExpectType number +} - rangeBy( [ x, accessor ] ); // $ExpectType number +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + rangeBy( '10', clbk ); // $ExpectError + rangeBy( 10, clbk ); // $ExpectError + rangeBy( true, clbk ); // $ExpectError + rangeBy( false, clbk ); // $ExpectError + rangeBy( null, clbk ); // $ExpectError + rangeBy( undefined, clbk ); // $ExpectError + rangeBy( [], clbk ); // $ExpectError + rangeBy( {}, clbk ); // $ExpectError + rangeBy( ( x: number ): number => x, clbk ); // $ExpectError + + rangeBy( '10', clbk, {} ); // $ExpectError + rangeBy( 10, clbk, {} ); // $ExpectError + rangeBy( true, clbk, {} ); // $ExpectError + rangeBy( false, clbk, {} ); // $ExpectError + rangeBy( null, clbk, {} ); // $ExpectError + rangeBy( undefined, clbk, {} ); // $ExpectError + rangeBy( [], clbk, {} ); // $ExpectError + rangeBy( {}, clbk, {} ); // $ExpectError + rangeBy( ( x: number ): number => x, clbk, {} ); // $ExpectError } -// The compiler throws an error if the function is provided a first argument which is not an array-like object containing an ndarray and a function... +// The compiler throws an error if the function is provided a second argument which is not a callback function... { const x = zeros( [ 10 ], { - 'dtype': 'float64' + 'dtype': 'generic' }); - rangeBy( '10' ); // $ExpectError - rangeBy( 10 ); // $ExpectError - rangeBy( true ); // $ExpectError - rangeBy( false ); // $ExpectError - rangeBy( null ); // $ExpectError - rangeBy( undefined ); // $ExpectError - rangeBy( [] ); // $ExpectError - rangeBy( [ x ] ); // $ExpectError - rangeBy( {} ); // $ExpectError - rangeBy( ( x: number ): number => x ); // $ExpectError + rangeBy( [ x ], '10' ); // $ExpectError + rangeBy( [ x ], 10 ); // $ExpectError + rangeBy( [ x ], true ); // $ExpectError + rangeBy( [ x ], false ); // $ExpectError + rangeBy( [ x ], null ); // $ExpectError + rangeBy( [ x ], undefined ); // $ExpectError + rangeBy( [ x ], [] ); // $ExpectError + rangeBy( [ x ], {} ); // $ExpectError + + rangeBy( [ x ], '10', {} ); // $ExpectError + rangeBy( [ x ], 10, {} ); // $ExpectError + rangeBy( [ x ], true, {} ); // $ExpectError + rangeBy( [ x ], false, {} ); // $ExpectError + rangeBy( [ x ], null, {} ); // $ExpectError + rangeBy( [ x ], undefined, {} ); // $ExpectError + rangeBy( [ x ], [], {} ); // $ExpectError + rangeBy( [ x ], {}, {} ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { const x = zeros( [ 10 ], { - 'dtype': 'float64' + 'dtype': 'generic' }); - function accessor( v: number ): number { - return v * 2.0; - } - rangeBy(); // $ExpectError - rangeBy( [ x, accessor ], {} ); // $ExpectError + rangeBy( [ x ], clbk, {}, {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js index ce4ff9fc526a..a968ca080441 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js @@ -18,30 +18,20 @@ 'use strict'; -var linspace = require( '@stdlib/array/base/linspace' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var rangeBy = require( './../lib' ); +var rangeBy = require( '@stdlib/stats/base/ndarray/range-by/lib' ); -/** -* Accessor function. -* -* @private -* @param {number} v - array element -* @returns {number} accessed value -*/ -function accessor( v ) { - return v * 2.0; +function clbk( value ) { + return value * 2.0; } -// Create a data buffer: -var xbuf = linspace( -5.0, 5.0, 10 ); - -// Create an ndarray: -var x = new ndarray( 'generic', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - -// Compute the range: -var v = rangeBy( [ x, accessor ] ); - +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); console.log( ndarray2array( x ) ); -console.log( 'range: %d', v ); + +var v = rangeBy( [ x ], clbk ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js index 27ad90a43756..055bfd2850a4 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Compute the range of an ndarray via a callback function. +* Compute the range of a one-dimensional ndarray via a callback function. * * @module @stdlib/stats/base/ndarray/range-by * @@ -27,20 +27,20 @@ * var ndarray = require( '@stdlib/ndarray/base/ctor' ); * var rangeBy = require( '@stdlib/stats/base/ndarray/range-by' ); * -* function accessor( v ) { -* return v * 2.0; +* function clbk( value ) { +* return value * 2.0; * } * -* var xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; -* var x = new ndarray( 'generic', xbuf, [ 8 ], [ 1 ], 0, 'row-major' ); +* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var v = rangeBy( [ x, accessor ] ); -* // returns 18.0 +* var v = rangeBy( [ x ], clbk ); +* // returns 8.0 */ // MODULES // -var main = require( './main.js' ); +var main = require( '@stdlib/stats/base/ndarray/range-by/lib/main.js' ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js index fa723a4c3322..c720ee2e71ea 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js @@ -30,29 +30,43 @@ var strided = require( '@stdlib/stats/strided/range-by' ).ndarray; // MAIN // /** -* Computes the range of a one-dimensional numeric ndarray via a callback function. +* Computes the maximum value of a one-dimensional ndarray via a callback function. * -* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray and a callback function -* @returns {number} range +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray +* @param {Function} clbk - callback function +* @param {*} [thisArg] - callback execution context +* @returns {number} maximum value * * @example -* var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/base/ctor' ); * -* function accessor( v ) { -* return v * 2.0; +* function clbk( value ) { +* return value * 2.0; * } * -* var xbuf = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); -* var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * -* var v = rangeBy( [ x, accessor ] ); -* // returns 18.0 +* var v = rangeBy( [ x ], clbk ); +* // returns 8.0 */ -function rangeBy( arrays ) { - var clbk = arrays[ 1 ]; +function rangeBy( arrays, clbk, thisArg ) { var x = arrays[ 0 ]; - return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ), clbk ); // eslint-disable-line max-len + return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ), wrapper, null ); // eslint-disable-line max-len + + /** + * Invokes a provided callback. + * + * @private + * @param {*} value - current array element + * @param {NonNegativeInteger} aidx - current array element index + * @param {NonNegativeInteger} sidx - current strided array element index + * @param {Collection} arr - input array + * @returns {*} result + */ + function wrapper( value, aidx ) { + return clbk.call( thisArg, value, aidx, x ); + } } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json index 4a6a2a348d67..da6c5126ef60 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/base/ndarray/range-by", "version": "0.0.0", - "description": "Compute the range of an ndarray via a callback function.", + "description": "Compute the maximum value of a one-dimensional ndarray via a callback function.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -55,13 +55,13 @@ "stats", "mathematics", "math", + "maximum", + "max", "range", - "ndarray", - "callback", - "accessor", - "extent", + "extremes", "domain", - "spread" + "extent", + "ndarray" ], "__stdlib__": {} } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js index 5fa9141ec59d..e4056f3319a2 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/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 rangeBy = require( './../lib' ); +var rangeBy = require( '@stdlib/stats/base/ndarray/range-by/lib' ); // FUNCTIONS // @@ -43,13 +43,6 @@ function vector( buffer, length, stride, offset ) { return new ndarray( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); } -function accessor( v ) { - if ( v === void 0 ) { - return; - } - return v * 2.0; -} - // TESTS // @@ -59,50 +52,59 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function has an arity of 1', function test( t ) { - t.strictEqual( rangeBy.length, 1, 'has expected arity' ); +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( rangeBy.length, 3, 'has expected arity' ); t.end(); }); -tape( 'the function calculates the range of a one-dimensional ndarray via a callback function', function test( t ) { +tape( 'the function calculates the maximum value of a one-dimensional ndarray via a callback function', function test( t ) { var x; var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; - v = rangeBy( [ vector( x, 6, 1, 0 ), accessor ] ); - t.strictEqual( v, 18.0, 'returns expected value' ); + v = rangeBy( [ vector( x, 6, 1, 0 ) ], clbk ); + t.strictEqual( v, 10.0, 'returns expected value' ); x = [ -4.0, -5.0 ]; - v = rangeBy( [ vector( x, 2, 1, 0 ), accessor ] ); - t.strictEqual( v, 2.0, 'returns expected value' ); + v = rangeBy( [ vector( x, 2, 1, 0 ) ], clbk ); + t.strictEqual( v, -8.0, 'returns expected value' ); x = [ -0.0, 0.0, -0.0 ]; - v = rangeBy( [ vector( x, 3, 1, 0 ), accessor ] ); + v = rangeBy( [ vector( x, 3, 1, 0 ) ], clbk ); t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); x = [ NaN ]; - v = rangeBy( [ vector( x, 1, 1, 0 ), accessor ] ); + v = rangeBy( [ vector( x, 1, 1, 0 ) ], clbk ); t.strictEqual( isnan( v ), true, 'returns expected value' ); x = [ NaN, NaN ]; - v = rangeBy( [ vector( x, 2, 1, 0 ), accessor ] ); + v = rangeBy( [ vector( x, 2, 1, 0 ) ], clbk ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = []; - x.length = 5; - v = rangeBy( [ vector( x, 5, 1, 0 ), accessor ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.end(); + + function clbk( v ) { + return v * 2.0; + } +}); + +tape( 'if provided an empty vector, the function returns `NaN`', function test( t ) { + var x; + var v; x = []; - x.length = 5; - x[ 2 ] = 1.0; - v = rangeBy( [ vector( x, 5, 1, 0 ), accessor ] ); - t.strictEqual( v, 0.0, 'returns expected value' ); + + v = rangeBy( [ vector( x, 0, 1, 0 ) ], clbk ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); + + function clbk( v ) { + return v * 2.0; + } }); -tape( 'the function supports non-unit strides', function test( t ) { +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { var x; var v; @@ -116,12 +118,18 @@ tape( 'the function supports non-unit strides', function test( t ) { 4.0, // 3 2.0 ]; - v = rangeBy( [ vector( x, 4, 2, 0 ), accessor ] ); - t.strictEqual( v, 12.0, 'returns expected value' ); + + v = rangeBy( [ vector( x, 4, 2, 0 ) ], clbk ); + + t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); + + function clbk( v ) { + return v * 2.0; + } }); -tape( 'the function supports negative strides', function test( t ) { +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { var x; var v; @@ -135,38 +143,107 @@ tape( 'the function supports negative strides', function test( t ) { 4.0, // 0 2.0 ]; - v = rangeBy( [ vector( x, 4, -2, 6 ), accessor ] ); - t.strictEqual( v, 12.0, 'returns expected value' ); + + v = rangeBy( [ vector( x, 4, -2, 6 ) ], clbk ); + + t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); + + function clbk( v ) { + return v * 2.0; + } }); -tape( 'the function supports non-zero offsets', function test( t ) { +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { var x; var v; x = [ - 1.0, - -2.0, // 0 + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 3.0, - 4.0, // 1 - 5.0, - -6.0 // 2 + 4.0 // 3 ]; - v = rangeBy( [ vector( x, 3, 2, 1 ), accessor ] ); - t.strictEqual( v, 20.0, 'returns expected value' ); - t.end(); -}); -tape( 'if provided an empty array, the function returns `NaN`', function test( t ) { - var x = []; - var v = rangeBy( [ vector( x, 0, 1, 0 ), accessor ] ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); + v = rangeBy( [ vector( x, 4, 2, 1 ) ], clbk ); + t.strictEqual( v, 8.0, 'returns expected value' ); + t.end(); + + function clbk( v ) { + return v * 2.0; + } }); -tape( 'if provided a single element, the function returns `0`', function test( t ) { - var x = [ 5.0 ]; - var v = rangeBy( [ vector( x, 1, 1, 0 ), accessor ] ); - t.strictEqual( v, 0.0, 'returns expected value' ); +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var ctx; + var arr; + 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 + ]; + ctx = { + 'count': 0 + }; + + indices = []; + values = []; + arrays = []; + + arr = vector( x, 4, 2, 0 ); + v = rangeBy( [ arr ], clbk, ctx ); + + t.strictEqual( v, 8.0, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + expected = [ + 1.0, + 2.0, + -2.0, + 4.0 + ]; + t.deepEqual( values, expected, 'returns expected value' ); + + expected = [ + 0, + 1, + 2, + 3 + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + arr, + arr, + arr, + arr + ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + t.end(); + + function clbk( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + values.push( v ); + indices.push( idx ); + arrays.push( arr ); + return v * 2.0; + } }); From 38ffbcf477d13fc61fc87e77fadd806d617abb93 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Tue, 11 Nov 2025 01:31:42 +0530 Subject: [PATCH 08/16] fix lint errors --- .../@stdlib/stats/base/ndarray/range-by/README.md | 2 ++ .../stats/base/ndarray/range-by/docs/repl.txt | 7 +++---- .../base/ndarray/range-by/docs/types/index.d.ts | 6 +++--- .../stats/base/ndarray/range-by/lib/index.js | 4 ++-- .../stats/base/ndarray/range-by/test/test.js | 14 +++++++------- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md index 107bd53becbd..f7394c6de2ca 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/README.md @@ -149,6 +149,8 @@ console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt index 534b9cedfb98..2d88834ef235 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/repl.txt @@ -1,7 +1,6 @@ {{alias}}( arrays, clbk[, thisArg] ) - Computes the maximum value of a one-dimensional ndarray via a callback - function. + Computes the range of a one-dimensional ndarray via a callback function. If provided an empty ndarray, the function returns `NaN`. @@ -30,7 +29,7 @@ Returns ------- out: number - Maximum value. + Range. Examples -------- @@ -43,7 +42,7 @@ > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); > function f ( v ) { return v * 2.0; }; > {{alias}}( [ x ], f ) - 4.0 + 8.0 See Also -------- diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts index 053bae9d9f76..234c56a7b4f0 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts @@ -67,12 +67,12 @@ type Ternary = ( this: ThisArg, value: T, index: number, array: U type Callback = Nullary | Unary | Binary | Ternary; /** -* Computes the maximum value of a one-dimensional ndarray via a callback function. +* Computes the range of a one-dimensional ndarray via a callback function. * * @param arrays - array-like object containing an input ndarray * @param clbk - callback function * @param thisArg - callback execution context -* @returns maximum value +* @returns range * * @example * var ndarray = require( '@stdlib/ndarray/base/ctor' ); @@ -85,7 +85,7 @@ type Callback = Nullary | Unary | Binary = typedndarray, ThisArg = unknown>( arrays: [ U ], clbk: Callback, thisArg?: ThisParameterType> ): number; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js index 055bfd2850a4..51cb4a91c69f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/index.js @@ -35,12 +35,12 @@ * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = rangeBy( [ x ], clbk ); -* // returns 8.0 +* // returns 6.0 */ // MODULES // -var main = require( '@stdlib/stats/base/ndarray/range-by/lib/main.js' ); +var main = require( './main.js' ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js index e4056f3319a2..2f2d91aacd0b 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js @@ -57,17 +57,17 @@ tape( 'the function has an arity of 3', function test( t ) { t.end(); }); -tape( 'the function calculates the maximum value of a one-dimensional ndarray via a callback function', function test( t ) { +tape( 'the function calculates the range of a one-dimensional ndarray via a callback function', function test( t ) { var x; var v; x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; v = rangeBy( [ vector( x, 6, 1, 0 ) ], clbk ); - t.strictEqual( v, 10.0, 'returns expected value' ); + t.strictEqual( v, 18.0, 'returns expected value' ); x = [ -4.0, -5.0 ]; v = rangeBy( [ vector( x, 2, 1, 0 ) ], clbk ); - t.strictEqual( v, -8.0, 'returns expected value' ); + t.strictEqual( v, 2.0, 'returns expected value' ); x = [ -0.0, 0.0, -0.0 ]; v = rangeBy( [ vector( x, 3, 1, 0 ) ], clbk ); @@ -121,7 +121,7 @@ tape( 'the function supports one-dimensional ndarrays having non-unit strides', v = rangeBy( [ vector( x, 4, 2, 0 ) ], clbk ); - t.strictEqual( v, 8.0, 'returns expected value' ); + t.strictEqual( v, 12.0, 'returns expected value' ); t.end(); function clbk( v ) { @@ -146,7 +146,7 @@ tape( 'the function supports one-dimensional ndarrays having negative strides', v = rangeBy( [ vector( x, 4, -2, 6 ) ], clbk ); - t.strictEqual( v, 8.0, 'returns expected value' ); + t.strictEqual( v, 12.0, 'returns expected value' ); t.end(); function clbk( v ) { @@ -170,7 +170,7 @@ tape( 'the function supports one-dimensional ndarrays having non-zero offsets', ]; v = rangeBy( [ vector( x, 4, 2, 1 ) ], clbk ); - t.strictEqual( v, 8.0, 'returns expected value' ); + t.strictEqual( v, 12.0, 'returns expected value' ); t.end(); @@ -210,7 +210,7 @@ tape( 'the function supports providing an execution context', function test( t ) arr = vector( x, 4, 2, 0 ); v = rangeBy( [ arr ], clbk, ctx ); - t.strictEqual( v, 8.0, 'returns expected value' ); + t.strictEqual( v, 12.0, 'returns expected value' ); t.strictEqual( ctx.count, 4, 'returns expected value' ); expected = [ From ff029cf03e59f64864fcb78ee98ca467b0e1bf03 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Tue, 11 Nov 2025 01:36:46 +0530 Subject: [PATCH 09/16] lint errors fixed --- .../@stdlib/stats/base/ndarray/range-by/lib/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js index c720ee2e71ea..434269cd13fe 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js @@ -30,12 +30,12 @@ var strided = require( '@stdlib/stats/strided/range-by' ).ndarray; // MAIN // /** -* Computes the maximum value of a one-dimensional ndarray via a callback function. +* Computes the range of a one-dimensional ndarray via a callback function. * * @param {ArrayLikeObject} arrays - array-like object containing an input ndarray * @param {Function} clbk - callback function * @param {*} [thisArg] - callback execution context -* @returns {number} maximum value +* @returns {number} range * * @example * var ndarray = require( '@stdlib/ndarray/base/ctor' ); @@ -48,7 +48,7 @@ var strided = require( '@stdlib/stats/strided/range-by' ).ndarray; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = rangeBy( [ x ], clbk ); -* // returns 8.0 +* // returns 6 */ function rangeBy( arrays, clbk, thisArg ) { var x = arrays[ 0 ]; From cc57bfdfa7b126d2dca4cf024aad232cae34e60e Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Tue, 11 Nov 2025 01:41:33 +0530 Subject: [PATCH 10/16] lint errors fixed --- .../@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts | 2 +- .../@stdlib/stats/base/ndarray/range-by/lib/main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts index 234c56a7b4f0..15583e259189 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts @@ -85,7 +85,7 @@ type Callback = Nullary | Unary | Binary = typedndarray, ThisArg = unknown>( arrays: [ U ], clbk: Callback, thisArg?: ThisParameterType> ): number; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js index 434269cd13fe..89abe5be4554 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/lib/main.js @@ -48,7 +48,7 @@ var strided = require( '@stdlib/stats/strided/range-by' ).ndarray; * var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); * * var v = rangeBy( [ x ], clbk ); -* // returns 6 +* // returns 6.0 */ function rangeBy( arrays, clbk, thisArg ) { var x = arrays[ 0 ]; From 0ddfd8a6a1e58f7091d3f816936cc9a7d04abb0d Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Tue, 11 Nov 2025 01:47:38 +0530 Subject: [PATCH 11/16] minor lint errors --- .../@stdlib/stats/base/ndarray/range-by/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js index a968ca080441..75e9aa76bcce 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/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 rangeBy = require( '@stdlib/stats/base/ndarray/range-by/lib' ); +var rangeBy = require( './../lib' ); function clbk( value ) { return value * 2.0; From 6955b0d8664f31439d35a6e9a1d3f3235c5b59cf Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Tue, 11 Nov 2025 01:55:24 +0530 Subject: [PATCH 12/16] benchmark tested --- .../@stdlib/stats/base/ndarray/range-by/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js index 2f2d91aacd0b..6bd4b4f85ac8 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/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 rangeBy = require( '@stdlib/stats/base/ndarray/range-by/lib' ); +var rangeBy = require( './../lib' ); // FUNCTIONS // From e1b62a814135fd986225c5e787ea1c843e9c7370 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Tue, 11 Nov 2025 02:01:57 +0530 Subject: [PATCH 13/16] fixed lint errors --- .../stats/base/ndarray/range-by/benchmark/benchmark.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js index 72c9461ea84f..bbf0300f7a6f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/benchmark/benchmark.js @@ -25,8 +25,8 @@ 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( '@stdlib/stats/base/ndarray/range-by/package.json' ).name; -var rangeBy = require( '@stdlib/stats/base/ndarray/range-by/lib' ); +var pkg = require( './../package.json' ).name; +var rangeBy = require( './../lib' ); // VARIABLES // From f155b4140e54a1600ef1c24542edc8f7754c6c8f Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 12 Nov 2025 17:30:47 -0800 Subject: [PATCH 14/16] docs: update descriptions Signed-off-by: Athan --- .../stats/base/ndarray/range-by/docs/types/index.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts index 15583e259189..f058dd96a7c6 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/docs/types/index.d.ts @@ -23,14 +23,14 @@ import { typedndarray } from '@stdlib/types/ndarray'; /** -* Returns the result of callback function. +* Callback function applied to each element of an ndarray. * * @returns result */ type Nullary = ( this: ThisArg ) => number | void; /** -* Returns the result of callback function. +* Callback function applied to each element of an ndarray. * * @param value - current array element * @returns result @@ -38,7 +38,7 @@ type Nullary = ( this: ThisArg ) => number | void; type Unary = ( this: ThisArg, value: T ) => number | void; /** -* Returns the result of callback function. +* Callback function applied to each element of an ndarray. * * @param value - current array element * @param index - current array element index @@ -47,7 +47,7 @@ type Unary = ( this: ThisArg, value: T ) => number | void; type Binary = ( this: ThisArg, value: T, index: number ) => number | void; /** -* Returns the result of callback function. +* Callback function applied to each element of an ndarray. * * @param value - current array element * @param index - current array element index @@ -57,7 +57,7 @@ type Binary = ( this: ThisArg, value: T, index: number ) => number | type Ternary = ( this: ThisArg, value: T, index: number, array: U ) => number | void; /** -* Returns the result of callback function. +* Callback function applied to each element of an ndarray. * * @param value - current array element * @param index - current array element index From caa30c11e098b986cc9a1ca8561d110048ff9c18 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 12 Nov 2025 17:33:31 -0800 Subject: [PATCH 15/16] docs: fix description Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/range-by/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json index da6c5126ef60..5b47ff1e1dca 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/stats/base/ndarray/range-by", "version": "0.0.0", - "description": "Compute the maximum value of a one-dimensional ndarray via a callback function.", + "description": "Compute the range of a one-dimensional ndarray via a callback function.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From e2a69330c9139bd99e6c12cca5e0acbf6172f8fc Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 12 Nov 2025 17:34:17 -0800 Subject: [PATCH 16/16] chore: update keywords Signed-off-by: Athan --- .../@stdlib/stats/base/ndarray/range-by/package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json index 5b47ff1e1dca..12ea6de04712 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range-by/package.json @@ -57,6 +57,8 @@ "math", "maximum", "max", + "minimum", + "min", "range", "extremes", "domain",