Skip to content

Commit 55940c4

Browse files
committed
refactor and add protocol support to stats/base/nanmin-by
1 parent 74d2527 commit 55940c4

File tree

14 files changed

+560
-129
lines changed

14 files changed

+560
-129
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,6 @@ jsconfig.json
192192
# Cursor #
193193
##########
194194
.cursorignore
195+
package.json
196+
etc/npm/deps.txt
197+
etc/npm/deps.txt

lib/node_modules/@stdlib/stats/base/nanmin-by/README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2020 The Stdlib Authors.
5+
Copyright (c) 2025 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ limitations under the License.
3030
var nanminBy = require( '@stdlib/stats/base/nanmin-by' );
3131
```
3232

33-
#### nanminBy( N, x, stride, clbk\[, thisArg] )
33+
#### nanminBy( N, x, strideX, clbk\[, thisArg] )
3434

3535
Calculates the minimum value of strided array `x` via a callback function, ignoring `NaN` values.
3636

@@ -49,7 +49,7 @@ The function has the following parameters:
4949

5050
- **N**: number of indexed elements.
5151
- **x**: input [`Array`][mdn-array], [`typed array`][mdn-typed-array], or an array-like object (excluding strings and functions).
52-
- **stride**: index increment.
52+
- **strideX**: index increment.
5353
- **clbk**: callback function.
5454
- **thisArg**: execution context (_optional_).
5555

@@ -81,7 +81,7 @@ var cnt = context.count;
8181
// returns 10
8282
```
8383

84-
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element
84+
The `N` and `strideX` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element
8585

8686
```javascript
8787
var floor = require( '@stdlib/math/base/special/floor' );
@@ -119,7 +119,7 @@ var v = nanminBy( N, x1, 2, accessor );
119119
// returns -12.0
120120
```
121121

122-
#### nanminBy.ndarray( N, x, stride, offset, clbk\[, thisArg] )
122+
#### nanminBy.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] )
123123

124124
Calculates the minimum value of strided array `x` via a callback function, ignoring `NaN` values and using alternative indexing semantics.
125125

@@ -136,9 +136,9 @@ var v = nanminBy.ndarray( x.length, x, 1, 0, accessor );
136136

137137
The function has the following additional parameters:
138138

139-
- **offset**: starting index.
139+
- **offsetX**: starting index.
140140

141-
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`
141+
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`
142142

143143
```javascript
144144
function accessor( v ) {
@@ -163,6 +163,7 @@ var v = nanminBy.ndarray( 3, x, 1, x.length-3, accessor );
163163
- A provided callback function should return a numeric value.
164164
- If a provided callback function returns `NaN`, the value is ignored.
165165
- If a provided callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored.
166+
- 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]).
166167
- When possible, prefer using [`dnanmin`][@stdlib/stats/strided/dnanmin], [`snanmin`][@stdlib/stats/strided/snanmin], and/or [`nanmin`][@stdlib/stats/base/nanmin], as, depending on the environment, these interfaces are likely to be significantly more performant.
167168

168169
</section>
@@ -176,23 +177,23 @@ var v = nanminBy.ndarray( 3, x, 1, x.length-3, accessor );
176177
<!-- eslint no-undef: "error" -->
177178

178179
```javascript
179-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
180-
var randu = require( '@stdlib/random/base/randu' );
180+
var uniform = require( '@stdlib/random/base/uniform' );
181181
var filledarrayBy = require( '@stdlib/array/filled-by' );
182+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
182183
var nanminBy = require( '@stdlib/stats/base/nanmin-by' );
183184

