Skip to content

Commit

Permalink
refactor: precompute constant
Browse files Browse the repository at this point in the history
---
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: passed
  - 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: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
  • Loading branch information
Planeshifter committed Jan 20, 2025
1 parent 7403869 commit b0790e4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
// MODULES //

var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var PI_SQUARED = require( '@stdlib/constants/float64/pi-squared' );


// VARIABLES //

var COSINE_EXCESS_KURTOSIS = -0.5937628755982794; // 6(90-π^4)/(5(π^4-6)^2)


// MAIN //
Expand Down Expand Up @@ -55,17 +58,14 @@ var PI_SQUARED = require( '@stdlib/constants/float64/pi-squared' );
* // returns NaN
*/
function kurtosis( mu, s ) {
var out;
if (
isnan( mu ) ||
isnan( s ) ||
s <= 0.0
) {
return NaN;
}
out = 6.0 * ( 90.0 - ( PI_SQUARED*PI_SQUARED ) );
out /= 5.0 * pow( PI_SQUARED-6.0, 2.0 );
return out;
return COSINE_EXCESS_KURTOSIS;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/binary",
"@stdlib/math/base/assert/is-nan",
"@stdlib/constants/float64/eps",
"@stdlib/math/base/special/pow",
"@stdlib/constants/float64/pi-squared"
"@stdlib/math/base/assert/is-nan"
]
},
{
Expand All @@ -58,9 +55,7 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/constants/float64/eps",
"@stdlib/math/base/special/pow",
"@stdlib/constants/float64/pi-squared"
"@stdlib/constants/float64/eps"
]
},
{
Expand All @@ -76,9 +71,7 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/is-nan",
"@stdlib/constants/float64/eps",
"@stdlib/math/base/special/pow",
"@stdlib/constants/float64/pi-squared"
"@stdlib/constants/float64/eps"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include "stdlib/stats/base/dists/cosine/kurtosis.h"
#include "stdlib/math/base/assert/is_nan.h"
#include "stdlib/math/base/special/pow.h"
#include "stdlib/constants/float64/pi_squared.h"

static const double COSINE_EXCESS_KURTOSIS = -0.5937628755982794; // 6(90-π^4)/(5(π^4-6)^2)

/**
* Returns the excess kurtosis of a raised cosine distribution.
Expand All @@ -40,7 +40,5 @@ double stdlib_base_dists_cosine_kurtosis( const double mu, const double s ) {
) {
return 0.0/0.0; // NaN
}
double out = 6.0 * ( 90.0 - ( STDLIB_CONSTANT_FLOAT64_PI_SQUARED*STDLIB_CONSTANT_FLOAT64_PI_SQUARED ) );
out /= 5.0 * stdlib_base_pow( STDLIB_CONSTANT_FLOAT64_PI_SQUARED-6.0, 2.0 );
return out;
return COSINE_EXCESS_KURTOSIS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@

var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var kurtosis = require( './../lib' );


Expand Down Expand Up @@ -79,8 +77,6 @@ tape( 'if provided a nonpositive `s`, the function returns `NaN`', function test

tape( 'the function returns the excess kurtosis of a raised cosine distribution', function test( t ) {
var expected;
var delta;
var tol;
var mu;
var s;
var y;
Expand All @@ -92,13 +88,7 @@ tape( 'the function returns the excess kurtosis of a raised cosine distribution'
for ( i = 0; i < mu.length; i++ ) {
y = kurtosis( mu[i], s[i] );
if ( expected[i] !== null ) {
if ( y === expected[i] ) {
t.equal( y, expected[i], 'mu:'+mu[i]+', s: '+s[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 10.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. mu: '+mu[i]+'. s: '+s[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.equal( y, expected[i], 'mu:'+mu[i]+', s: '+s[i]+', y: '+y+', expected: '+expected[i] );
}
}
t.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
var resolve = require( 'path' ).resolve;
var tape = require( 'tape' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand Down Expand Up @@ -88,8 +86,6 @@ tape( 'if provided a nonpositive `s`, the function returns `NaN`', opts, functio

tape( 'the function returns the excess kurtosis of a raised cosine distribution', opts, function test( t ) {
var expected;
var delta;
var tol;
var mu;
var s;
var y;
Expand All @@ -101,13 +97,7 @@ tape( 'the function returns the excess kurtosis of a raised cosine distribution'
for ( i = 0; i < mu.length; i++ ) {
y = kurtosis( mu[i], s[i] );
if ( expected[i] !== null ) {
if ( y === expected[i] ) {
t.equal( y, expected[i], 'mu:'+mu[i]+', s: '+s[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = 10.0 * EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. mu: '+mu[i]+'. s: '+s[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
}
t.equal( y, expected[i], 'mu:'+mu[i]+', s: '+s[i]+', y: '+y+', expected: '+expected[i] );
}
}
t.end();
Expand Down

0 comments on commit b0790e4

Please sign in to comment.