Skip to content

Commit 0cac3f8

Browse files
committed
feat: add support for accessor arrays and refactor stats/base/stdevyc
1 parent 41058a4 commit 0cac3f8

File tree

7 files changed

+88
-52
lines changed

7 files changed

+88
-52
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ 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 stdevyc = require( './../lib/main.js' );
29-
30-
29+
30+
3131
// VARIABLES //
32-
32+
3333
var options = {
3434
'dtype': 'generic'
3535
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var pkg = require( './../package.json' ).name;
2828
var stdevyc = require( './../lib/ndarray.js' );
2929

3030
// VARIABLES //
31-
31+
3232
var options = {
3333
'dtype': 'generic'
3434
};

lib/node_modules/@stdlib/stats/base/stdevyc/lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
4646
var main = require( './main.js' );
4747
var ndarray = require( './ndarray.js' );
48-
49-
48+
49+
5050
// MAIN //
51-
51+
5252
setReadOnly( main, 'ndarray', ndarray );
5353

5454
// EXPORTS //

lib/node_modules/@stdlib/stats/base/stdevyc/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var ndarray = require( './ndarray.js' );
4646
* // returns ~2.0817
4747
*/
4848
function stdevyc( N, correction, x, strideX ) {
49-
return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) );
49+
return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) );
5050
}
5151

5252
// EXPORTS //

lib/node_modules/@stdlib/stats/base/stdevyc/lib/ndarray.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ var varianceyc = require( '@stdlib/stats/base/varianceyc' ).ndarray;
5050
* // returns ~2.0817
5151
*/
5252
function stdevyc( N, correction, x, strideX, offsetX ) {
53-
var o;
54-
55-
if ( N <= 0 ) {
56-
return NaN;
57-
}
58-
o = arraylike2object( x );
59-
if ( o.accessorProtocol ) {
60-
return accessors( N, correction, o, strideX, offsetX );
61-
}
62-
return sqrt( varianceyc( N, correction, x, strideX, offsetX ) );
53+
var o;
54+
55+
if ( N <= 0 ) {
56+
return NaN;
57+
}
58+
o = arraylike2object( x );
59+
if ( o.accessorProtocol ) {
60+
return accessors( N, correction, o, strideX, offsetX );
61+
}
62+
return sqrt( varianceyc( N, correction, x, strideX, offsetX ) );
6363
}
6464

6565

lib/node_modules/@stdlib/stats/base/stdevyc/lib/stdevyc.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ var varianceyc = require( '@stdlib/stats/base/varianceyc' ).ndarray;
4949
* // returns ~2.0817
5050
*/
5151
function stdevyc( N, correction, x, strideX, offsetX ) {
52-
var o;
53-
54-
if ( N <= 0 ) {
55-
return NaN;
56-
}
57-
o = arraylike2object( x );
58-
if ( o.accessorProtocol ) {
59-
return accessors( N, correction, o, strideX, offsetX );
60-
}
61-
return sqrt( varianceyc( N, correction, x, strideX, offsetX ) );
52+
var o;
53+
54+
if ( N <= 0 ) {
55+
return NaN;
56+
}
57+
o = arraylike2object( x );
58+
if ( o.accessorProtocol ) {
59+
return accessors( N, correction, o, strideX, offsetX );
60+
}
61+
return sqrt( varianceyc( N, correction, x, strideX, offsetX ) );
6262
}
6363

6464

lib/node_modules/@stdlib/stats/base/stdevyc/test/test.ndarray.js

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,30 +59,25 @@ tape( 'the function calculates the population standard deviation of a strided ar
5959
t.end();
6060
});
6161

