Skip to content

Commit 7a7a8ce

Browse files
committed
added JSDoc comment
1 parent 9e97729 commit 7a7a8ce

File tree

1 file changed

+12
-13
lines changed
  • lib/node_modules/@stdlib/stats/base/variancewd/lib

1 file changed

+12
-13
lines changed

lib/node_modules/@stdlib/stats/base/variancewd/lib/accessors.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
'use strict';
2020

21+
// MAIN //
22+
2123
/**
2224
* Computes the variance of a strided array using Welford's algorithm and accessors.
2325
*
@@ -43,8 +45,7 @@
4345
* var v = variancewd( x.data.length, 1, x, 1, 0 );
4446
* // returns 10.0
4547
*/
46-
47-
function variancewd(N, correction, x, strideX, offsetX) {
48+
function variancewd( N, correction, x, strideX, offsetX ) {
4849
var delta2;
4950
var delta;
5051
var xbuf;
@@ -57,24 +58,26 @@ function variancewd(N, correction, x, strideX, offsetX) {
5758
var i;
5859

5960
n = N - correction;
60-
if (N <= 0 || n <= 0.0) {
61+
if ( N <= 0 || n <= 0.0 ) {
6162
return NaN;
6263
}
63-
if (N === 1 || strideX === 0) {
64+
if ( N === 1 || strideX === 0 ) {
6465
return 0.0;
6566
}
6667

68+
// Cache reference to array data:
6769
xbuf = x.data;
68-
get = x.accessors[0];
70+
// Cache a reference to the element accessor:
71+
get = x.accessors[ 0 ];
6972

7073
ix = offsetX;
7174
M2 = 0.0;
7275
mu = 0.0;
7376

74-
for (i = 0; i < N; i++) {
75-
v = get(xbuf, ix);
77+
for ( i = 0; i < N; i++ ) {
78+
v = get( xbuf, ix );
7679
delta = v - mu;
77-
mu += delta / (i + 1);
80+
mu += delta / ( i + 1 );
7881
delta2 = v - mu;
7982
M2 += delta * delta2;
8083
ix += strideX;
@@ -83,9 +86,5 @@ function variancewd(N, correction, x, strideX, offsetX) {
8386
return M2 / n;
8487
}
8588

86-
/**
87-
* Exports function for computing the variance of a strided array using Welford's algorithm and accessors.
88-
*
89-
* @type {Function}
90-
*/
89+
// EXPORTS //
9190
module.exports = variancewd;

0 commit comments

Comments
 (0)