Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor and add protocol support to stats/base/nanmax-by #6469

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
28 changes: 14 additions & 14 deletions lib/node_modules/@stdlib/stats/base/nanmax-by/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand All @@ -49,15 +49,15 @@ 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_).

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`.
Expand All @@ -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' );
Expand Down Expand Up @@ -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.

Expand All @@ -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 ) {
Expand Down Expand Up @@ -176,23 +176,23 @@ var v = nanmaxBy.ndarray( 3, x, 1, x.length-3, accessor );
<!-- eslint no-undef: "error" -->

```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 );
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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 ) {
Expand Down
17 changes: 9 additions & 8 deletions lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

{{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
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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 );
Expand Down
30 changes: 17 additions & 13 deletions lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,7 +20,11 @@

/// <reference types="@stdlib/types"/>

import { Collection } from '@stdlib/types/array';
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
/**
* Input array.
*/
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;

/**
* Returns an accessed value.
Expand Down Expand Up @@ -51,7 +55,7 @@ type Binary<T, U> = ( 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<T, U> = ( this: U, value: T, aidx: number, sidx: number ) => number | void;
Expand All @@ -61,7 +65,7 @@ type Ternary<T, U> = ( 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
*/
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -117,7 +121,7 @@ interface Routine {
* var v = nanmaxBy( x.length, x, 1, accessor );
* // returns 8.0
*/
<T = unknown, U = unknown>( N: number, x: Collection<T>, stride: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
<T = unknown, U = unknown>( N: number, x: InputArray, strideX: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;

/**
* Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -155,7 +159,7 @@ interface Routine {
* var v = nanmaxBy.ndarray( x.length, x, 1, 0, accessor );
* // returns 8.0
*/
ndarray<T = unknown, U = unknown>( N: number, x: Collection<T>, stride: number, offset: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
ndarray<T = unknown, U = unknown>( N: number, x: InputArray, strideX: number, offsetX: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
}

/**
Expand All @@ -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.
Expand All @@ -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
Expand Down
Loading
Loading