Skip to content

Commit 2b3a178

Browse files
committed
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: 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 653a95e commit 2b3a178

File tree

14 files changed

+620
-623
lines changed

14 files changed

+620
-623
lines changed

lib/node_modules/@stdlib/stats/base/stdevwd/README.md

Lines changed: 18 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note,
9898
var stdevwd = require( '@stdlib/stats/base/stdevwd' );
9999
```
100100

101-
#### stdevwd( N, correction, x, stride )
101+
#### stdevwd( N, correction, x, strideX )
102102

103-
Computes the [standard deviation][standard-deviation] of a strided array `x` using Welford's algorithm.
103+
Computes the [standard deviation][standard-deviation] of a strided array using Welford's algorithm.
104104

105105
```javascript
106106
var x = [ 1.0, -2.0, 2.0 ];
@@ -113,18 +113,15 @@ The function has the following parameters:
113113

114114
- **N**: number of indexed elements.
115115
- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [standard deviation][standard-deviation] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the corrected sample [standard deviation][standard-deviation], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction).
116-
- **x**: input [`Array`][mdn-array], [`typed array`][mdn-typed-array], or accessor array.
117-
- **stride**: index increment for `x`.
116+
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
117+
- **strideX**: stride length for `x`.
118118

119-
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [standard deviation][standard-deviation] of every other element in `x`,
119+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [standard deviation][standard-deviation] of every other element in `x`,
120120

121121
```javascript
122-
var floor = require( '@stdlib/math/base/special/floor' );
123-
124122
var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ];
125-
var N = floor( x.length / 2 );
126123

127-
var v = stdevwd( N, 1, x, 2 );
124+
var v = stdevwd( 4, 1, x, 2 );
128125
// returns 2.5
129126
```
130127

