Skip to content

Commit fca8e7b

Browse files
committed
chore: update docs, test, 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: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 4cf14a3 commit fca8e7b

File tree

15 files changed

+413
-239
lines changed

15 files changed

+413
-239
lines changed

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2025 The Stdlib Authors.
5+
Copyright (c) 2020 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.
@@ -40,7 +40,7 @@ var rangeBy = require( '@stdlib/stats/base/range-by' );
4040

4141
#### rangeBy( N, x, strideX, clbk\[, thisArg] )
4242

43-
Calculates the [range][range] of strided array `x` via a callback function.
43+
Computes the [range][range] of a strided array via a callback function.
4444

4545
```javascript
4646
function accessor( v ) {
@@ -89,27 +89,23 @@ var cnt = context.count;
8989
// returns 8
9090
```
9191

92-
The `N` and `strideX` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element
92+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element
9393

9494
```javascript
95-
var floor = require( '@stdlib/math/base/special/floor' );
96-
9795
function accessor( v ) {
9896
return v * 2.0;
9997
}
10098

10199
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
102-
var N = floor( x.length / 2 );
103100

104-
var v = rangeBy( N, x, 2, accessor );
101+
var v = rangeBy( 4, x, 2, accessor );
105102
// returns 12.0
106103
```
107104

108105
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
109106

110107
```javascript
111108
var Float64Array = require( '@stdlib/array/float64' );
112-
var floor = require( '@stdlib/math/base/special/floor' );
113109

114110
function accessor( v ) {
115111
return v * 2.0;
@@ -120,16 +116,15 @@ var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
120116

121117
// Create an offset view...
122118
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
123-
var N = floor( x0.length/2 );
124119

125120
// Access every other element...
126-
var v = rangeBy( N, x1, 2, accessor );
121+
var v = rangeBy( 3, x1, 2, accessor );
127122
// returns 8.0
128123
```
129124

130-
#### rangeBy.ndarray( N, x, strideX, offset, clbk\[, thisArg] )
125+
#### rangeBy.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] )
131126

132-
Calculates the [range][range] of strided array `x` via a callback function and using alternative indexing semantics.
127+
Computes the [range][range] of a strided array via a callback function and using alternative indexing semantics.
133128

134129
```javascript
135130
function accessor( v ) {
@@ -144,9 +139,9 @@ var v = rangeBy.ndarray( x.length, x, 1, 0, accessor );
144139

145140
The function has the following additional parameters:
146141

147-
- **offset**: starting index.
142+
- **offsetX**: starting index.
148143

149-
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`
144+
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`
150145

151146
```javascript
152147
function accessor( v ) {
@@ -170,6 +165,7 @@ var v = rangeBy.ndarray( 3, x, 1, x.length-3, accessor );
170165
- If `N <= 0`, both functions return `NaN`.
171166
- A provided callback function should return a numeric value.
172167
- If a provided callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is **ignored**.
168+
- 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]).
173169
- When possible, prefer using [`drange`][@stdlib/stats/strided/drange], [`srange`][@stdlib/stats/strided/srange], and/or [`range`][@stdlib/stats/base/range], as, depending on the environment, these interfaces are likely to be significantly more performant.
174170

175171
</section>
@@ -183,15 +179,16 @@ var v = rangeBy.ndarray( 3, x, 1, x.length-3, accessor );
183179
<!-- eslint no-undef: "error" -->
184180

