Skip to content

Commit 1a0c328

Browse files
Om-A-osckgryte
andauthored
refactor: reuse variance in stats/base/dists/chi/stdev
PR-URL: #11365 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent af81941 commit 1a0c328

File tree

3 files changed

+8
-22
lines changed

3 files changed

+8
-22
lines changed

lib/node_modules/@stdlib/stats/base/dists/chi/stdev/lib/main.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@
2020

2121
// MODULES //
2222

23-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
24-
var mean = require( '@stdlib/stats/base/dists/chi/mean' );
2523
var sqrt = require( '@stdlib/math/base/special/sqrt' );
24+
var variance = require( '@stdlib/stats/base/dists/chi/variance' );
2625

2726

2827
// MAIN //
@@ -50,12 +49,7 @@ var sqrt = require( '@stdlib/math/base/special/sqrt' );
5049
* // returns NaN
5150
*/
5251
function stdev( k ) {
53-
var mu;
54-
if ( isnan( k ) || k < 0.0 ) {
55-
return NaN;
56-
}
57-
mu = mean( k );
58-
return sqrt( k - ( mu*mu ) );
52+
return sqrt( variance( k ) );
5953
}
6054

6155

lib/node_modules/@stdlib/stats/base/dists/chi/stdev/manifest.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@
3939
"libpath": [],
4040
"dependencies": [
4141
"@stdlib/math/base/napi/unary",
42-
"@stdlib/math/base/assert/is-nan",
4342
"@stdlib/math/base/special/sqrt",
44-
"@stdlib/stats/base/dists/chi/mean"
43+
"@stdlib/stats/base/dists/chi/variance"
4544
]
4645
},
4746
{
@@ -56,9 +55,8 @@
5655
"libraries": [],
5756
"libpath": [],
5857
"dependencies": [
59-
"@stdlib/math/base/assert/is-nan",
6058
"@stdlib/math/base/special/sqrt",
61-
"@stdlib/stats/base/dists/chi/mean"
59+
"@stdlib/stats/base/dists/chi/variance"
6260
]
6361
},
6462
{
@@ -73,9 +71,8 @@
7371
"libraries": [],
7472
"libpath": [],
7573
"dependencies": [
76-
"@stdlib/math/base/assert/is-nan",
7774
"@stdlib/math/base/special/sqrt",
78-
"@stdlib/stats/base/dists/chi/mean"
75+
"@stdlib/stats/base/dists/chi/variance"
7976
]
8077
}
8178
]

lib/node_modules/@stdlib/stats/base/dists/chi/stdev/src/main.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/stats/base/dists/chi/mean.h"
20-
#include "stdlib/math/base/assert/is_nan.h"
19+
#include "stdlib/stats/base/dists/chi/stdev.h"
20+
#include "stdlib/stats/base/dists/chi/variance.h"
2121
#include "stdlib/math/base/special/sqrt.h"
2222

2323
/**
@@ -31,10 +31,5 @@
3131
* // returns ~0.697
3232
*/
3333
double stdlib_base_dists_chi_stdev( const double k ) {
34-
double mu;
35-
if ( stdlib_base_is_nan( k ) || k < 0.0 ) {
36-
return 0.0/0.0; // NaN
37-
}
38-
mu = stdlib_base_dists_chi_mean( k );
39-
return stdlib_base_sqrt( k - ( mu*mu ) );
34+
return stdlib_base_sqrt( stdlib_base_dists_chi_variance( k ) );
4035
}

0 commit comments

Comments
 (0)