From 140bea72f8bbfb21ce88f379c34683b73cce4d09 Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Mon, 31 Mar 2025 23:04:40 +0530 Subject: [PATCH 01/26] refactor and add protocol support to stats/base/nanmax-by --- .../@stdlib/stats/base/nanmax-by/README.md | 29 +-- .../base/nanmax-by/benchmark/benchmark.js | 24 ++- .../nanmax-by/benchmark/benchmark.ndarray.js | 24 ++- .../stats/base/nanmax-by/docs/repl.txt | 14 +- .../base/nanmax-by/docs/types/index.d.ts | 30 +-- .../stats/base/nanmax-by/docs/types/test.ts | 11 +- .../stats/base/nanmax-by/examples/index.js | 14 +- .../stats/base/nanmax-by/lib/accessors.js | 101 ++++++++++ .../stats/base/nanmax-by/lib/nanmax_by.js | 53 +---- .../stats/base/nanmax-by/lib/ndarray.js | 23 ++- .../base/nanmax-by/test/test.nanmax_by.js | 184 +++++++++++++++++- .../stats/base/nanmax-by/test/test.ndarray.js | 176 ++++++++++++++++- 12 files changed, 554 insertions(+), 129 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md index 5e8ffb3e9671..cb0faeddca10 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2020 The Stdlib Authors. +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. @@ -30,7 +30,7 @@ limitations under the License. var nanmaxBy = require( '@stdlib/stats/base/nanmax-by' ); ``` -#### nanmaxBy( N, x, stride, clbk\[, thisArg] ) +#### nanmaxBy( N, x, strideX, clbk\[, thisArg] ) Calculates the maximum value of strided array `x` via a callback function, ignoring `NaN` values. @@ -49,7 +49,7 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Array`][mdn-array], [`typed array`][mdn-typed-array], or an array-like object (excluding strings and functions). -- **stride**: index increment. +- **strideX**: index increment. - **clbk**: callback function. - **thisArg**: execution context (_optional_). @@ -57,7 +57,7 @@ The invoked callback is provided four arguments: - **value**: array element. - **aidx**: array index. -- **sidx**: strided index (`offset + aidx*stride`). +- **sidx**: strided index (`offsetX + aidx*strideX`). - **array**: input array/collection. To set the callback execution context, provide a `thisArg`. @@ -81,7 +81,7 @@ var cnt = context.count; // returns 10 ``` -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element +The `N` and `strideX` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element ```javascript var floor = require( '@stdlib/math/base/special/floor' ); @@ -119,7 +119,7 @@ var v = nanmaxBy( N, x1, 2, accessor ); // returns -4.0 ``` -#### nanmaxBy.ndarray( N, x, stride, offset, clbk\[, thisArg] ) +#### nanmaxBy.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] ) Calculates the maximum value of strided array `x` via a callback function, ignoring `NaN` values and using alternative indexing semantics. @@ -136,9 +136,9 @@ var v = nanmaxBy.ndarray( x.length, x, 1, 0, accessor ); The function has the following additional parameters: -- **offset**: starting index. +- **offsetX**: starting index. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x` +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offsetX` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x` ```javascript function accessor( v ) { @@ -160,6 +160,7 @@ var v = nanmaxBy.ndarray( 3, x, 1, x.length-3, accessor ); ## Notes - If `N <= 0`, both functions return `NaN`. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). - 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. @@ -176,23 +177,23 @@ var v = nanmaxBy.ndarray( 3, x, 1, x.length-3, accessor ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var nanmaxBy = require( '@stdlib/stats/base/nanmax-by' ); -function fill() { - if ( randu() < 0.2 ) { +function rand() { + if ( bernoulli( 0.8 )< 0.2 ) { return NaN; } - return discreteUniform( -50, 50 ); + return uniform( -50, 50 ); } function accessor( v ) { return v * 2.0; } -var x = filledarrayBy( 10, 'float64', fill ); +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = nanmaxBy( x.length, x, 1, accessor ); diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js index d7f641b56dfe..94557d54f523 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -21,7 +21,9 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -37,6 +39,12 @@ var nanmaxBy = require( './../lib/nanmax_by.js' ); * @param {number} value - array element * @returns {number} accessed value */ +function rand() { + if( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} function accessor( value ) { return value * 2.0; } @@ -49,17 +57,7 @@ function accessor( value ) { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - if ( randu() < 0.2 ) { - x.push( NaN ); - } else { - x.push( ( randu()*20.0 ) - 10.0 ); - } - } + var x = filledarrayBy( len, "float64", rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js index cb4ba4704442..e264b52d3dba 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -21,7 +21,9 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -37,6 +39,12 @@ var nanmaxBy = require( './../lib/ndarray.js' ); * @param {number} value - array element * @returns {number} accessed value */ +function rand() { + if( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); +} function accessor( value ) { return value * 2.0; } @@ -49,17 +57,7 @@ function accessor( value ) { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - if ( randu() < 0.2 ) { - x.push( NaN ); - } else { - x.push( ( randu()*20.0 ) - 10.0 ); - } - } + var x = filledarrayBy( len, "float64", rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt index 59166ac9c070..bf6eb19e8ea5 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, x, stride, clbk[, thisArg] ) +{{alias}}( N, x, strideX, clbk[, thisArg] ) Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values. - The `N` and `stride` parameters determine which elements in `x` are accessed + The `N` and `strideX` parameters determine which elements in `x` are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed @@ -34,7 +34,7 @@ Input array/collection. If provided an object, the object must be array- like (excluding strings and functions). - stride: integer + strideX: integer Index increment for `x`. clbk: Function @@ -69,12 +69,12 @@ > {{alias}}( N, x1, 2, accessor ) -4.0 -{{alias}}.ndarray( N, x, stride, offset, clbk[, thisArg] ) +{{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] ) Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a + buffer, the `offsetX` parameter supports indexing semantics based on a starting index. Parameters @@ -86,10 +86,10 @@ Input array/collection. If provided an object, the object must be array- like (excluding strings and functions). - stride: integer + strideX: integer Index increment for `x`. - offset: integer + offsetX: integer Starting index of `x`. clbk: Function diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts index ed14a85bbb5b..e25598608f4d 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -20,7 +20,11 @@ /// -import { Collection } from '@stdlib/types/array'; +import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; +/** +* Input array. +*/ +type InputArray = NumericArray | Collection | AccessorArrayLike; /** * Returns an accessed value. @@ -51,7 +55,7 @@ type Binary = ( this: U, value: T, aidx: number ) => number | void; * * @param value - array element * @param aidx - array index -* @param sidx - strided index (offset + aidx*stride) +* @param sidx - strided index (offsetX + aidx*strideX) * @returns accessed value */ type Ternary = ( this: U, value: T, aidx: number, sidx: number ) => number | void; @@ -61,7 +65,7 @@ type Ternary = ( this: U, value: T, aidx: number, sidx: number ) => number * * @param value - array element * @param aidx - array index -* @param sidx - strided index (offset + aidx*stride) +* @param sidx - strided index (offsetX + aidx*strideX) * @param array - input array * @returns accessed value */ @@ -91,7 +95,7 @@ interface Routine { * * - `value`: array element * - `aidx`: array index - * - `sidx`: strided index (offset + aidx*stride) + * - `sidx`: strided index (offsetX + aidx*strideX) * - `array`: input array * * - The callback function should return a numeric value. @@ -102,7 +106,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @param clbk - callback * @param thisArg - execution context * @returns maximum value @@ -117,7 +121,7 @@ interface Routine { * var v = nanmaxBy( x.length, x, 1, accessor ); * // returns 8.0 */ - ( N: number, x: Collection, stride: number, clbk: Callback, thisArg?: ThisParameterType> ): number; + ( N: number, x: InputArray, strideX: number, clbk: Callback, thisArg?: ThisParameterType> ): number; /** * Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. @@ -128,7 +132,7 @@ interface Routine { * * - `value`: array element * - `aidx`: array index - * - `sidx`: strided index (offset + aidx*stride) + * - `sidx`: strided index (offsetX + aidx*strideX) * - `array`: input array * * - The callback function should return a numeric value. @@ -139,8 +143,8 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @param clbk - callback * @param thisArg - execution context * @returns maximum value @@ -155,7 +159,7 @@ interface Routine { * var v = nanmaxBy.ndarray( x.length, x, 1, 0, accessor ); * // returns 8.0 */ - ndarray( N: number, x: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): number; + ndarray( N: number, x: InputArray, strideX: number, offsetX: number, clbk: Callback, thisArg?: ThisParameterType> ): number; } /** @@ -167,7 +171,7 @@ interface Routine { * * - `value`: array element * - `aidx`: array index -* - `sidx`: strided index (offset + aidx*stride) +* - `sidx`: strided index (offsetX + aidx*strideX) * - `array`: input array * * - The callback function should return a numeric value. @@ -178,7 +182,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @param clbk - callback * @param thisArg - execution context * @returns maximum value diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts index 171fa67151bf..67f5775ab641 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -17,6 +17,7 @@ */ import nanmaxBy = require( './index' ); +import toAccessorArray from '@stdlib/array/base/to-accessor-array'; const accessor = (): number => { return 5.0; @@ -29,8 +30,8 @@ const accessor = (): number => { { const x = new Float64Array( 10 ); - nanmaxBy( x.length, x, 1, accessor ); // $ExpectType number - nanmaxBy( x.length, x, 1, accessor, {} ); // $ExpectType number + nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); // $ExpectType number + nanmaxBy( x.length, toAccessorArray( x ), 1, accessor, {} ); // $ExpectType number } // The compiler throws an error if the function is provided a first argument which is not a number... @@ -101,8 +102,8 @@ const accessor = (): number => { { const x = new Float64Array( 10 ); - nanmaxBy.ndarray( x.length, x, 1, 0, accessor ); // $ExpectType number - nanmaxBy.ndarray( x.length, x, 1, 0, accessor, {} ); // $ExpectType number + nanmaxBy.ndarray( x.length, toAccessorArray( x ), 1, 0, accessor ); // $ExpectType number + nanmaxBy.ndarray( x.length, toAccessorArray( x ), 1, 0, accessor, {} ); // $ExpectType number } // The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js index d10496816b36..325623b4baeb 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -18,23 +18,23 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var nanmaxBy = require( './../lib' ); -function fill() { - if ( randu() < 0.2 ) { +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { return NaN; } - return discreteUniform( -50, 50 ); + return uniform( -50, 50 ); } function accessor( v ) { return v * 2.0; } -var x = filledarrayBy( 10, 'float64', fill ); +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = nanmaxBy( x.length, x, 1, accessor ); diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js new file mode 100644 index 000000000000..5b664fd243f3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js @@ -0,0 +1,101 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); + + +// MAIN // + +/** +* Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array/collection +* @param {integer} strideX - index increment +* @param {NonNegativeInteger} offsetX - starting index +* @param {Callback} clbk - callback +* @param {*} [thisArg] - execution context +* @returns {number} maximum value +* +* @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 = nanmaxBy( x.length, x, 1, 0, accessor ); +* // returns 8.0 +*/ +function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { + var xbuf; + var get; + var max; + var ix; + var v; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[0]; + if ( N <= 0 ) { + return NaN; + } + if ( N === 1 || strideX === 0 ) { + v = clbk.call( thisArg, get( xbuf, 0 ), 0, 0, x ); + if ( v === void 0 || isnan( v ) ) { + return NaN; + } + return v; + } + ix = offsetX; + for ( i = 0; i < N; i++ ) { + max = clbk.call( thisArg, get( xbuf, ix ), i, ix, x ); + if ( max === max && max !== void 0 ) { + break; + } + ix += strideX; + } + if ( i === N ) { + return NaN; + } + i += 1; + for( i ; i < N ; i++ ) { + ix += strideX; + v = clbk.call( thisArg, get( xbuf, ix ), i, ix, x ); + if ( v === void 0 || isnan( v ) ) { + continue; + } + if( v > max || ( v === max && isPositiveZero( v ) ) ) { + max = v; + } + } + return max; +} + + +// EXPORTS // + +module.exports = nanmaxBy; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js index 32c7988df13c..3aa219a9fbb5 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -20,8 +20,8 @@ // MODULES // -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var ndarray = require( './ndarray.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); // MAIN // @@ -31,7 +31,7 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Collection} x - input array/collection -* @param {integer} stride - index increment +* @param {integer} strideX - index increment * @param {Callback} clbk - callback * @param {*} [thisArg] - execution context * @returns {number} maximum value @@ -46,49 +46,8 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); * var v = nanmaxBy( x.length, x, 1, accessor ); * // returns 8.0 */ -function nanmaxBy( N, x, stride, clbk, thisArg ) { - var max; - var ix; - var v; - var i; - - if ( N <= 0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - v = clbk.call( thisArg, x[ 0 ], 0, 0, x ); - if ( v === void 0 ) { - return NaN; - } - return v; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - for ( i = 0; i < N; i++ ) { - max = clbk.call( thisArg, x[ ix ], i, ix, x ); - if ( max === max && max !== void 0 ) { - break; - } - ix += stride; - } - if ( i === N ) { - return NaN; - } - i += 1; - for ( i; i < N; i++ ) { - ix += stride; - v = clbk.call( thisArg, x[ ix ], i, ix, x ); - if ( v === void 0 || isnan( v ) ) { - continue; - } - if ( v > max || ( v === max && isPositiveZero( v ) ) ) { - max = v; - } - } - return max; +function nanmaxBy( N, x, strideX, clbk, thisArg ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk , thisArg ); } diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js index 1095598082f8..49239fa0be57 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -22,6 +22,8 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); // MAIN // @@ -31,8 +33,8 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Collection} x - input array/collection -* @param {integer} stride - index increment -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - index increment +* @param {NonNegativeInteger} offsetX - starting index * @param {Callback} clbk - callback * @param {*} [thisArg] - execution context * @returns {number} maximum value @@ -47,36 +49,41 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); * var v = nanmaxBy( x.length, x, 1, 0, accessor ); * // returns 8.0 */ -function nanmaxBy( N, x, stride, offset, clbk, thisArg ) { +function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { var max; var ix; + var o; var v; var i; if ( N <= 0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { + o = arraylike2object( x ); + if( o.accessorProtocol ) { + return accessors( N, o, strideX, offsetX, clbk, thisArg ); + } + if ( N === 1 || strideX === 0 ) { v = clbk.call( thisArg, x[ 0 ], 0, 0, x ); if ( v === void 0 ) { return NaN; } return v; } - ix = offset; + ix = offsetX; for ( i = 0; i < N; i++ ) { max = clbk.call( thisArg, x[ ix ], i, ix, x ); if ( max === max && max !== void 0 ) { break; } - ix += stride; + ix += strideX; } if ( i === N ) { return NaN; } i += 1; for ( i; i < N; i++ ) { - ix += stride; + ix += strideX; v = clbk.call( thisArg, x[ ix ], i, ix, x ); if ( v === void 0 || isnan( v ) ) { continue; diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js index 962b286baf67..cda5bb6d9c88 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var floor = require( '@stdlib/math/base/special/floor' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var Float64Array = require( '@stdlib/array/float64' ); @@ -87,6 +88,42 @@ tape( 'the function calculates the maximum value of a strided array via a callba t.end(); }); +tape( 'the function calculates the maximum value of a strided array via a callback function, ignoring NaN values (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, NaN, 3.0 ]; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); + t.strictEqual( v, 10.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); + t.strictEqual( v, -8.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Array( 5 ); // sparse array + v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Array( 5 ); // sparse array + x[ 2 ] = 1.0; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { var x; var v; @@ -102,6 +139,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanmaxBy( 0, toAccessorArray( x ), 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = nanmaxBy( -1, toAccessorArray( x ), 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided an `N` parameter equal to `1`, the function returns the first accessed element', function test( t ) { var x; var v; @@ -118,6 +170,22 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first t.end(); }); +tape( 'if provided an `N` parameter equal to `1`, the function returns the first accessed element (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + x = new Array( 1 ); // sparse array + v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports a `stride` parameter', function test( t ) { var N; var x; @@ -143,6 +211,31 @@ tape( 'the function supports a `stride` parameter', function test( t ) { t.end(); }); +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var N; + 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, + NaN, // 4 + NaN + ]; + + N = floor( x.length / 2 ); + v = nanmaxBy( N, toAccessorArray( x ), 2, accessor ); + + t.strictEqual( v, 8.0, 'returns expected value' ); + t.end(); +}); + tape( 'the function supports a negative `stride` parameter', function test( t ) { var N; var x; @@ -168,6 +261,31 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var N; + var x; + var v; + + x = [ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + N = floor( x.length / 2 ); + v = nanmaxBy( N, toAccessorArray( x ), -2, accessor ); + + t.strictEqual( v, 8.0, 'returns expected value' ); + t.end(); +}); + tape( 'if provided a `stride` parameter equal to `0`, the function returns the first accessed element', function test( t ) { var x; var v; @@ -184,6 +302,22 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f t.end(); }); +tape( 'if provided a `stride` parameter equal to `0`, the function returns the first accessed element (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanmaxBy( x.length, x, 0, accessor ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + x = new Array( 1 ); // sparse array + v = nanmaxBy( 1, toAccessorArray( x ), 0, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports view offsets', function test( t ) { var x0; var x1; @@ -213,6 +347,35 @@ tape( 'the function supports view offsets', function test( t ) { t.end(); }); +tape( 'the function supports view offsets (accessors)', function test( t ) { + var x0; + var x1; + var N; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0, + NaN, // 4 + NaN + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); + + v = nanmaxBy( N, toAccessorArray( x1 ), 2, accessor ); + t.strictEqual( v, 8.0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports providing a callback execution context', function test( t ) { var ctx; var x; @@ -231,3 +394,22 @@ tape( 'the function supports providing a callback execution context', function t return v * 2.0; } }); + +tape( 'the function supports providing a callback execution context (accessors)', function test( t ) { + var ctx; + var x; + + x = [ 1.0, 2.0, 3.0, NaN, 4.0, 5.0 ]; + ctx = { + 'count': 0 + }; + nanmaxBy( x.length, toAccessorArray( x ), 1, accessor, ctx ); + + t.strictEqual( ctx.count, x.length, 'returns expected value' ); + t.end(); + + function accessor( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v * 2.0; + } +}); diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js index 1979f76e115f..bd9265c48382 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -22,6 +22,7 @@ var tape = require( 'tape' ); var floor = require( '@stdlib/math/base/special/floor' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var nanmaxBy = require( './../lib/ndarray.js' ); @@ -86,6 +87,42 @@ tape( 'the function calculates the maximum value of a strided array via a callba t.end(); }); +tape( 'the function calculates the maximum value of a strided array via a callback function, ignoring NaN values (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, NaN, 3.0 ]; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( v, 10.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( v, -8.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Array( 5 ); // sparse array + v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Array( 5 ); // sparse array + x[ 2 ] = 1.0; + v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { var x; var v; @@ -101,6 +138,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanmaxBy( 0, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = nanmaxBy( -1, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'if provided an `N` parameter equal to `1`, the function returns the first accessed element', function test( t ) { var x; var v; @@ -117,6 +169,22 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first t.end(); }); +tape( 'if provided an `N` parameter equal to `1`, the function returns the first accessed element (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanmaxBy( 1, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + x = new Array( 1 ); // sparse array + v = nanmaxBy( 1, toAccessorArray( x ), 1, 0, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports a `stride` parameter', function test( t ) { var N; var x; @@ -142,6 +210,31 @@ tape( 'the function supports a `stride` parameter', function test( t ) { t.end(); }); +tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { + var N; + 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, + NaN, // 4 + NaN + ]; + + N = floor( x.length / 2 ); + v = nanmaxBy( N, toAccessorArray( x ), 2, 0, accessor ); + + t.strictEqual( v, 8.0, 'returns expected value' ); + t.end(); +}); + tape( 'the function supports a negative `stride` parameter', function test( t ) { var N; var x; @@ -167,6 +260,31 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); +tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { + var N; + var x; + var v; + + x = [ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + N = floor( x.length / 2 ); + v = nanmaxBy( N, toAccessorArray( x ), -2, 8, accessor ); + + t.strictEqual( v, 8.0, 'returns expected value' ); + t.end(); +}); + tape( 'if provided a `stride` parameter equal to `0`, the function returns the first accessed element', function test( t ) { var x; var v; @@ -183,6 +301,22 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f t.end(); }); +tape( 'if provided a `stride` parameter equal to `0`, the function returns the first accessed element (accessors)', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanmaxBy( x.length, toAccessorArray( x ), 0, 0, accessor ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + x = new Array( 1 ); // sparse array + v = nanmaxBy( 1, toAccessorArray( x ), 0, 0, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports an offset parameter', function test( t ) { var x; var v; @@ -204,6 +338,27 @@ tape( 'the function supports an offset parameter', function test( t ) { t.end(); }); +tape( 'the function supports an offset parameter (accessors)', function test( t ) { + var x; + var v; + + x = [ + 1.0, + -2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + -6.0, // 2 + NaN, + NaN // 3 + ]; + + v = nanmaxBy( 4, toAccessorArray( x ), 2, 1, accessor ); + t.strictEqual( v, 8.0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports providing a callback execution context', function test( t ) { var ctx; var x; @@ -222,3 +377,22 @@ tape( 'the function supports providing a callback execution context', function t return v * 2.0; } }); + +tape( 'the function supports providing a callback execution context (accessors)', function test( t ) { + var ctx; + var x; + + x = [ 1.0, 2.0, 3.0, NaN, 4.0, 5.0 ]; + ctx = { + 'count': 0 + }; + nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor, ctx ); + + t.strictEqual( ctx.count, x.length, 'returns expected value' ); + t.end(); + + function accessor( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v * 2.0; + } +}); From 8a8ffcdb72142a4e03ca61f8732a7cb3dc0f944d Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Tue, 1 Apr 2025 01:01:49 +0530 Subject: [PATCH 02/26] fix linting error --- .../@stdlib/stats/base/nanmax-by/README.md | 3 +- .../stats/base/nanmax-by/lib/accessors.js | 43 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md index cb0faeddca10..da52c48fc0b1 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md @@ -160,7 +160,6 @@ var v = nanmaxBy.ndarray( 3, x, 1, x.length-3, accessor ); ## Notes - If `N <= 0`, both functions return `NaN`. -- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). - 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. @@ -183,7 +182,7 @@ var bernoulli = require( '@stdlib/random/base/bernoulli' ); var nanmaxBy = require( '@stdlib/stats/base/nanmax-by' ); function rand() { - if ( bernoulli( 0.8 )< 0.2 ) { + if ( bernoulli( 0.8 )< 0.2 ) { return NaN; } return uniform( -50, 50 ); diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js index 5b664fd243f3..6a910ac5b694 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js @@ -38,17 +38,20 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); * @returns {number} maximum value * * @example -* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ]; +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ -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 = nanmaxBy( x.length, x, 1, 0, accessor ); +* var v = nanmaxBy( x.length, arraylike2object( x ), 1, 0, accessor ); * // returns 8.0 */ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { - var xbuf; + var xbuf; var get; var max; var ix; @@ -61,38 +64,38 @@ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { // Cache a reference to the element accessor: get = x.accessors[0]; if ( N <= 0 ) { - return NaN; + return NaN; } if ( N === 1 || strideX === 0 ) { - v = clbk.call( thisArg, get( xbuf, 0 ), 0, 0, x ); - if ( v === void 0 || isnan( v ) ) { - return NaN; - } - return v; + v = clbk.call( thisArg, get( xbuf, 0 ), 0, 0, x ); + if ( v === void 0 || isnan( v ) ) { + return NaN; + } + return v; } ix = offsetX; for ( i = 0; i < N; i++ ) { max = clbk.call( thisArg, get( xbuf, ix ), i, ix, x ); - if ( max === max && max !== void 0 ) { - break; - } - ix += strideX; + if ( max === max && max !== void 0 ) { + break; + } + ix += strideX; } if ( i === N ) { - return NaN; + return NaN; } i += 1; - for( i ; i < N ; i++ ) { + for ( i; i < N; i++ ) { ix += strideX; v = clbk.call( thisArg, get( xbuf, ix ), i, ix, x ); - if ( v === void 0 || isnan( v ) ) { - continue; - } - if( v > max || ( v === max && isPositiveZero( v ) ) ) { + if ( v === void 0 || isnan( v ) ) { + continue; + } + if ( v > max || ( v === max && isPositiveZero( v ) ) ) { max = v; } } - return max; + return max; } From baea46dc8566c9162534610c058ef4fe1ece6bce Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Tue, 1 Apr 2025 01:06:55 +0530 Subject: [PATCH 03/26] Update accessors.js Signed-off-by: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> --- .../@stdlib/stats/base/nanmax-by/lib/accessors.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js index 6a910ac5b694..8147d1b5f302 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js @@ -51,7 +51,7 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); * // returns 8.0 */ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { - var xbuf; + var xbuf; var get; var max; var ix; @@ -95,10 +95,10 @@ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { max = v; } } - return max; + return max; } // EXPORTS // -module.exports = nanmaxBy; \ No newline at end of file +module.exports = nanmaxBy; From 27e92b1f15e3b03325bb83715a4a0f52d5e9f63d Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Tue, 1 Apr 2025 22:53:44 +0530 Subject: [PATCH 04/26] Update nanmax_by.js Signed-off-by: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> --- .../@stdlib/stats/base/nanmax-by/lib/nanmax_by.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js index 3aa219a9fbb5..2631869b3393 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js @@ -20,8 +20,8 @@ // MODULES // -var ndarray = require( './ndarray.js' ); var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -47,7 +47,7 @@ var stride2offset = require( '@stdlib/strided/base/stride2offset' ); * // returns 8.0 */ function nanmaxBy( N, x, strideX, clbk, thisArg ) { - return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk , thisArg ); + return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk, thisArg ); } From e719cfdc78f2afcb312e48ad22edb453aa9ed9c0 Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Tue, 1 Apr 2025 22:53:51 +0530 Subject: [PATCH 05/26] Update repl.txt Signed-off-by: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt index bf6eb19e8ea5..902186f54ffa 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt @@ -3,8 +3,8 @@ Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values. - The `N` and `strideX` parameters determine which elements in `x` are accessed - at runtime. + The `N` and `strideX` parameters determine which elements in `x` are, + accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. @@ -111,6 +111,7 @@ > {{alias}}.ndarray( x.length, x, 1, 0, accessor ) 8.0 + // Using an index offset: > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); From e0e8bb3cf42b223425a89bcfbd7e2d7bc7aa443e Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Tue, 1 Apr 2025 22:56:58 +0530 Subject: [PATCH 06/26] Update ndarray.js Signed-off-by: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js index 49239fa0be57..fbb61e197a54 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js @@ -60,7 +60,7 @@ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { return NaN; } o = arraylike2object( x ); - if( o.accessorProtocol ) { + if ( o.accessorProtocol ) { return accessors( N, o, strideX, offsetX, clbk, thisArg ); } if ( N === 1 || strideX === 0 ) { From 17549ddebbbf65f84789bf79ecb87732bece9515 Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Tue, 1 Apr 2025 23:14:52 +0530 Subject: [PATCH 07/26] Update test.nanmax_by.js Signed-off-by: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> --- .../stats/base/nanmax-by/test/test.nanmax_by.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js index cda5bb6d9c88..cb507f9c1d40 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js @@ -76,11 +76,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = Array( 5 ).fill( undefined ); // sparse array v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = Array( 5 ).fill( undefined ); // sparse array x[ 2 ] = 1.0; v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -112,11 +112,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = Array( 5 ).fill( undefined ); // sparse array v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = Array( 5 ).fill( undefined ); // sparse array x[ 2 ] = 1.0; v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -163,7 +163,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // sparse array + x = Array( 5 ).fill( undefined ); // sparse array v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -179,7 +179,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // sparse array + x = Array( 1 ).fill( undefined ); // sparse array v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -295,7 +295,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, x, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // sparse array + x = Array( ).fill( undefined ); // sparse array v = nanmaxBy( 1, x, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -311,7 +311,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, x, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // sparse array + x = Array( 1 ).fill( undefined ); // sparse array v = nanmaxBy( 1, toAccessorArray( x ), 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); From 759244ef3f9e0a6b047a90bbd244bd1cc343985b Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Tue, 1 Apr 2025 23:20:23 +0530 Subject: [PATCH 08/26] Update test.nanmax_by.js Signed-off-by: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> --- .../stats/base/nanmax-by/test/test.nanmax_by.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js index cb507f9c1d40..60e594d7f2cc 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js @@ -76,7 +76,7 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = Array( 5 ).fill( undefined ); // sparse array + x = new Array( 5 ).fill( undefined ); // sparse array v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -116,7 +116,7 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = Array( 5 ).fill( undefined ); // sparse array + x = new Array( 5 ).fill( undefined ); // sparse array x[ 2 ] = 1.0; v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -163,7 +163,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = Array( 5 ).fill( undefined ); // sparse array + x = new Array( 5 ).fill( undefined ); // sparse array v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -179,7 +179,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = Array( 1 ).fill( undefined ); // sparse array + x = new Array( 1 ).fill( undefined ); // sparse array v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -295,7 +295,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, x, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = Array( ).fill( undefined ); // sparse array + x = new Array( ).fill( undefined ); // sparse array v = nanmaxBy( 1, x, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -311,7 +311,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, x, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = Array( 1 ).fill( undefined ); // sparse array + x = new Array( 1 ).fill( undefined ); // sparse array v = nanmaxBy( 1, toAccessorArray( x ), 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); From 670cfe2ed9b248b3bd698ca7386408410f72269a Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Tue, 1 Apr 2025 23:27:44 +0530 Subject: [PATCH 09/26] Update test.nanmax_by.js Signed-off-by: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> --- .../stats/base/nanmax-by/test/test.nanmax_by.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js index 60e594d7f2cc..2acef382fe70 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js @@ -76,7 +76,8 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ).fill( undefined ); // sparse array + x = []; + x.length = 5; // sparse array v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -112,7 +113,8 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = Array( 5 ).fill( undefined ); // sparse array + x = []; // Sparse array + x.length = 5; v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -163,7 +165,8 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 5 ).fill( undefined ); // sparse array + x = []; // Sparse array + x.length = 5; v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -179,7 +182,8 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ).fill( undefined ); // sparse array + x = []; // Sparse array + x.length = 5; v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -295,7 +299,8 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, x, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( ).fill( undefined ); // sparse array + x = []; // Sparse array + x.length = 5; v = nanmaxBy( 1, x, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); From 27b7ac5ecbce5c9d32ee0c0cc85f600831d0d637 Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Wed, 2 Apr 2025 22:34:28 +0530 Subject: [PATCH 10/26] Update test.nanmax_by.js Signed-off-by: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> --- .../stats/base/nanmax-by/test/test.nanmax_by.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js index 2acef382fe70..6b0680de5f0d 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js @@ -76,8 +76,7 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = []; - x.length = 5; // sparse array + x = new Array( 5 ); // sparse array v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -113,12 +112,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = []; // Sparse array - x.length = 5; + x = new Array( 5 ); // sparse array v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ).fill( undefined ); // sparse array + x = new Array( 5 ); // sparse array x[ 2 ] = 1.0; v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -165,8 +163,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = []; // Sparse array - x.length = 5; + x = new Array( 5 ); // sparse array; v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -182,8 +179,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = []; // Sparse array - x.length = 5; + x = new Array( 5 ); // sparse array v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -299,8 +295,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, x, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = []; // Sparse array - x.length = 5; + x = new Array( 5 ); // sparse array v = nanmaxBy( 1, x, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); From 0297ff663c3c590d125a17ef496c7d952c57c022 Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Thu, 3 Apr 2025 00:17:50 +0530 Subject: [PATCH 11/26] Update test.nanmax_by.js Signed-off-by: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> --- .../@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js index 6b0680de5f0d..15063d272b48 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js @@ -80,7 +80,7 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = Array( 5 ).fill( undefined ); // sparse array + x = new Array( 5 ); // sparse array x[ 2 ] = 1.0; v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -311,7 +311,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, x, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ).fill( undefined ); // sparse array + x = new Array( 5 ); // sparse array v = nanmaxBy( 1, toAccessorArray( x ), 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); From faaa99bcfbad1d6c4aecc156c184755c356b5356 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 3 Jun 2025 20:06:43 +0000 Subject: [PATCH 12/26] fix: cleanup README --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/nanmax-by/README.md | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md index da52c48fc0b1..a3457cc6cfdf 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +Copyright (c) 2020 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. @@ -32,7 +32,7 @@ var nanmaxBy = require( '@stdlib/stats/base/nanmax-by' ); #### nanmaxBy( N, x, strideX, clbk\[, thisArg] ) -Calculates the maximum value of strided array `x` via a callback function, ignoring `NaN` values. +Calculates the maximum value of strided array via a callback function, ignoring `NaN` values. ```javascript function accessor( v ) { @@ -49,7 +49,7 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Array`][mdn-array], [`typed array`][mdn-typed-array], or an array-like object (excluding strings and functions). -- **strideX**: index increment. +- **strideX**: stride length. - **clbk**: callback function. - **thisArg**: execution context (_optional_). @@ -57,7 +57,7 @@ The invoked callback is provided four arguments: - **value**: array element. - **aidx**: array index. -- **sidx**: strided index (`offsetX + aidx*strideX`). +- **sidx**: strided index (`offset + aidx*stride`). - **array**: input array/collection. To set the callback execution context, provide a `thisArg`. @@ -81,19 +81,16 @@ var cnt = context.count; // returns 10 ``` -The `N` and `strideX` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element ```javascript -var floor = require( '@stdlib/math/base/special/floor' ); - function accessor( v ) { return v * 2.0; } var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0, NaN, NaN ]; -var N = floor( x.length / 2 ); -var v = nanmaxBy( N, x, 2, accessor ); +var v = nanmaxBy( 5, x, 2, accessor ); // returns 8.0 ``` @@ -101,7 +98,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); function accessor( v ) { return v * 2.0; @@ -112,16 +108,15 @@ var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); // Create an offset view... var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length/2 ); // Access every other element... -var v = nanmaxBy( N, x1, 2, accessor ); +var v = nanmaxBy( 3, x1, 2, accessor ); // returns -4.0 ``` #### nanmaxBy.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] ) -Calculates the maximum value of strided array `x` via a callback function, ignoring `NaN` values and using alternative indexing semantics. +Computes the maximum value of strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. ```javascript function accessor( v ) { @@ -138,7 +133,7 @@ The function has the following additional parameters: - **offsetX**: starting index. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offsetX` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x` +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x` ```javascript function accessor( v ) { @@ -164,6 +159,7 @@ var v = nanmaxBy.ndarray( 3, x, 1, x.length-3, accessor ); - 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. - When possible, prefer using [`dnanmax`][@stdlib/stats/strided/dnanmax], [`snanmax`][@stdlib/stats/strided/snanmax], and/or [`nanmax`][@stdlib/stats/base/nanmax], as, depending on the environment, these interfaces are likely to be significantly more performant. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). @@ -229,6 +225,8 @@ console.log( v ); [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor + [@stdlib/stats/strided/dnanmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dnanmax From a2d6b6c3821f6ff9f29ed1fb10ee90231e044fc4 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 3 Jun 2025 20:12:14 +0000 Subject: [PATCH 13/26] fix: clenaup benchmarks --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/nanmax-by/benchmark/benchmark.js | 20 +++++++++++++------ .../nanmax-by/benchmark/benchmark.ndarray.js | 20 +++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js index 94557d54f523..cd8bf64706cb 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -32,6 +32,17 @@ var nanmaxBy = require( './../lib/nanmax_by.js' ); // FUNCTIONS // +/** +* Accessor function. +* +* @private +* @param {number} value - array element +* @returns {number} accessed value +*/ +function accessor( value ) { + return value * 2.0; +} + /** * Accessor function. * @@ -40,14 +51,11 @@ var nanmaxBy = require( './../lib/nanmax_by.js' ); * @returns {number} accessed value */ function rand() { - if( bernoulli( 0.8 ) < 1 ) { + if ( bernoulli( 0.8 ) < 1 ) { return NaN; } return uniform( -50.0, 50.0 ); } -function accessor( value ) { - return value * 2.0; -} /** * Create a benchmark function. @@ -57,7 +65,7 @@ function accessor( value ) { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, "float64", rand ); + var x = filledarrayBy( len, 'generic', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js index e264b52d3dba..aa645f6c381f 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -32,6 +32,17 @@ var nanmaxBy = require( './../lib/ndarray.js' ); // FUNCTIONS // +/** +* Accessor function. +* +* @private +* @param {number} value - array element +* @returns {number} accessed value +*/ +function accessor( value ) { + return value * 2.0; +} + /** * Accessor function. * @@ -40,14 +51,11 @@ var nanmaxBy = require( './../lib/ndarray.js' ); * @returns {number} accessed value */ function rand() { - if( bernoulli( 0.8 ) < 1 ) { + if ( bernoulli( 0.8 ) < 1 ) { return NaN; } return uniform( -50.0, 50.0 ); } -function accessor( value ) { - return value * 2.0; -} /** * Create a benchmark function. @@ -57,7 +65,7 @@ function accessor( value ) { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, "float64", rand ); + var x = filledarrayBy( len, 'generic', rand ); return benchmark; function benchmark( b ) { From cb17995da8a1064c02da4904d3c427c4476fbb10 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 3 Jun 2025 20:17:26 +0000 Subject: [PATCH 14/26] docs: fix repl --- 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: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/base/nanmax-by/docs/repl.txt | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt index 902186f54ffa..f44751e376a0 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt @@ -1,10 +1,10 @@ {{alias}}( N, x, strideX, clbk[, thisArg] ) - Calculates the maximum value of a strided array via a callback function, + Computes the maximum value of strided array via a callback function, ignoring `NaN` values. - The `N` and `strideX` parameters determine which elements in `x` are, - accessed at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. @@ -35,7 +35,7 @@ like (excluding strings and functions). strideX: integer - Index increment for `x`. + Stride length. clbk: Function Callback function. @@ -56,25 +56,24 @@ > {{alias}}( x.length, x, 1, accessor ) 8.0 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, x, 2, accessor ) + > {{alias}}( 3, x, 2, accessor ) 8.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > {{alias}}( N, x1, 2, accessor ) + > {{alias}}( 3, x1, 2, accessor ) -4.0 + {{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] ) Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offsetX` parameter supports indexing semantics based on a + buffer, the offset parameter supports indexing semantics based on a starting index. Parameters @@ -87,10 +86,10 @@ like (excluding strings and functions). strideX: integer - Index increment for `x`. + Stride length. offsetX: integer - Starting index of `x`. + Starting index. clbk: Function Callback function. @@ -114,8 +113,7 @@ // Using an index offset: > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1, accessor ) + > {{alias}}.ndarray( 3, x, 2, 1, accessor ) -4.0 See Also From 0620ad51ce3f8c2ac6ff2b65be78978409f4d6c3 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 3 Jun 2025 21:12:42 +0000 Subject: [PATCH 15/26] docs: minor cleanup and fix test.ts --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: 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: passed - task: lint_license_headers status: passed --- --- .../base/nanmax-by/docs/types/index.d.ts | 19 +++++++++--------- .../stats/base/nanmax-by/docs/types/test.ts | 20 ++++++++++++------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts index e25598608f4d..106918e08dfe 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -21,6 +21,7 @@ /// import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array'; + /** * Input array. */ @@ -55,7 +56,7 @@ type Binary = ( this: U, value: T, aidx: number ) => number | void; * * @param value - array element * @param aidx - array index -* @param sidx - strided index (offsetX + aidx*strideX) +* @param sidx - strided index (offset + aidx*stride) * @returns accessed value */ type Ternary = ( this: U, value: T, aidx: number, sidx: number ) => number | void; @@ -65,7 +66,7 @@ type Ternary = ( this: U, value: T, aidx: number, sidx: number ) => number * * @param value - array element * @param aidx - array index -* @param sidx - strided index (offsetX + aidx*strideX) +* @param sidx - strided index (offset + aidx*stride) * @param array - input array * @returns accessed value */ @@ -87,7 +88,7 @@ type Callback = Nullary | Unary | Binary | Ternary | */ interface Routine { /** - * Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values. + * Computes the maximum value of a strided array via a callback function, ignoring `NaN` values. * * ## Notes * @@ -95,7 +96,7 @@ interface Routine { * * - `value`: array element * - `aidx`: array index - * - `sidx`: strided index (offsetX + aidx*strideX) + * - `sidx`: strided index (offset + aidx*stride) * - `array`: input array * * - The callback function should return a numeric value. @@ -124,7 +125,7 @@ interface Routine { ( N: number, x: InputArray, strideX: number, clbk: Callback, thisArg?: ThisParameterType> ): number; /** - * Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. + * Computes the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. * * ## Notes * @@ -132,7 +133,7 @@ interface Routine { * * - `value`: array element * - `aidx`: array index - * - `sidx`: strided index (offsetX + aidx*strideX) + * - `sidx`: strided index (offset + aidx*stride) * - `array`: input array * * - The callback function should return a numeric value. @@ -163,7 +164,7 @@ interface Routine { } /** -* Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values. +* Computes the maximum value of a strided array via a callback function, ignoring `NaN` values. * * ## Notes * @@ -171,7 +172,7 @@ interface Routine { * * - `value`: array element * - `aidx`: array index -* - `sidx`: strided index (offsetX + aidx*strideX) +* - `sidx`: strided index (offset + aidx*stride) * - `array`: input array * * - The callback function should return a numeric value. diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts index 67f5775ab641..768e6fa78cf0 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -16,8 +16,8 @@ * limitations under the License. */ +import AccessorArray = require( '@stdlib/array/base/accessor' ); import nanmaxBy = require( './index' ); -import toAccessorArray from '@stdlib/array/base/to-accessor-array'; const accessor = (): number => { return 5.0; @@ -30,8 +30,11 @@ const accessor = (): number => { { const x = new Float64Array( 10 ); - nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); // $ExpectType number - nanmaxBy( x.length, toAccessorArray( x ), 1, accessor, {} ); // $ExpectType number + nanmaxBy( x.length, x, 1, accessor ); // $ExpectType number + nanmaxBy( x.length, new AccessorArray( x ), 1, accessor ); // $ExpectType number + + nanmaxBy( x.length, x, 1, accessor, {} ); // $ExpectType number + nanmaxBy( x.length, new AccessorArray( x ), 1, accessor, {} ); // $ExpectType number } // The compiler throws an error if the function is provided a first argument which is not a number... @@ -71,7 +74,7 @@ const accessor = (): number => { nanmaxBy( x.length, x, undefined, accessor ); // $ExpectError nanmaxBy( x.length, x, [], accessor ); // $ExpectError nanmaxBy( x.length, x, {}, accessor ); // $ExpectError - nanmaxBy( x.length, x, ( x: number, accessor ): number => x, accessor ); // $ExpectError + nanmaxBy( x.length, x, ( x: number ): number => x, accessor ); // $ExpectError } // The compiler throws an error if the function is provided a fourth argument which is not a function... @@ -102,8 +105,11 @@ const accessor = (): number => { { const x = new Float64Array( 10 ); - nanmaxBy.ndarray( x.length, toAccessorArray( x ), 1, 0, accessor ); // $ExpectType number - nanmaxBy.ndarray( x.length, toAccessorArray( x ), 1, 0, accessor, {} ); // $ExpectType number + nanmaxBy.ndarray( x.length, x, 1, 0, accessor ); // $ExpectType number + nanmaxBy.ndarray( x.length, new AccessorArray( x ), 1, 0, accessor ); // $ExpectType number + + nanmaxBy.ndarray( x.length, x, 1, 0, accessor, {} ); // $ExpectType number + nanmaxBy.ndarray( x.length, new AccessorArray( x ), 1, 0, accessor, {} ); // $ExpectType number } // The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... From da5a2d9dd2077a61ab8681c1b0638fb32f8d5f50 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Tue, 3 Jun 2025 21:14:14 +0000 Subject: [PATCH 16/26] docs: fix examples --- 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: passed - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js index 325623b4baeb..518d5462a702 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js @@ -24,7 +24,7 @@ var bernoulli = require( '@stdlib/random/base/bernoulli' ); var nanmaxBy = require( './../lib' ); function rand() { - if ( bernoulli( 0.8 ) < 1 ) { + if ( bernoulli( 0.8 )< 0.2 ) { return NaN; } return uniform( -50, 50 ); From 19e5376d92a8356202bcbe964c46aa5193b9d9ae Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Wed, 4 Jun 2025 06:06:15 +0000 Subject: [PATCH 17/26] fix: implementation --- 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/base/nanmax-by/lib/accessors.js | 11 ++-- .../@stdlib/stats/base/nanmax-by/lib/index.js | 9 ++- .../@stdlib/stats/base/nanmax-by/lib/main.js | 27 ++++++++- .../stats/base/nanmax-by/lib/nanmax_by.js | 56 ------------------- .../stats/base/nanmax-by/lib/ndarray.js | 6 +- 5 files changed, 42 insertions(+), 67 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js index 8147d1b5f302..6c6c7ae048c8 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js @@ -27,11 +27,13 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); // MAIN // /** -* Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values. +* Computes the maximum value of a strided array via a callback function, ignoring `NaN` values. * * @param {PositiveInteger} N - number of indexed elements -* @param {Collection} x - input array/collection -* @param {integer} strideX - index increment +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length * @param {NonNegativeInteger} offsetX - starting index * @param {Callback} clbk - callback * @param {*} [thisArg] - execution context @@ -63,11 +65,12 @@ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { // Cache a reference to the element accessor: get = x.accessors[0]; + if ( N <= 0 ) { return NaN; } if ( N === 1 || strideX === 0 ) { - v = clbk.call( thisArg, get( xbuf, 0 ), 0, 0, x ); + v = clbk.call( thisArg, get( xbuf, 0 ), 0, offsetX, x ); if ( v === void 0 || isnan( v ) ) { return NaN; } diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/index.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/index.js index 8995feabfd2d..f35d4e1092d7 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Calculate the maximum value of a strided array via a callback function and ignoring `NaN` values. +* Compute the maximum value of a strided array via a callback function and ignoring `NaN` values. * * @module @stdlib/stats/base/nanmax-by * @@ -50,7 +50,14 @@ // MODULES // +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/main.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/main.js index f1141e54d975..09117b59a4e0 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/main.js @@ -20,14 +20,35 @@ // MODULES // -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var nanmaxBy = require( './nanmax_by.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); var ndarray = require( './ndarray.js' ); // MAIN // -setReadOnly( nanmaxBy, 'ndarray', ndarray ); +/** +* Computes the maximum value of a strided array via a callback function, ignoring `NaN` values. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array/collection +* @param {integer} strideX - index increment +* @param {Callback} clbk - callback +* @param {*} [thisArg] - execution context +* @returns {number} maximum value +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; +* +* function accessor( v ) { +* return v * 2.0; +* } +* +* var v = nanmaxBy( x.length, x, 1, accessor ); +* // returns 8.0 +*/ +function nanmaxBy( N, x, strideX, clbk, thisArg ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk, thisArg ); +} // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js deleted file mode 100644 index 2631869b3393..000000000000 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js +++ /dev/null @@ -1,56 +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'; - -// MODULES // - -var stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -/** -* Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values. -* -* @param {PositiveInteger} N - number of indexed elements -* @param {Collection} x - input array/collection -* @param {integer} strideX - index increment -* @param {Callback} clbk - callback -* @param {*} [thisArg] - execution context -* @returns {number} maximum value -* -* @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 = nanmaxBy( x.length, x, 1, accessor ); -* // returns 8.0 -*/ -function nanmaxBy( N, x, strideX, clbk, thisArg ) { - return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk, thisArg ); -} - - -// EXPORTS // - -module.exports = nanmaxBy; diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js index fbb61e197a54..04334929d526 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -29,7 +29,7 @@ var accessors = require( './accessors.js' ); // MAIN // /** -* Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values. +* Computes the maximum value of a strided array via a callback function, ignoring `NaN` values. * * @param {PositiveInteger} N - number of indexed elements * @param {Collection} x - input array/collection @@ -64,7 +64,7 @@ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { return accessors( N, o, strideX, offsetX, clbk, thisArg ); } if ( N === 1 || strideX === 0 ) { - v = clbk.call( thisArg, x[ 0 ], 0, 0, x ); + v = clbk.call( thisArg, x[ offsetX ], 0, offsetX, x ); if ( v === void 0 ) { return NaN; } From d1e495d1579fe3be6721ced1ff160ae011012743 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Wed, 4 Jun 2025 06:20:40 +0000 Subject: [PATCH 18/26] fix: test cases --- 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../base/nanmax-by/test/test.nanmax_by.js | 47 +++++++------------ .../stats/base/nanmax-by/test/test.ndarray.js | 35 +++++--------- 2 files changed, 30 insertions(+), 52 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js index 15063d272b48..80b00b8feee4 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -21,12 +21,11 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var Float64Array = require( '@stdlib/array/float64' ); -var nanmaxBy = require( './../lib/nanmax_by.js' ); +var nanmaxBy = require( './../lib/main.js' ); // FUNCTIONS // @@ -76,11 +75,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array x[ 2 ] = 1.0; v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -112,11 +111,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array x[ 2 ] = 1.0; v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -163,7 +162,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 5 ); // sparse array; + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -179,7 +178,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -187,7 +186,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -204,15 +202,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]; - N = floor( x.length / 2 ); - v = nanmaxBy( N, x, 2, accessor ); + v = nanmaxBy( 5, x, 2, accessor ); t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var N; var x; var v; @@ -229,15 +225,13 @@ tape( 'the function supports a `stride` parameter (accessors)', function test( t NaN ]; - N = floor( x.length / 2 ); - v = nanmaxBy( N, toAccessorArray( x ), 2, accessor ); + v = nanmaxBy( 5, toAccessorArray( x ), 2, accessor ); t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -254,15 +248,13 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = nanmaxBy( N, x, -2, accessor ); + v = nanmaxBy( 5, x, -2, accessor ); t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var N; var x; var v; @@ -279,8 +271,7 @@ tape( 'the function supports a negative `stride` parameter (accessors)', functio 2.0 ]; - N = floor( x.length / 2 ); - v = nanmaxBy( N, toAccessorArray( x ), -2, accessor ); + v = nanmaxBy( 5, toAccessorArray( x ), -2, accessor ); t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); @@ -295,7 +286,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, x, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, x, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -308,10 +299,10 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - v = nanmaxBy( x.length, x, 0, accessor ); + v = nanmaxBy( x.length, toAccessorArray( x ), 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, toAccessorArray( x ), 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -321,7 +312,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -339,9 +329,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = nanmaxBy( N, x1, 2, accessor ); + v = nanmaxBy( 5, x1, 2, accessor ); t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); @@ -350,7 +339,6 @@ tape( 'the function supports view offsets', function test( t ) { tape( 'the function supports view offsets (accessors)', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -368,9 +356,8 @@ tape( 'the function supports view offsets (accessors)', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = nanmaxBy( N, toAccessorArray( x1 ), 2, accessor ); + v = nanmaxBy( 5, toAccessorArray( x1 ), 2, accessor ); t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js index bd9265c48382..d0567ebca61a 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); @@ -75,11 +74,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, x, 1, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( x.length, x, 1, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array x[ 2 ] = 1.0; v = nanmaxBy( x.length, x, 1, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -111,11 +110,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // sparse array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array x[ 2 ] = 1.0; v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -162,7 +161,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, x, 1, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // sparse array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, x, 1, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -178,7 +177,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, toAccessorArray( x ), 1, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // sparse array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, toAccessorArray( x ), 1, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -186,7 +185,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -203,15 +201,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]; - N = floor( x.length / 2 ); - v = nanmaxBy( N, x, 2, 0, accessor ); + v = nanmaxBy( 5, x, 2, 0, accessor ); t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var N; var x; var v; @@ -228,15 +224,13 @@ tape( 'the function supports a `stride` parameter (accessors)', function test( t NaN ]; - N = floor( x.length / 2 ); - v = nanmaxBy( N, toAccessorArray( x ), 2, 0, accessor ); + v = nanmaxBy( 5, toAccessorArray( x ), 2, 0, accessor ); t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -253,15 +247,13 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = nanmaxBy( N, x, -2, 8, accessor ); + v = nanmaxBy( 5, x, -2, 8, accessor ); t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var N; var x; var v; @@ -278,8 +270,7 @@ tape( 'the function supports a negative `stride` parameter (accessors)', functio 2.0 ]; - N = floor( x.length / 2 ); - v = nanmaxBy( N, toAccessorArray( x ), -2, 8, accessor ); + v = nanmaxBy( 5, toAccessorArray( x ), -2, 8, accessor ); t.strictEqual( v, 8.0, 'returns expected value' ); t.end(); @@ -294,7 +285,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, x, 0, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // sparse array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, x, 0, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -310,7 +301,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, toAccessorArray( x ), 0, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // sparse array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, toAccessorArray( x ), 0, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); From 55eb92a95b018ca9497ae898c63decfc18ac79c6 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Wed, 4 Jun 2025 06:33:03 +0000 Subject: [PATCH 19/26] docs: udpate description --- 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: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/base/nanmax-by/README.md | 2 +- lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md index a3457cc6cfdf..558493ec96d1 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md @@ -32,7 +32,7 @@ var nanmaxBy = require( '@stdlib/stats/base/nanmax-by' ); #### nanmaxBy( N, x, strideX, clbk\[, thisArg] ) -Calculates the maximum value of strided array via a callback function, ignoring `NaN` values. +Computes the maximum value of strided array via a callback function, ignoring `NaN` values. ```javascript function accessor( v ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt index f44751e376a0..3a6bf888d26d 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt @@ -69,7 +69,7 @@ {{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] ) - Calculates the maximum value of a strided array via a callback function, + Computes the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. While typed array views mandate a view offset based on the underlying From 81e8b1e7234c936d41a1c58ce1e4ad7f1d683bbe Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Wed, 4 Jun 2025 06:34:24 +0000 Subject: [PATCH 20/26] docs: cleanup --- 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: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/nanmax-by/benchmark/benchmark.js | 2 +- lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js index cd8bf64706cb..883525265c6e 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js @@ -27,7 +27,7 @@ var bernoulli = require( '@stdlib/random/base/bernoulli' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; -var nanmaxBy = require( './../lib/nanmax_by.js' ); +var nanmaxBy = require( './../lib/main.js' ); // FUNCTIONS // diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js index 518d5462a702..b0814b0fad7d 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2020 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. From 4a704443226d02303a8d0bdb7839e0dcee1425f5 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 4 Jun 2025 02:00:59 -0700 Subject: [PATCH 21/26] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/nanmax-by/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md index 558493ec96d1..cc6b24435432 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md @@ -32,7 +32,7 @@ var nanmaxBy = require( '@stdlib/stats/base/nanmax-by' ); #### nanmaxBy( N, x, strideX, clbk\[, thisArg] ) -Computes the maximum value of strided array via a callback function, ignoring `NaN` values. +Computes the maximum value of a strided array via a callback function, ignoring `NaN` values. ```javascript function accessor( v ) { @@ -116,7 +116,7 @@ var v = nanmaxBy( 3, x1, 2, accessor ); #### nanmaxBy.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] ) -Computes the maximum value of strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. +Computes the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. ```javascript function accessor( v ) { From a5a0e330713dd31cbbf4363e473edadc17b5da98 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 4 Jun 2025 02:04:01 -0700 Subject: [PATCH 22/26] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/stats/base/nanmax-by/benchmark/benchmark.js | 5 ++--- .../stats/base/nanmax-by/benchmark/benchmark.ndarray.js | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js index 883525265c6e..bfc13ba47524 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js @@ -44,11 +44,10 @@ function accessor( value ) { } /** -* Accessor function. +* Returns a random number. * * @private -* @param {number} value - array element -* @returns {number} accessed value +* @returns {number} random number */ function rand() { if ( bernoulli( 0.8 ) < 1 ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js index aa645f6c381f..e4ee26cf6dce 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js @@ -44,11 +44,10 @@ function accessor( value ) { } /** -* Accessor function. +* Returns a random number. * * @private -* @param {number} value - array element -* @returns {number} accessed value +* @returns {number} random number */ function rand() { if ( bernoulli( 0.8 ) < 1 ) { From dfee50b0ab311a3834dc02dd398a8485ab8f238f Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 4 Jun 2025 02:05:29 -0700 Subject: [PATCH 23/26] style: remove empty line Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt index 3a6bf888d26d..d19a14e06764 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt @@ -110,7 +110,6 @@ > {{alias}}.ndarray( x.length, x, 1, 0, accessor ) 8.0 - // Using an index offset: > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; > {{alias}}.ndarray( 3, x, 2, 1, accessor ) From bf92cb2bb491d97e12b6b3d76ecd3d7b6c939330 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 4 Jun 2025 02:08:46 -0700 Subject: [PATCH 24/26] fix: use correct offset Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js index 6c6c7ae048c8..8295b1152f89 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js @@ -70,7 +70,7 @@ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { return NaN; } if ( N === 1 || strideX === 0 ) { - v = clbk.call( thisArg, get( xbuf, 0 ), 0, offsetX, x ); + v = clbk.call( thisArg, get( xbuf, offsetX ), 0, offsetX, x ); if ( v === void 0 || isnan( v ) ) { return NaN; } From 2f5c1635ca53306ef3bb3ae30553f0444ba4adb7 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 4 Jun 2025 02:09:52 -0700 Subject: [PATCH 25/26] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/stats/base/nanmax-by/lib/accessors.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js index 8295b1152f89..b6e1e8be659f 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js @@ -70,7 +70,7 @@ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { return NaN; } if ( N === 1 || strideX === 0 ) { - v = clbk.call( thisArg, get( xbuf, offsetX ), 0, offsetX, x ); + v = clbk.call( thisArg, get( xbuf, offsetX ), 0, offsetX, xbuf ); if ( v === void 0 || isnan( v ) ) { return NaN; } @@ -78,7 +78,7 @@ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { } ix = offsetX; for ( i = 0; i < N; i++ ) { - max = clbk.call( thisArg, get( xbuf, ix ), i, ix, x ); + max = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf ); if ( max === max && max !== void 0 ) { break; } @@ -90,7 +90,7 @@ function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) { i += 1; for ( i; i < N; i++ ) { ix += strideX; - v = clbk.call( thisArg, get( xbuf, ix ), i, ix, x ); + v = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf ); if ( v === void 0 || isnan( v ) ) { continue; } From 1ec869923753871e76a30108707c8458d36a5fb4 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 4 Jun 2025 02:14:25 -0700 Subject: [PATCH 26/26] Apply suggestions from code review Signed-off-by: Athan --- .../stats/base/nanmax-by/test/test.nanmax_by.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js index 80b00b8feee4..75b542f6da57 100644 --- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js +++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js @@ -75,11 +75,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array x[ 2 ] = 1.0; v = nanmaxBy( x.length, x, 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -111,11 +111,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array x[ 2 ] = 1.0; v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); @@ -162,7 +162,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, x, 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -178,7 +178,7 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -286,7 +286,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, x, 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, x, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); @@ -302,7 +302,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f v = nanmaxBy( x.length, toAccessorArray( x ), 0, accessor ); t.strictEqual( v, 2.0, 'returns expected value' ); - x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array v = nanmaxBy( 1, toAccessorArray( x ), 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' );