185181
```javascript
186-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
187-
var filledarrayBy = require( '@stdlib/array/filled-by' );
182+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
188183
var rangeBy = require( '@stdlib/stats/base/range-by' );
189184

190185
function accessor( v ) {
191186
return v * 2.0;
192187
}
193188

194-
var x = filledarrayBy( 10, 'float64', discreteUniform( -50, 50 ) );
189+
var x = discreteUniform( 10, -50, 50, {
190+
'dtype': 'float64'
191+
});
195192
console.log( x );
196193

197194
var v = rangeBy( x.length, x, 1, accessor );
@@ -231,6 +228,8 @@ console.log( v );
231228

232229
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
233230

231+
[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor
232+
234233
<!-- <related-links> -->
235234

236235
[@stdlib/stats/strided/drange]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/drange

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2020 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.

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2020 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,13 +21,20 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var pkg = require( './../package.json' ).name;
2828
var rangeBy = require( './../lib/ndarray.js' );
2929

3030

31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'generic'
35+
};
36+
37+
3138
// FUNCTIONS //
3239

3340
/**
@@ -49,13 +56,7 @@ function accessor( value ) {
4956
* @returns {Function} benchmark function
5057
*/
5158
function createBenchmark( len ) {
52-
var x;
53-
var i;
54-
55-
x = [];
56-
for ( i = 0; i < len; i++ ) {
57-
x.push( ( randu()*20.0 ) - 10.0 );
58-
}
59+
var x = uniform( len, -10, 10, options );
5960
return benchmark;
6061

6162
function benchmark( b ) {

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
12
{{alias}}( N, x, strideX, clbk[, thisArg] )
2-
Calculates the range of a strided array via a callback function.
3+
Computes the range of a strided array via a callback function.
34

4-
The `N` and `stride` parameters determine which elements in `x` are accessed
5-
at runtime.
5+
The `N` and stride parameters determine which elements in the strided array
6+
are accessed at runtime.
67

78
Indexing is relative to the first index. To introduce an offset, use typed
89
array views.
@@ -13,7 +14,7 @@
1314

1415
- value: array element.
1516
- aidx: array index.
16-
- sidx: strided index (offsetX + aidx*strideX).
17+
- sidx: strided index (offset + aidx*stride).
1718
- array: the input array.
1819

1920
The callback function should return a numeric value.
@@ -31,7 +32,7 @@
3132
like (excluding strings and functions).
3233

3334
strideX: integer
34-
Index increment for `x`.
35+
Stride length.
3536

3637
clbk: Function
3738
Callback function.
@@ -52,17 +53,15 @@
5253
> {{alias}}( x.length, x, 1, accessor )
5354
18.0
5455

55-
// Using `N` and `strideX` parameters:
56+
// Using `N` and stride parameters:
5657
> x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ];
57-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
58-
> {{alias}}( N, x, 2, accessor )
58+
> {{alias}}( 3, x, 2, accessor )
5959
12.0
6060

6161
// Using view offsets:
6262
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
6363
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
64-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
65-
> {{alias}}( N, x1, 2, accessor )
64+
> {{alias}}( 3, x1, 2, accessor )
6665
8.0
6766

6867

@@ -71,7 +70,7 @@
7170
alternative indexing semantics.
7271

7372
While typed array views mandate a view offset based on the underlying
74-
buffer, the `offsetX` parameter supports indexing semantics based on a
73+
buffer, the offset parameter supports indexing semantics based on a
7574
starting index.
7675

7776
Parameters
@@ -84,10 +83,10 @@
8483
like (excluding strings and functions).
8584

8685
strideX: integer
87-
Index increment for `x`.
86+
Stride length.
8887

8988
offsetX: integer
90-
Starting index of `x`.
89+
Starting index.
9190

9291
clbk: Function
9392
Callback function.
@@ -110,8 +109,7 @@
110109

111110
// Using an index offset:
112111
> x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
113-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
114-
> {{alias}}.ndarray( N, x, 2, 1, accessor )
112+
> {{alias}}.ndarray( 3, x, 2, 1, accessor )
115113
8.0
116114

117115
See Also

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

Lines changed: 9 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) 2025 The Stdlib Authors.
4+
* Copyright (c) 2020 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,10 +20,8 @@
2020

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

23-
// import { Collection } from '@stdlib/types/array';
2423
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
2524

26-
2725
/**
2826
* Input array.
2927
*/
@@ -72,7 +70,7 @@ type Ternary<T, U> = ( this: U, value: T, aidx: number, sidx: number ) => number
7270
* @param array - input array
7371
* @returns accessed value
7472
*/
75-
type Quaternary<T, U> = ( this: U, value: T, aidx: number, sidx: number, array: InputArray ) => number | void;
73+
type Quaternary<T, U> = ( this: U, value: T, aidx: number, sidx: number, array: Collection<T> ) => number | void;
7674

7775
/**
7876
* Returns an accessed value.
@@ -90,7 +88,7 @@ type Callback<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U> |
9088
*/
9189
interface Routine {
9290
/**
93-
* Calculates the range of a strided array via a callback function.
91+
* Computes the range of a strided array via a callback function.
9492
*
9593
* ## Notes
9694
*
@@ -120,10 +118,10 @@ interface Routine {
120118
* var v = rangeBy( x.length, x, 1, accessor );
121119
* // returns 18.0
122120
*/
123-
<T = unknown, U = unknown>( N: number, x: InputArray, stride: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
121+
<T = unknown, U = unknown>( N: number, x: InputArray, strideX: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
124122

125123
/**
126-
* Calculates the range of a strided array via a callback function and using alternative indexing semantics.
124+
* Computes the range of a strided array via a callback function and using alternative indexing semantics.
127125
*
128126
* ## Notes
129127
*
@@ -138,8 +136,8 @@ interface Routine {
138136
*
139137
* @param N - number of indexed elements
140138
* @param x - input array
141-
* @param stride - stride length
142-
* @param offset - starting index
139+
* @param strideX - stride length
140+
* @param offsetX - starting index
143141
* @param clbk - callback
144142
* @param thisArg - execution context
145143
* @returns range
@@ -154,7 +152,7 @@ interface Routine {
154152
* var v = rangeBy.ndarray( x.length, x, 1, 0, accessor );
155153
* // returns 18.0
156154
*/
157-
ndarray<T = unknown, U = unknown>( N: number, x: InputArray, stride: number, offset: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
155+
ndarray<T = unknown, U = unknown>( N: number, x: InputArray, strideX: number, offsetX: number, clbk: Callback<T, U>, thisArg?: ThisParameterType<Callback<T, U>> ): number;
158156
}
159157

160158
/**
@@ -173,7 +171,7 @@ interface Routine {
173171
*
174172
* @param N - number of indexed elements
175173
* @param x - input array
176-
* @param stride - stride length
174+
* @param strideX - stride length
177175
* @param clbk - callback
178176
* @param thisArg - execution context
179177
* @returns range

lib/node_modules/@stdlib/stats/base/range-by/docs/types/test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2020 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.
@@ -16,8 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19-
import rangeBy = require( '@stdlib/stats/base/range-by' );
2019
import AccessorArray = require( '@stdlib/array/base/accessor' );
20+
import rangeBy = require( './index' );
2121

2222
const accessor = (): number => {
2323
return 5.0;
@@ -31,8 +31,9 @@ const accessor = (): number => {
3131
const x = new Float64Array( 10 );
3232

3333
rangeBy( x.length, x, 1, accessor ); // $ExpectType number
34-
rangeBy( x.length, x, 1, accessor, {} ); // $ExpectType number
3534
rangeBy( x.length, new AccessorArray ( x ), 1, accessor ); // $ExpectType number
35+
36+
rangeBy( x.length, x, 1, accessor, {} ); // $ExpectType number
3637
rangeBy( x.length, new AccessorArray ( x ), 1, accessor, {} ); // $ExpectType number
3738
}
3839

@@ -105,8 +106,9 @@ const accessor = (): number => {
105106
const x = new Float64Array( 10 );
106107

107108
rangeBy.ndarray( x.length, x, 1, 0, accessor ); // $ExpectType number
108-
rangeBy.ndarray( x.length, x, 1, 0, accessor, {} ); // $ExpectType number
109109
rangeBy.ndarray( x.length, new AccessorArray ( x ), 1, 0, accessor ); // $ExpectType number
110+
111+
rangeBy.ndarray( x.length, x, 1, 0, accessor, {} ); // $ExpectType number
110112
rangeBy.ndarray( x.length, new AccessorArray ( x ), 1, 0, accessor, {} ); // $ExpectType number
111113
}
112114

0 commit comments

Comments
 (0)