@@ -134,18 +131,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [
134131

135132
```javascript
136133
var Float64Array = require( '@stdlib/array/float64' );
137-
var floor = require( '@stdlib/math/base/special/floor' );
138134

139135
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
140136
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
141137

142-
var N = floor( x0.length / 2 );
143-
144-
var v = stdevwd( N, 1, x1, 2 );
138+
var v = stdevwd( 4, 1, x1, 2 );
145139
// returns 2.5
146140
```
147141

148-
#### stdevwd.ndarray( N, correction, x, stride, offset )
142+
#### stdevwd.ndarray( N, correction, x, strideX, offsetX )
149143

150144
Computes the [standard deviation][standard-deviation] of a strided array using Welford's algorithm and alternative indexing semantics.
151145

@@ -158,37 +152,17 @@ var v = stdevwd.ndarray( x.length, 1, x, 1, 0 );
158152

159153
The function has the following additional parameters:
160154

161-
- **offset**: starting index for `x`.
155+
- **offsetX**: starting index for `x`.
162156

163-
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 calculate the [standard deviation][standard-deviation] for every other value in `x` starting from the second value
157+
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 calculate the [standard deviation][standard-deviation] for every other element in the strided array starting from the second element
164158

165159
```javascript
166-
var floor = require( '@stdlib/math/base/special/floor' );
167-
168160
var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
169-
var N = floor( x.length / 2 );
170161

171-
var v = stdevwd.ndarray( N, 1, x, 2, 1 );
162+
var v = stdevwd.ndarray( 4, 1, x, 2, 1 );
172163
// returns 2.5
173164
```
174165

175-
```javascript
176-
var stdevwd = require( '@stdlib/stats/base/stdevwd' );
177-
178-
var accessorArray = {
179-
get(i) {
180-
return [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ][i];
181-
},
182-
set(i, v) {
183-
// No-op for this example
184-
},
185-
length: 8
186-
};
187-
188-
var v = stdevwd.ndarray( 4, 1, accessorArray, 2, 1 );
189-
console.log( v );
190-
```
191-
192166
</section>
193167

194168
<!-- /.usage -->
@@ -199,6 +173,7 @@ console.log( v );
199173

200174
- If `N <= 0`, both functions return `NaN`.
201175
- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`.
176+
- 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]).
202177
- Depending on the environment, the typed versions ([`dstdevwd`][@stdlib/stats/strided/dstdevwd], [`sstdevwd`][@stdlib/stats/base/sstdevwd], etc.) are likely to be significantly more performant.
203178

204179
</section>
@@ -212,43 +187,18 @@ console.log( v );
212187
<!-- eslint no-undef: "error" -->
213188

214189
```javascript
215-
var randu = require( '@stdlib/random/base/randu' );
216-
var round = require( '@stdlib/math/base/special/round' );
217-
var Float64Array = require( '@stdlib/array/float64' );
190+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
218191
var stdevwd = require( '@stdlib/stats/base/stdevwd' );
219192

220-
var x;
221-
var i;
222-
223-
x = new Float64Array( 10 );
224-
for ( i = 0; i < x.length; i++ ) {
225-
x[ i ] = round( (randu()*100.0) - 50.0 );
226-
}
193+
var x = discreteUniform( 10, -50, 50, {
194+
'dtype': 'float64'
195+
});
227196
console.log( x );
228197

229198
var v = stdevwd( x.length, 1, x, 1 );
230199
console.log( v );
231200
```
232201

233-
```javascript
234-
var stdevwd = require( '@stdlib/stats/base/stdevwd' );
235-
236-
var accessorArray = {
237-
get(i) {
238-
return [ 1.0, -2.0, 3.0, -4.0, 5.0 ][i];
239-
},
240-
set(i, v) {
241-
// No-op for this example
242-
},
243-
length: 5
244-
};
245-
246-
var v = stdevwd( accessorArray.length, 1, accessorArray, 1 );
247-
console.log( v );
248-
```
249-
250-
- The function supports accessor arrays, which provide an alternative way to define strided arrays using `get` and `set` methods for data access.
251-
252202
</section>
253203

254204
<!-- /.examples -->
@@ -294,6 +244,8 @@ console.log( v );
294244

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

247+
[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor
248+
297249
[@welford:1962a]: https://doi.org/10.1080/00401706.1962.10490022
298250

299251
[@vanreeken:1968a]: https://doi.org/10.1145/362929.362961

lib/node_modules/@stdlib/stats/base/stdevwd/benchmark/benchmark.js

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,75 +21,31 @@
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 stdevwd = require( './../lib/stdevwd.js' );
2929

3030

31-
// FUNCTIONS //
31+
// VARIABLES //
3232

33-
/**
34-
* Creates a benchmark function for a native array.
35-
*
36-
* @private
37-
* @param {PositiveInteger} len - array length
38-
* @returns {Function} benchmark function
39-
*/
40-
function createNativeBenchmark( len ) {
41-
var x;
42-
var i;
33+
var options = {
34+
'dtype': 'generic'
35+
};
4336

44-
x = new Array( len );
45-
for ( i = 0; i < len; i++ ) {
46-
x[ i ] = ( randu()*20.0 ) - 10.0;
47-
}
48-
return benchmark;
49-
50-
function benchmark( b ) {
51-
var v;
52-
var i;
5337

54-
b.tic();
55-
for ( i = 0; i < b.iterations; i++ ) {
56-
v = stdevwd( x.length, 1, x, 1 );
57-
if ( isnan( v ) ) {
58-
b.fail( 'should not return NaN' );
59-
}
60-
}
61-
b.toc();
62-
if ( isnan( v ) ) {
63-
b.fail( 'should not return NaN' );
64-
}
65-
b.pass( 'benchmark finished' );
66-
b.end();
67-
}
68-
}
38+
// FUNCTIONS //
6939

7040
/**
71-
* Creates a benchmark function for an accessor array.
41+
* Creates a benchmark function.
7242
*
7343
* @private
7444
* @param {PositiveInteger} len - array length
7545
* @returns {Function} benchmark function
7646
*/
77-
function createAccessorBenchmark( len ) {
78-
var data;
79-
var x;
80-
var i;
81-
82-
data = new Array( len );
83-
for ( i = 0; i < len; i++ ) {
84-
data[ i ] = ( randu()*20.0 ) - 10.0;
85-
}
86-
x = {
87-
'get': function get( i ) {
88-
return data[ i ];
89-
},
90-
'set': function set() {},
91-
'length': data.length
92-
};
47+
function createBenchmark( len ) {
48+
var x = uniform( len, -10, 10, options );
9349
return benchmark;
9450

9551
function benchmark( b ) {
@@ -132,11 +88,9 @@ function main() {
13288

13389
for ( i = min; i <= max; i++ ) {
13490
len = pow( 10, i );
135-
f = createNativeBenchmark( len );
136-
bench( pkg+':native:len='+len, f );
137-
f = createAccessorBenchmark( len );
138-
bench( pkg+':accessors:len='+len, f );
91+
f = createBenchmark( len );
92+
bench( pkg+':len='+len, f );
13993
}
14094
}
14195

142-
main();
96+
main();

lib/node_modules/@stdlib/stats/base/stdevwd/benchmark/benchmark.ndarray.js

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -21,75 +21,31 @@
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 stdevwd = require( './../lib/ndarray.js' );
2929

3030

31-
// FUNCTIONS //
31+
// VARIABLES //
3232

33-
/**
34-
* Creates a benchmark function for a native array.
35-
*
36-
* @private
37-
* @param {PositiveInteger} len - array length
38-
* @returns {Function} benchmark function
39-
*/
40-
function createNativeBenchmark( len ) {
41-
var x;
42-
var i;
33+
var options = {
34+
'dtype': 'generic'
35+
};
4336

44-
x = new Array( len );
45-
for ( i = 0; i < len; i++ ) {
46-
x[ i ] = ( randu()*20.0 ) - 10.0;
47-
}
48-
return benchmark;
49-
50-
function benchmark( b ) {
51-
var v;
52-
var i;
5337

54-
b.tic();
55-
for ( i = 0; i < b.iterations; i++ ) {
56-
v = stdevwd( x.length, 1, x, 1, 0 );
57-
if ( isnan( v ) ) {
58-
b.fail( 'should not return NaN' );
59-
}
60-
}
61-
b.toc();
62-
if ( isnan( v ) ) {
63-
b.fail( 'should not return NaN' );
64-
}
65-
b.pass( 'benchmark finished' );
66-
b.end();
67-
}
68-
}
38+
// FUNCTIONS //
6939

7040
/**
71-
* Creates a benchmark function for an accessor array.
41+
* Creates a benchmark function.
7242
*
7343
* @private
7444
* @param {PositiveInteger} len - array length
7545
* @returns {Function} benchmark function
7646
*/
77-
function createAccessorBenchmark( len ) {
78-
var data;
79-
var x;
80-
var i;
81-
82-
data = new Array( len );
83-
for ( i = 0; i < len; i++ ) {
84-
data[ i ] = ( randu()*20.0 ) - 10.0;
85-
}
86-
x = {
87-
'get': function get( i ) {
88-
return data[ i ];
89-
},
90-
'set': function set() {},
91-
'length': data.length
92-
};
47+
function createBenchmark( len ) {
48+
var x = uniform( len, -10, 10, options );
9349
return benchmark;
9450

9551
function benchmark( b ) {
@@ -132,11 +88,9 @@ function main() {
13288

13389
for ( i = min; i <= max; i++ ) {
13490
len = pow( 10, i );
135-
f = createNativeBenchmark( len );
136-
bench( pkg+':ndarray:native:len='+len, f );
137-
f = createAccessorBenchmark( len );
138-
bench( pkg+':ndarray:accessors:len='+len, f );
91+
f = createBenchmark( len );
92+
bench( pkg+':ndarray:len='+len, f );
13993
}
14094
}
14195

142-
main();
96+
main();

0 commit comments

Comments
 (0)