184-
function fill() {
185-
if ( randu() < 0.2 ) {
185+
function rand() {
186+
if( bernoulli( 0.8 ) < 1 ) {
186187
return NaN;
187188
}
188-
return discreteUniform( -50, 50 );
189+
return uniform( -50.0, 50.0 );
189190
}
190191

191192
function accessor( v ) {
192193
return v * 2.0;
193194
}
194195

195-
var x = filledarrayBy( 10, 'float64', fill );
196+
var x = filledarrayBy( 10, 'float64', rand );
196197
console.log( x );
197198

198199
var v = nanminBy( x.length, x, 1, accessor );

lib/node_modules/@stdlib/stats/base/nanmin-by/benchmark/benchmark.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2020 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,7 +21,9 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/base/uniform' );
25+
var filledarrayBy = require( '@stdlib/array/filled-by' );
26+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var pow = require( '@stdlib/math/base/special/pow' );
2729
var pkg = require( './../package.json' ).name;
@@ -37,6 +39,13 @@ var nanminBy = require( './../lib/nanmin_by.js' );
3739
* @param {number} value - array element
3840
* @returns {number} accessed value
3941
*/
42+
function rand() {
43+
if( bernoulli( 0.8 ) < 1 ) {
44+
return NaN;
45+
}
46+
return uniform( -50.0, 50.0 );
47+
}
48+
4049
function accessor( value ) {
4150
return value * 2.0;
4251
}
@@ -49,17 +58,7 @@ function accessor( value ) {
4958
* @returns {Function} benchmark function
5059
*/
5160
function createBenchmark( len ) {
52-
var x;
53-
var i;
54-
55-
x = [];
56-
for ( i = 0; i < len; i++ ) {
57-
if ( randu() < 0.2 ) {
58-
x.push( NaN );
59-
} else {
60-
x.push( ( randu()*20.0 ) - 10.0 );
61-
}
62-
}
61+
var x = filledarrayBy( len, "float64", rand );
6362
return benchmark;
6463

6564
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/nanmin-by/benchmark/benchmark.ndarray.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2020 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,7 +21,9 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/base/uniform' );
25+
var filledarrayBy = require( '@stdlib/array/filled-by' );
26+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var pow = require( '@stdlib/math/base/special/pow' );
2729
var pkg = require( './../package.json' ).name;
@@ -37,6 +39,13 @@ var nanminBy = require( './../lib/ndarray.js' );
3739
* @param {number} value - array element
3840
* @returns {number} accessed value
3941
*/
42+
function rand() {
43+
if( bernoulli( 0.8 ) < 1 ) {
44+
return NaN;
45+
}
46+
return uniform( -50.0, 50.0 );
47+
}
48+
4049
function accessor( value ) {
4150
return value * 2.0;
4251
}
@@ -49,17 +58,7 @@ function accessor( value ) {
4958
* @returns {Function} benchmark function
5059
*/
5160
function createBenchmark( len ) {
52-
var x;
53-
var i;
54-
55-
x = [];
56-
for ( i = 0; i < len; i++ ) {
57-
if ( randu() < 0.2 ) {
58-
x.push( NaN );
59-
} else {
60-
x.push( ( randu()*20.0 ) - 10.0 );
61-
}
62-
}
61+
var x = filledarrayBy( len, "float64", rand );
6362
return benchmark;
6463

6564
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/nanmin-by/docs/repl.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
{{alias}}( N, x, stride, clbk[, thisArg] )
2+
{{alias}}( N, x, strideX, clbk[, thisArg] )
33
Calculates the minimum value of a strided array via a callback function,
44
ignoring `NaN` values.
55

6-
The `N` and `stride` parameters determine which elements in `x` are accessed
6+
The `N` and `strideX` parameters determine which elements in `x` are accessed
77
at runtime.
88

99
Indexing is relative to the first index. To introduce an offset, use typed
@@ -34,7 +34,7 @@
3434
Input array/collection. If provided an object, the object must be array-
3535
like (excluding strings and functions).
3636

37-
stride: integer
37+
strideX: integer
3838
Index increment for `x`.
3939

4040
clbk: Function
@@ -56,7 +56,7 @@
5656
> {{alias}}( x.length, x, 1, accessor )
5757
-10.0
5858

59-
// Using `N` and `stride` parameters:
59+
// Using `N` and `strideX` parameters:
6060
> x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, NaN, -3.0 ];
6161
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
6262
> {{alias}}( N, x, 2, accessor )
@@ -69,12 +69,12 @@
6969
> {{alias}}( N, x1, 2, accessor )
7070
-12.0
7171

72-
{{alias}}.ndarray( N, x, stride, offset, clbk[, thisArg] )
72+
{{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] )
7373
Calculates the minimum value of a strided array via a callback function,
7474
ignoring `NaN` values and using alternative indexing semantics.
7575

7676
While typed array views mandate a view offset based on the underlying
77-
buffer, the `offset` parameter supports indexing semantics based on a
77+
buffer, the `offsetX` parameter supports indexing semantics based on a
7878
starting index.
7979

8080
Parameters
@@ -86,10 +86,10 @@
8686
Input array/collection. If provided an object, the object must be array-
8787
like (excluding strings and functions).
8888

89-
stride: integer
89+
strideX: integer
9090
Index increment for `x`.
9191

92-
offset: integer
92+
offsetX: integer
9393
Starting index of `x`.
9494

9595
clbk: Function

lib/node_modules/@stdlib/stats/base/nanmin-by/docs/types/index.d.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2020 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -20,7 +20,11 @@
2020

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

23-
import { Collection } from '@stdlib/types/array';
23+
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
24+
/**
25+
* Input array.
26+
*/
27+
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
2428

2529
/**
2630
* Returns an accessed value.
@@ -51,7 +55,7 @@ type Binary<T, U> = ( this: U, value: T, aidx: number ) => number | void;
5155
*
5256
* @param value - array element
5357
* @param aidx - array index
54-
* @param sidx - strided index (offset + aidx*stride)
58+
* @param sidx - strided index (offsetX + aidx*strideX)
5559
* @returns accessed value
5660
*/
5761
type Ternary<T, U> = ( this: U, value: T, aidx: number, sidx: number ) => number | void;
@@ -61,7 +65,7 @@ type Ternary<T, U> = ( this: U, value: T, aidx: number, sidx: number ) => number
6165
*
6266
* @param value - array element
6367
* @param aidx - array index
64-
* @param sidx - strided index (offset + aidx*stride)
68+
* @param sidx - strided index (offsetX + aidx*strideX)
6569
* @param array - input array
6670
* @returns accessed value
6771
*/
@@ -102,7 +106,7 @@ interface Routine {
102106
*
103107
* @param N - number of indexed elements
104108
* @param x - input array
105-
* @param stride - stride length
109+
* @param strideX - stride length
106110
* @param clbk - callback
107111
* @param thisArg - execution context
108112
* @returns minimum value
@@ -117,7 +121,7 @@ interface Routine {
117121
* var v = nanminBy( x.length, x, 1, accessor );
118122
* // returns -10.0
119123
*/
120-
<T = unknown, U = unknown>( N: number, x: Collection<T>, stride: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
124+
<T = unknown, U = unknown>( N: number, x: InputArray, stride: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
121125

122126
/**
123127
* Calculates the minimum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics.
@@ -139,8 +143,8 @@ interface Routine {
139143
*
140144
* @param N - number of indexed elements
141145
* @param x - input array
142-
* @param stride - stride length
143-
* @param offset - starting index
146+
* @param strideX - stride length
147+
* @param offsetX - starting index
144148
* @param clbk - callback
145149
* @param thisArg - execution context
146150
* @returns minimum value
@@ -155,7 +159,7 @@ interface Routine {
155159
* var v = nanminBy.ndarray( x.length, x, 1, 0, accessor );
156160
* // returns -10.0
157161
*/
158-
ndarray<T = unknown, U = unknown>( N: number, x: Collection<T>, stride: number, offset: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
162+
ndarray<T = unknown, U = unknown>( N: number, x: InputArray, strideX: number, offsetX: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
159163
}
160164

161165
/**
@@ -167,7 +171,7 @@ interface Routine {
167171
*
168172
* - `value`: array element
169173
* - `aidx`: array index
170-
* - `sidx`: strided index (offset + aidx*stride)
174+
* - `sidx`: strided index (offsetX + aidx*strideX)
171175
* - `array`: input array
172176
*
173177
* - The callback function should return a numeric value.
@@ -178,7 +182,7 @@ interface Routine {
178182
*
179183
* @param N - number of indexed elements
180184
* @param x - input array
181-
* @param stride - stride length
185+
* @param strideX - stride length
182186
* @param clbk - callback
183187
* @param thisArg - execution context
184188
* @returns minimum value

0 commit comments

Comments
 (0)