Skip to content

Commit 867c513

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into stats-array-nanrange-by
2 parents 12d8d95 + 4f78b17 commit 867c513

File tree

29 files changed

+949
-258
lines changed

29 files changed

+949
-258
lines changed

lib/node_modules/@stdlib/stats/array/mskrange/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ limitations under the License.
2424
2525
<section class="intro">
2626

27+
The [**range**][range] is defined as the difference between the maximum and minimum values.
28+
2729
</section>
2830

2931
<!-- /.intro -->

lib/node_modules/@stdlib/stats/array/nanmskrange/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ limitations under the License.
2424
2525
<section class="intro">
2626

27+
The [**range**][range] is defined as the difference between the maximum and minimum values.
28+
2729
</section>
2830

2931
<!-- /.intro -->

lib/node_modules/@stdlib/stats/array/nanrange/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ limitations under the License.
2424
2525
<section class="intro">
2626

27+
The [**range**][range] is defined as the difference between the maximum and minimum values.
28+
2729
</section>
2830

2931
<!-- /.intro -->

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ limitations under the License.
2424
2525
<section class="intro">
2626

27+
The [**range**][range] is defined as the difference between the maximum and minimum values.
28+
2729
</section>
2830

2931
<!-- /.intro -->

lib/node_modules/@stdlib/stats/array/range/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ limitations under the License.
2424
2525
<section class="intro">
2626

27+
The [**range**][range] is defined as the difference between the maximum and minimum values.
28+
2729
</section>
2830

