From f39b0a8c13a8c6e33e5cf17f43dc35eefd12fd21 Mon Sep 17 00:00:00 2001 From: Om-A-osc Date: Sat, 14 Feb 2026 17:08:39 +0530 Subject: [PATCH 1/6] feat: add `stats/array/nanmidrange-by` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../stats/array/nanmidrange-by/README.md | 152 +++++++++ .../nanmidrange-by/benchmark/benchmark.js | 115 +++++++ .../stats/array/nanmidrange-by/docs/repl.txt | 44 +++ .../nanmidrange-by/docs/types/index.d.ts | 97 ++++++ .../array/nanmidrange-by/docs/types/test.ts | 76 +++++ .../array/nanmidrange-by/examples/index.js | 36 +++ .../stats/array/nanmidrange-by/lib/index.js | 46 +++ .../stats/array/nanmidrange-by/lib/main.js | 78 +++++ .../stats/array/nanmidrange-by/package.json | 73 +++++ .../stats/array/nanmidrange-by/test/test.js | 292 ++++++++++++++++++ 10 files changed, 1009 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/array/nanmidrange-by/README.md create mode 100644 lib/node_modules/@stdlib/stats/array/nanmidrange-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/array/nanmidrange-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/array/nanmidrange-by/package.json create mode 100644 lib/node_modules/@stdlib/stats/array/nanmidrange-by/test/test.js diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/README.md b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/README.md new file mode 100644 index 000000000000..7652262a80db --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/README.md @@ -0,0 +1,152 @@ + + +# nanmidrangeBy + +> Calculate the [midrange][midrange] of an array via a callback function, ignoring `NaN` values. + +
+ +The [**midrange**][midrange] is defined as the arithmetic mean of the maximum and minimum values. + +
+ + + +
+ +## Usage + +```javascript +var nanmidrangeBy = require( '@stdlib/stats/array/nanmidrange-by' ); +``` + +#### nanmidrangeBy( x, clbk\[, thisArg] ) + +Computes the [midrange][midrange] of an array via a callback function, ignoring `NaN` values. + +```javascript +function accessor( v ) { + return v * 2.0; +} + +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ]; + +var v = nanmidrangeBy( x, accessor ); +// returns -1.0 +``` + +The function has the following parameters: + +- **x**: input array. +- **clbk**: callback function. +- **thisArg**: execution context (_optional_). + +The invoked callback is provided three arguments: + +- **value**: current array element. +- **index**: current array index. +- **array**: input array. + +To set the callback execution context, provide a `thisArg`. + +```javascript +function accessor( v ) { + this.count += 1; + return v * 2.0; +} + +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ]; + +var context = { + 'count': 0 +}; + +var v = nanmidrangeBy( x, accessor, context ); +// returns -1.0 + +var cnt = context.count; +// returns 9 +``` + +
+ + + +
+ +## Notes + +- If provided an empty array, 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**. +- The function supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var nanmidrangeBy = require( '@stdlib/stats/array/nanmidrange-by' ); + +function accessor( v ) { + return v * 2.0; +} + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +x[ 2 ] = NaN; +console.log( x ); + +var v = nanmidrangeBy( x, accessor ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/benchmark/benchmark.js new file mode 100644 index 000000000000..bc2d532f694e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/benchmark/benchmark.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var nanmidrangeBy = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// 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 x = uniform( len, -10, 10, options ); + x[ 0 ] = NaN; // Ensure at least one NaN + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = nanmidrangeBy( x, accessor ); + if ( len > 1 && isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( len > 1 && 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( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt new file mode 100644 index 000000000000..e222f86e65f4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt @@ -0,0 +1,44 @@ + +{{alias}}( x, clbk[, thisArg] ) + Computes the midrange of an array via a callback function, + ignoring NaN values. + + If provided an empty array, the function returns `NaN`. + + The callback function is provided three arguments: + + - value: current array element. + - index: current array index. + - array: the input array. + + 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 + ---------- + x: Array|TypedArray + Input array. + + clbk: Function + Callback function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: number + Midrange. + + Examples + -------- + > function accessor( v ) { return v * 2.0; }; + > var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, -1.0, -3.0 ]; + > {{alias}}( x, accessor ) + -1.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/types/index.d.ts new file mode 100644 index 000000000000..2fb96c8481ac --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/types/index.d.ts @@ -0,0 +1,97 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Returns an accessed value. +* +* @returns accessed value +*/ +type Nullary = ( this: ThisArg ) => number | void; + +/** +* Returns an accessed value. +* +* @param value - current array element +* @returns accessed value +*/ +type Unary = ( this: ThisArg, value: T ) => number | void; + +/** +* Returns an accessed value. +* +* @param value - current array element +* @param index - current array index +* @returns accessed value +*/ +type Binary = ( this: ThisArg, value: T, index: number ) => number | void; + +/** +* Returns an accessed value. +* +* @param value - current array element +* @param index - current array index +* @param array - input array +* @returns accessed value +*/ +type Ternary = ( this: ThisArg, value: T, index: number, array: U ) => number | void; + +/** +* Returns an accessed value. +* +* @param value - current array element +* @param index - current array index +* @param array - input array +* @returns accessed value +*/ +type Callback = Nullary | Unary | Binary | Ternary; + +/** +* Computes the midrange of an array via a callback function, ignoring `NaN` values. +* +* @param x - input array +* @param clbk - callback +* @param thisArg - execution context +* @returns midrange +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ]; +* +* function accessor( v ) { +* return v * 2.0; +* } +* +* var v = nanmidrangeBy( x, accessor ); +* // returns -1.0 +*/ +declare function nanmidrangeBy = InputArray, ThisArg = unknown>( x: U, clbk: Callback, thisArg?: ThisParameterType> ): number; + + +// EXPORTS // + +export = nanmidrangeBy; diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/types/test.ts b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/types/test.ts new file mode 100644 index 000000000000..e8113575a771 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/types/test.ts @@ -0,0 +1,76 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import AccessorArray = require( '@stdlib/array/base/accessor' ); +import nanmidrangeBy = require( './index' ); + +/** +* Accessor function. +* +* @returns accessed value +*/ +function accessor(): number { + return 5.0; +} + + +// TESTS // + +// The function returns a number... +{ + const x = new Float64Array( 10 ); + + nanmidrangeBy( x, accessor ); // $ExpectType number + nanmidrangeBy( new AccessorArray( x ), accessor ); // $ExpectType number + + nanmidrangeBy( x, accessor, {} ); // $ExpectType number + nanmidrangeBy( new AccessorArray( x ), accessor, {} ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + nanmidrangeBy( 10, accessor ); // $ExpectError + nanmidrangeBy( true, accessor ); // $ExpectError + nanmidrangeBy( false, accessor ); // $ExpectError + nanmidrangeBy( null, accessor ); // $ExpectError + nanmidrangeBy( undefined, accessor ); // $ExpectError + nanmidrangeBy( {}, accessor ); // $ExpectError + nanmidrangeBy( ( x: number ): number => x, accessor ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a function... +{ + const x = new Float64Array( 10 ); + + nanmidrangeBy( x, '10' ); // $ExpectError + nanmidrangeBy( x, true ); // $ExpectError + nanmidrangeBy( x, false ); // $ExpectError + nanmidrangeBy( x, null ); // $ExpectError + nanmidrangeBy( x, undefined ); // $ExpectError + nanmidrangeBy( x, [] ); // $ExpectError + nanmidrangeBy( x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + nanmidrangeBy(); // $ExpectError + nanmidrangeBy( x ); // $ExpectError + nanmidrangeBy( x, accessor, {}, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/examples/index.js b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/examples/index.js new file mode 100644 index 000000000000..f08e1e705640 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var nanmidrangeBy = require( './../lib' ); + +function accessor( v ) { + return v * 2.0; +} + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +x[ 2 ] = NaN; +x[ 5 ] = NaN; +console.log( x ); + +var v = nanmidrangeBy( x, accessor ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js new file mode 100644 index 000000000000..68b4857f12e1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Calculate the midrange of an array via a callback function, ignoring NaN values. +* +* @module @stdlib/stats/array/nanmidrange-by +* +* @example +* var nanmidrangeBy = require( '@stdlib/stats/array/nanmidrange-by' ); +* +* function accessor( v ) { +* return v * 2.0; +* } +* +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ]; +* +* var v = nanmidrangeBy( x, accessor ); +* // returns -1.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// MAIN // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/main.js b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/main.js new file mode 100644 index 000000000000..0a00a3ffbffd --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/main.js @@ -0,0 +1,78 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isCollection = require( '@stdlib/assert/is-collection' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var strided = require( '@stdlib/stats/strided/nanmidrange-by' ).ndarray; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Computes the midrange of an array via a callback function, ignoring `NaN` values. +* +* @param {Collection} x - input array +* @param {Callback} clbk - callback +* @param {*} [thisArg] - execution context +* @throws {TypeError} first argument must be an array-like object +* @throws {TypeError} second argument must be a function +* @returns {number} midrange +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ]; +* +* function accessor( v ) { +* return v * 2.0; +* } +* +* var v = nanmidrangeBy( x, accessor ); +* // returns -1.0 +*/ +function nanmidrangeBy( x, clbk, thisArg ) { + if ( !isCollection( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) ); + } + if ( !isFunction( clbk ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) ); + } + return strided( x.length, x, 1, 0, wrapper ); + + /** + * Invokes a provided callback. + * + * @private + * @param {*} value - current element + * @param {NonNegativeInteger} aidx - current array index + * @param {NonNegativeInteger} sidx - current strided index + * @param {Collection} arr - input array + * @returns {number} callback return value + */ + function wrapper( value, aidx, sidx, arr ) { + return clbk.call( thisArg, value, aidx, arr ); + } +} + + +// EXPORTS // + +module.exports = nanmidrangeBy; diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/package.json b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/package.json new file mode 100644 index 000000000000..c0f8429fe767 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/array/nanmidrange-by", + "version": "0.0.0", + "description": "Calculate the midrange of an array via a callback function, ignoring NaN values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "maximum", + "max", + "minimum", + "min", + "midrange", + "range", + "extremes", + "dispersion", + "domain", + "extent", + "array", + "nan", + "ignore" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/test/test.js b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/test/test.js new file mode 100644 index 000000000000..3f5cebf5c92e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/test/test.js @@ -0,0 +1,292 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var isSameArray = require( '@stdlib/assert/is-same-array' ); +var nanmidrangeBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Accessor function. +* +* @private +* @param {number} v - value +* @returns {(number|void)} result +*/ +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 nanmidrangeBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( nanmidrangeBy.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + nanmidrangeBy( value, accessor ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { + var values; + var i; + var x; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + [], + {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + nanmidrangeBy( x, value ); + }; + } +}); + +tape( 'the function calculates the midrange of an array via a callback function, ignoring NaN values', function test( t ) { + var x; + var v; + + x = [ 1.0, NaN, -2.0, -4.0, 5.0, 0.0, NaN, 3.0 ]; + v = nanmidrangeBy( x, accessor ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + v = nanmidrangeBy( x, accessor ); + t.strictEqual( v, -9.0, 'returns expected value' ); + + x = [ -0.0, NaN, 0.0, -0.0 ]; + v = nanmidrangeBy( x, accessor ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = nanmidrangeBy( x, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = nanmidrangeBy( x, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the midrange of an array via a callback function (accessors), ignoring NaN values', function test( t ) { + var x; + var v; + + x = [ 1.0, NaN, -2.0, -4.0, 5.0, 0.0, NaN, 3.0 ]; + v = nanmidrangeBy( toAccessorArray( x ), accessor ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + v = nanmidrangeBy( toAccessorArray( x ), accessor ); + t.strictEqual( v, -9.0, 'returns expected value' ); + + x = [ -0.0, NaN, 0.0, -0.0 ]; + v = nanmidrangeBy( toAccessorArray( x ), accessor ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = nanmidrangeBy( toAccessorArray( x ), accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = nanmidrangeBy( toAccessorArray( x ), accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the midrange of an array (array-like object), ignoring NaN values', function test( t ) { + var x; + var v; + + x = { + 'length': 8, + '0': 1.0, + '1': NaN, + '2': -2.0, + '3': -4.0, + '4': 5.0, + '5': 0.0, + '6': NaN, + '7': 3.0 + }; + v = nanmidrangeBy( x, accessor ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a callback execution context', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var ctx; + var x; + + x = [ 1.0, NaN, 2.0, 3.0, 4.0, 5.0 ]; + ctx = { + 'count': 0 + }; + indices = []; + values = []; + arrays = []; + nanmidrangeBy( x, accessor, ctx ); + + t.strictEqual( ctx.count, x.length, 'returns expected value' ); + + expected = [ 0, 1, 2, 3, 4, 5 ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ 1.0, NaN, 2.0, 3.0, 4.0, 5.0 ]; + t.strictEqual( isSameArray( values, expected ), true, 'returns expected value' ); + + expected = [ x, x, x, x, x, x ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + t.end(); + + function accessor( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + indices.push( idx ); + values.push( v ); + arrays.push( arr ); + return v * 2.0; + } +}); + +tape( 'the function supports providing a callback execution context (accessors)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var ctx; + var ax; + var x; + + x = [ 1.0, NaN, 2.0, 3.0, 4.0, 5.0 ]; + ax = toAccessorArray( x ); + ctx = { + 'count': 0 + }; + indices = []; + values = []; + arrays = []; + nanmidrangeBy( ax, accessor, ctx ); + + t.strictEqual( ctx.count, x.length, 'returns expected value' ); + + expected = [ 0, 1, 2, 3, 4, 5 ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ 1.0, NaN, 2.0, 3.0, 4.0, 5.0 ]; + t.strictEqual( isSameArray( values, expected ), true, 'returns expected value' ); + + expected = [ ax, ax, ax, ax, ax, ax ]; + t.deepEqual( arrays, expected, 'returns expected value' ); + t.end(); + + function accessor( v, idx, arr ) { + this.count += 1; // eslint-disable-line no-invalid-this + indices.push( idx ); + values.push( v ); + arrays.push( arr ); + return v * 2.0; + } +}); + +tape( 'if provided an empty array, the function returns `NaN`', function test( t ) { + var v = nanmidrangeBy( [], accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an empty array, the function returns `NaN` (accessors)', function test( t ) { + var v = nanmidrangeBy( toAccessorArray( [] ), accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an array containing a single element, the function returns the result of applying a provided callback function to that element', function test( t ) { + var v = nanmidrangeBy( [ 1.0 ], accessor ); + t.strictEqual( v, 2.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an array containing a single element, the function returns the result of applying a provided callback function to that element (accessors)', function test( t ) { + var v = nanmidrangeBy( toAccessorArray( [ 1.0 ] ), accessor ); + t.strictEqual( v, 2.0, 'returns expected value' ); + t.end(); +}); From 7d9509ab19b252b85f1a0e32d1b85954f42f9e71 Mon Sep 17 00:00:00 2001 From: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> Date: Sat, 14 Feb 2026 20:46:26 +0530 Subject: [PATCH 2/6] Update documentation to use backticks for NaN Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> --- .../@stdlib/stats/array/nanmidrange-by/lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js index 68b4857f12e1..7703a80ab8e7 100644 --- a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Calculate the midrange of an array via a callback function, ignoring NaN values. +* Calculate the midrange of an array via a callback function, ignoring `NaN` values. * * @module @stdlib/stats/array/nanmidrange-by * @@ -41,6 +41,6 @@ var main = require( './main.js' ); -// MAIN // +// EXPORTS // module.exports = main; From 27497ceb2db3e868b3f6fa18b8a3d6bf764ade2a Mon Sep 17 00:00:00 2001 From: Om-A-osc Date: Sat, 14 Feb 2026 21:37:02 +0530 Subject: [PATCH 3/6] fix: addressing comments --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/array/nanmidrange-by/README.md | 25 +++++++++----- .../nanmidrange-by/benchmark/benchmark.js | 33 +++++++++++-------- .../stats/array/nanmidrange-by/docs/repl.txt | 2 ++ .../array/nanmidrange-by/examples/index.js | 17 ++++++---- .../stats/array/nanmidrange-by/package.json | 5 +-- 5 files changed, 50 insertions(+), 32 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/README.md b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/README.md index 7652262a80db..e9322066143d 100644 --- a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/README.md +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/README.md @@ -24,7 +24,7 @@ limitations under the License.
-The [**midrange**][midrange] is defined as the arithmetic mean of the maximum and minimum values. +The [**midrange**][midrange] is defined as the arithmetic mean of the maximum and minimum values in a data set. The measure is the midpoint of the range and a measure of central tendency.
@@ -47,7 +47,7 @@ function accessor( v ) { return v * 2.0; } -var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ]; +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0, NaN ]; var v = nanmidrangeBy( x, accessor ); // returns -1.0 @@ -73,7 +73,7 @@ function accessor( v ) { return v * 2.0; } -var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ]; +var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0, NaN ]; var context = { 'count': 0 @@ -83,7 +83,7 @@ var v = nanmidrangeBy( x, accessor, context ); // returns -1.0 var cnt = context.count; -// returns 9 +// returns 10 ``` @@ -96,6 +96,7 @@ var cnt = context.count; - If provided an empty array, the function returns `NaN`. - A provided callback function should return a numeric value. +- If a provided callback function returns `NaN`, the value is **ignored**. - If a provided callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is **ignored**. - The function supports array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). @@ -110,17 +111,23 @@ var cnt = context.count; ```javascript -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var nanmidrangeBy = require( '@stdlib/stats/array/nanmidrange-by' ); +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + function accessor( v ) { return v * 2.0; } -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -x[ 2 ] = NaN; +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = nanmidrangeBy( x, accessor ); diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/benchmark/benchmark.js index bc2d532f694e..0399df4024c0 100644 --- a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/benchmark/benchmark.js @@ -21,21 +21,16 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/array/uniform' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var format = require( '@stdlib/string/format' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var nanmidrangeBy = require( './../lib' ); -// VARIABLES // - -var options = { - 'dtype': 'generic' -}; - - // FUNCTIONS // /** @@ -49,6 +44,19 @@ function accessor( value ) { return value * 2.0; } +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -57,8 +65,7 @@ function accessor( value ) { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = uniform( len, -10, 10, options ); - x[ 0 ] = NaN; // Ensure at least one NaN + var x = filledarrayBy( len, 'generic', rand ); return benchmark; /** @@ -74,12 +81,12 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { v = nanmidrangeBy( x, accessor ); - if ( len > 1 && isnan( v ) ) { + if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } } b.toc(); - if ( len > 1 && isnan( v ) ) { + if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt index e222f86e65f4..c6ab53851ed3 100644 --- a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt @@ -13,6 +13,8 @@ The callback function should return a numeric value. + If the callback function returns `NaN`, the value is ignored. + If the callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored. diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/examples/index.js b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/examples/index.js index f08e1e705640..9e45e7345085 100644 --- a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/examples/index.js +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/examples/index.js @@ -18,18 +18,23 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var nanmidrangeBy = require( './../lib' ); +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} + function accessor( v ) { return v * 2.0; } -var x = discreteUniform( 10, -50, 50, { - 'dtype': 'float64' -}); -x[ 2 ] = NaN; -x[ 5 ] = NaN; +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = nanmidrangeBy( x, accessor ); diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/package.json b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/package.json index c0f8429fe767..1b90f213ba26 100644 --- a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/package.json +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/package.json @@ -62,12 +62,9 @@ "midrange", "range", "extremes", - "dispersion", "domain", "extent", - "array", - "nan", - "ignore" + "array" ], "__stdlib__": {} } From 32719e2cf69ad53a4e4d897c4f70a95cca35e79f Mon Sep 17 00:00:00 2001 From: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> Date: Sun, 15 Feb 2026 00:29:33 +0530 Subject: [PATCH 4/6] Update index.js Signed-off-by: Sachin Pangal <151670745+Sachinn-64@users.noreply.github.com> --- .../@stdlib/stats/array/nanmidrange-by/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js index 7703a80ab8e7..434ad65a3bbc 100644 --- a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Calculate the midrange of an array via a callback function, ignoring `NaN` values. +* Compute the midrange of an array via a callback function, ignoring `NaN` values. * * @module @stdlib/stats/array/nanmidrange-by * From 7acf2636a69b2e0a8ac074e7efc4399eb6dd1441 Mon Sep 17 00:00:00 2001 From: Om-A-osc Date: Sun, 15 Feb 2026 11:06:53 +0530 Subject: [PATCH 5/6] fix: addressing second round comments --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/array/nanmidrange-by/test/test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/test/test.js b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/test/test.js index 3f5cebf5c92e..8d7342814b3e 100644 --- a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/test/test.js +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/test/test.js @@ -114,7 +114,7 @@ tape( 'the function throws an error if provided a second argument which is not a } }); -tape( 'the function calculates the midrange of an array via a callback function, ignoring NaN values', function test( t ) { +tape( 'the function calculates the midrange of an array via a callback function', function test( t ) { var x; var v; @@ -141,7 +141,7 @@ tape( 'the function calculates the midrange of an array via a callback function, t.end(); }); -tape( 'the function calculates the midrange of an array via a callback function (accessors), ignoring NaN values', function test( t ) { +tape( 'the function calculates the midrange of an array via a callback function (accessors)', function test( t ) { var x; var v; @@ -168,7 +168,7 @@ tape( 'the function calculates the midrange of an array via a callback function t.end(); }); -tape( 'the function calculates the midrange of an array (array-like object), ignoring NaN values', function test( t ) { +tape( 'the function calculates the midrange of an array via a callback function (array-like object)', function test( t ) { var x; var v; From a55bbf9395e75d05f6107218e1e2a8d85d51e830 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 15 Feb 2026 13:26:03 -0500 Subject: [PATCH 6/6] docs: add missing backticks Signed-off-by: Philipp Burckhardt --- .../@stdlib/stats/array/nanmidrange-by/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt index c6ab53851ed3..55e72b2c6cd3 100644 --- a/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/array/nanmidrange-by/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x, clbk[, thisArg] ) Computes the midrange of an array via a callback function, - ignoring NaN values. + ignoring `NaN` values. If provided an empty array, the function returns `NaN`.