Skip to content

Commit 9b98e3f

Browse files
committed
refactor: reduce FLOPs
--- 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: 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: na - task: lint_license_headers status: passed ---
1 parent 1212357 commit 9b98e3f

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

lib/node_modules/@stdlib/stats/base/dists/triangular/logpdf/lib/factory.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function factory( a, b, c ) {
4949
var denom1;
5050
var denom2;
5151
var denom3;
52+
var v;
5253

5354
if (
5455
isnan( a ) ||
@@ -59,10 +60,10 @@ function factory( a, b, c ) {
5960
) {
6061
return constantFunction( NaN );
6162
}
62-
63-
denom1 = ln( b - a ) + ln( c - a );
64-
denom2 = ln( b - a );
65-
denom3 = ln( b - a ) + ln( b - c );
63+
v = ln( b - a );
64+
denom1 = v + ln( c - a );
65+
denom2 = v;
66+
denom3 = v + ln( b - c );
6667
return logpdf;
6768

6869
/**

lib/node_modules/@stdlib/stats/base/dists/triangular/logpdf/lib/main.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ var LN2 = require( '@stdlib/constants/float64/ln-two' );
7474
* // returns NaN
7575
*/
7676
function logpdf( x, a, b, c ) {
77-
var denom1;
78-
var denom2;
79-
var denom3;
80-
8177
if (
8278
isnan( x ) ||
8379
isnan( a ) ||
@@ -91,20 +87,16 @@ function logpdf( x, a, b, c ) {
9187
if ( x < a ) {
9288
return NINF;
9389
}
94-
denom1 = ln( b - a ) + ln( c - a );
95-
denom2 = ln( b - a );
96-
denom3 = ln( b - a ) + ln( b - c );
97-
9890
// Case: x >= a
9991
if ( x < c ) {
100-
return LN2 + ln( x - a ) - denom1;
92+
return LN2 + ln( x - a ) - ln( b - a ) - ln( c - a );
10193
}
10294
if ( x === c ) {
103-
return LN2 - denom2;
95+
return LN2 - ln( b - a );
10496
}
10597
// Case: x > c
10698
if ( x <= b ) {
107-
return LN2 + ln( b - x ) - denom3;
99+
return LN2 + ln( b - x ) - ln( b - a ) - ln( b - c );
108100
}
109101
// Case: x > b
110102
return NINF;

0 commit comments

Comments
 (0)