2931
<!-- /.intro -->

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ The [**range**][range] is defined as the difference between the maximum and mini
3838
var nanrangeBy = require( '@stdlib/stats/base/nanrange-by' );
3939
```
4040

41-
#### nanrangeBy( N, x, stride, clbk\[, thisArg] )
41+
#### nanrangeBy( N, x, strideX, clbk\[, thisArg] )
4242

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

4545
```javascript
4646
function accessor( v ) {
@@ -57,7 +57,7 @@ The function has the following parameters:
5757

5858
- **N**: number of indexed elements.
5959
- **x**: input [`Array`][mdn-array], [`typed array`][mdn-typed-array], or an array-like object (excluding strings and functions).
60-
- **stride**: index increment.
60+
- **strideX**: stride length.
6161
- **clbk**: callback function.
6262
- **thisArg**: execution context (_optional_).
6363

@@ -89,27 +89,23 @@ var cnt = context.count;
8989
// returns 10
9090
```
9191

92-
The `N` and `stride` 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, NaN, NaN ];
102-
var N = floor( x.length / 2 );
103100

104-
var v = nanrangeBy( N, x, 2, accessor );
101+
var v = nanrangeBy( 5, 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 = nanrangeBy( N, x1, 2, accessor );
121+
var v = nanrangeBy( 3, x1, 2, accessor );
127122
// returns 8.0
128123
```
129124

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

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

134129
```javascript
135130
function accessor( v ) {
@@ -144,9 +139,9 @@ var v = nanrangeBy.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 ) {
@@ -171,6 +166,7 @@ var v = nanrangeBy.ndarray( 3, x, 1, x.length-3, accessor );
171166
- A provided callback function should return a numeric value.
172167
- If a provided callback function returns `NaN`, the value is ignored.
173168
- If a provided callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored.
169+
- 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]).
174170
- When possible, prefer using [`dnanrange`][@stdlib/stats/strided/dnanrange], [`snanrange`][@stdlib/stats/strided/snanrange], and/or [`nanrange`][@stdlib/stats/base/nanrange], as, depending on the environment, these interfaces are likely to be significantly more performant.
175171

176172
</section>
@@ -184,23 +180,23 @@ var v = nanrangeBy.ndarray( 3, x, 1, x.length-3, accessor );
184180
<!-- eslint no-undef: "error" -->
185181

186182
```javascript
187-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
188-
var randu = require( '@stdlib/random/base/randu' );
183+
var uniform = require( '@stdlib/random/base/uniform' );
189184
var filledarrayBy = require( '@stdlib/array/filled-by' );
185+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
190186
var nanrangeBy = require( '@stdlib/stats/base/nanrange-by' );
191187

192-
function fill() {
193-
if ( randu() < 0.2 ) {
188+
function rand() {
189+
if ( bernoulli( 0.8 ) < 0.2 ) {
194190
return NaN;
195191
}
196-
return discreteUniform( -50, 50 );
192+
return uniform( -50.0, 50.0 );
197193
}
198194

199195
function accessor( v ) {
200196
return v * 2.0;
201197
}
202198

203-
var x = filledarrayBy( 10, 'float64', fill );
199+
var x = filledarrayBy( 10, 'float64', rand );
204200
console.log( x );
205201

206202
var v = nanrangeBy( x.length, x, 1, accessor );
@@ -240,6 +236,8 @@ console.log( v );
240236

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

239+
[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor
240+
243241
<!-- <related-links> -->
244242

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

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
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;
28-
var nanrangeBy = require( './../lib/nanrange_by.js' );
30+
var nanrangeBy = require( './../lib/main.js' );
2931

3032

3133
// FUNCTIONS //
@@ -41,6 +43,19 @@ function accessor( value ) {
4143
return value * 2.0;
4244
}
4345

46+
/**
47+
* Returns a random number.
48+
*
49+
* @private
50+
* @returns {number} random number
51+
*/
52+
function rand() {
53+
if ( bernoulli( 0.8 ) < 1 ) {
54+
return NaN;
55+
}
56+
return uniform( -50.0, 50.0 );
57+
}
58+
4459
/**
4560
* Create a benchmark function.
4661
*
@@ -49,17 +64,7 @@ function accessor( value ) {
4964
* @returns {Function} benchmark function
5065
*/
5166
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-
}
67+
var x = filledarrayBy( len, 'generic', rand );
6368
return benchmark;
6469

6570
function benchmark( b ) {

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -41,6 +43,19 @@ function accessor( value ) {
4143
return value * 2.0;
4244
}
4345

46+
/**
47+
* Returns a random number.
48+
*
49+
* @private
50+
* @returns {number} random number
51+
*/
52+
function rand() {
53+
if ( bernoulli( 0.8 ) < 1 ) {
54+
return NaN;
55+
}
56+
return uniform( -50.0, 50.0 );
57+
}
58+
4459
/**
4560
* Create a benchmark function.
4661
*
@@ -49,17 +64,7 @@ function accessor( value ) {
4964
* @returns {Function} benchmark function
5065
*/
5166
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-
}
67+
var x = filledarrayBy( len, 'generic', rand );
6368
return benchmark;
6469

6570
function benchmark( b ) {

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

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

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

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

37-
stride: integer
38-
Index increment for `x`.
37+
strideX: integer
38+
Stride length.
3939

4040
clbk: Function
4141
Callback function.
@@ -56,25 +56,24 @@
5656
> {{alias}}( x.length, x, 1, accessor )
5757
18.0
5858

59-
// Using `N` and `stride` parameters:
59+
// Using `N` and stride parameters:
6060
> x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0, 1.0 ];
61-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
62-
> {{alias}}( N, x, 2, accessor )
61+
> {{alias}}( 4, x, 2, accessor )
6362
14.0
6463

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

72-
{{alias}}.ndarray( N, x, stride, offset, clbk[, thisArg] )
70+
71+
{{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] )
7372
Calculates the range of a strided array via a callback function, ignoring
7473
`NaN` values and using alternative indexing semantics.
7574

7675
While typed array views mandate a view offset based on the underlying
77-
buffer, the `offset` parameter supports indexing semantics based on a
76+
buffer, the offset parameter supports indexing semantics based on a
7877
starting index.
7978

8079
Parameters
@@ -86,11 +85,11 @@
8685
Input array/collection. If provided an object, the object must be array-
8786
like (excluding strings and functions).
8887

89-
stride: integer
90-
Index increment for `x`.
88+
strideX: integer
89+
Stride length.
9190

92-
offset: integer
93-
Starting index of `x`.
91+
offsetX: integer
92+
Starting index.
9493

9594
clbk: Function
9695
Callback function.
@@ -113,8 +112,7 @@
113112

114113
// Using an index offset:
115114
> x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
116-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
117-
> {{alias}}.ndarray( N, x, 2, 1, accessor )
115+
> {{alias}}.ndarray( 3, x, 2, 1, accessor )
118116
8.0
119117

120118
See Also

0 commit comments

Comments
 (0)