Skip to content

Commit 5cd5cdc

Browse files
committed
refactor: reuse variance in chi/stdev 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - 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: na - task: lint_license_headers status: passed ---
1 parent 1cae4f4 commit 5cd5cdc

3 files changed

Lines changed: 7 additions & 22 deletions

File tree

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: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +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"
2119
#include "stdlib/math/base/special/sqrt.h"
20+
#include "stdlib/stats/base/dists/chi/variance.h"
2221

2322
/**
2423
* Returns the standard deviation of a chi distribution.
@@ -31,10 +30,5 @@
3130
* // returns ~0.697
3231
*/
3332
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 ) );
33+
return stdlib_base_sqrt( stdlib_base_dists_chi_variance( k ) );
4034
}

0 commit comments

Comments
 (0)