62-
tape( 'the function calculates the standard deviation of a strided array (accessors)', function test( t ) {
63-
var x;
64-
var v;
65-
66-
x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ];
67-
v = stdevyc( x.length, 0, toAccessorArray( x ), 1, 0 );
68-
t.strictEqual( v, sqrt( 53.5 / x.length ), 'returns expected value' );
62+
tape( 'the function calculates the population standard deviation of a strided array (accessor)', function test( t ) {
63+
var x;
64+
var v;
6965

70-
x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ];
71-
v = stdevyc( x.length, 1, toAccessorArray( x ), 1, 0 );
72-
t.strictEqual( v, sqrt( 53.5 / (x.length - 1) ), 'returns expected value' );
66+
x = toAccessorArray( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] );
67+
v = stdevyc( x.length, 0, x, 1, 0 );
68+
t.strictEqual( v, sqrt( 53.5/x.length ), 'returns expected value' );
7369

74-
x = [ -4.0, -4.0 ];
75-
v = stdevyc( x.length, 0, toAccessorArray( x ), 1, 0 );
76-
t.strictEqual( v, 0.0, 'returns expected value' );
70+
x = [ -4.0, -4.0 ];
71+
v = stdevyc( x.length, 0, x, 1, 0 );
72+
t.strictEqual( v, 0.0, 'returns expected value' );
7773

78-
x = [ NaN, 4.0 ];
79-
v = stdevyc( x.length, 0, toAccessorArray( x ), 1, 0 );
80-
t.strictEqual( isnan( v ), true, 'returns expected value' );
74+
x = [ NaN, 4.0 ];
75+
v = stdevyc( x.length, 0, x, 1, 0 );
76+
t.strictEqual( isnan( v ), true, 'returns expected value' );
8177

82-
t.end();
78+
t.end();
8379
});
8480

85-
8681
tape( 'the function calculates the sample standard deviation of a strided array', function test( t ) {
8782
var x;
8883
var v;
@@ -117,6 +112,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
117112
t.end();
118113
});
119114

115+
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) {
116+
var x;
117+
var v;
118+
119+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
120+
121+
v = stdevyc( 0, 1, toAccessorArray( x ), 1, 0 );
122+
t.strictEqual( isnan( v ), true, 'returns expected value' );
123+
124+
v = stdevyc( -1, 1, toAccessorArray( x ), 1, 0 );
125+
t.strictEqual( isnan( v ), true, 'returns expected value' );
126+
127+
t.end();
128+
});
129+
120130
tape( 'if provided an `N` parameter equal to `1`, the function returns a population standard deviation of `0`', function test( t ) {
121131
var x;
122132
var v;
@@ -129,6 +139,18 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a populat
129139
t.end();
130140
});
131141

142+
tape( 'if provided an `N` parameter equal to `1`, the function returns a population standard deviation of `0` (accessor)', function test( t ) {
143+
var x;
144+
var v;
145+
146+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
147+
148+
v = stdevyc( 1, 0, toAccessorArray( x ), 1, 0 );
149+
t.strictEqual( v, 0.0, 'returns expected value' );
150+
151+
t.end();
152+
});
153+
132154
tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) {
133155
var x;
134156
var v;
@@ -144,6 +166,21 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or
144166
t.end();
145167
});
146168

169+
tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN` (accessor)', function test( t ) {
170+
var x;
171+
var v;
172+
173+
x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
174+
175+
v = stdevyc( x.length, x.length, toAccessorArray( x ), 1, 0 );
176+
t.strictEqual( isnan( v ), true, 'returns expected value' );
177+
178+
v = stdevyc( x.length, x.length+1, toAccessorArray( x ), 1, 0 );
179+
t.strictEqual( isnan( v ), true, 'returns expected value' );
180+
181+
t.end();
182+
});
183+
147184
tape( 'the function supports a `stride` parameter', function test( t ) {
148185
var x;
149186
var v;
@@ -165,7 +202,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
165202
t.end();
166203
});
167204

168-
tape( 'the function supports a `stride` parameter', function test( t ) {
205+
tape( 'the function supports a `stride` parameter (accessor)', function test( t ) {
169206
var x;
170207
var v;
171208

@@ -207,7 +244,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
207244
t.end();
208245
});
209246

210-
tape( 'the function supports a negative `stride` parameter', function test( t ) {
247+
tape( 'the function supports a negative `stride` parameter (accessor)', function test( t ) {
211248
var x;
212249
var v;
213250

@@ -228,7 +265,6 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
228265
t.end();
229266
});
230267

231-
232268
tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) {
233269
var x;
234270
var v;
@@ -241,7 +277,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`',
241277
t.end();
242278
});
243279

244-
tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) {
280+
tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessor)', function test( t ) {
245281
var x;
246282
var v;
247283

@@ -274,7 +310,7 @@ tape( 'the function supports an `offset` parameter', function test( t ) {
274310
t.end();
275311
});
276312

277-
tape( 'the function supports an `offset` parameter', function test( t ) {
313+
tape( 'the function supports an `offset` parameter (accessor)', function test( t ) {
278314
var x;
279315
var v;
280316

@@ -293,4 +329,4 @@ tape( 'the function supports an `offset` parameter', function test( t ) {
293329
t.strictEqual( v, 2.5, 'returns expected value' );
294330

295331
t.end();
296-
});
332+
});

0 commit comments

Comments
 (0)