From c4ef5500174a0d77a90b1a72be560938ac56d58d Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 20 Jan 2025 11:21:00 -0500 Subject: [PATCH] chore: minor clean-up --- 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: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - 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: passed - 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 --- --- .../stdlib/stats/base/dists/chisquare/mgf.h | 4 -- .../base/dists/cosine/median/test/test.js | 12 +--- .../dists/cosine/median/test/test.native.js | 12 +--- .../base/dists/degenerate/logpmf/README.md | 2 +- .../degenerate/stdev/benchmark/c/benchmark.c | 57 +++++++++++++++---- .../stats/base/dists/degenerate/stdev.h | 3 - .../base/dists/degenerate/stdev/src/addon.c | 2 +- .../base/dists/degenerate/stdev/src/main.c | 1 + .../dists/weibull/cdf/test/test.native.js | 2 +- .../dists/weibull/logcdf/test/test.native.js | 2 +- .../dists/weibull/logpdf/test/test.native.js | 2 +- 11 files changed, 53 insertions(+), 46 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/chisquare/mgf/include/stdlib/stats/base/dists/chisquare/mgf.h b/lib/node_modules/@stdlib/stats/base/dists/chisquare/mgf/include/stdlib/stats/base/dists/chisquare/mgf.h index ec1ea5bef17a..6fff5fb95c6e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chisquare/mgf/include/stdlib/stats/base/dists/chisquare/mgf.h +++ b/lib/node_modules/@stdlib/stats/base/dists/chisquare/mgf/include/stdlib/stats/base/dists/chisquare/mgf.h @@ -29,10 +29,6 @@ extern "C" { /** * Evaluates the moment-generating function (MGF) for a chi-squared distribution * with degrees of freedom `k` at a value `t`. -* -* @param t input value -* @param k degrees of freedom (must be non-negative) -* @return evaluated MGF */ double stdlib_base_dists_chisquare_mgf( const double t, const double k ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/cosine/median/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/cosine/median/test/test.js index 4efd33fe143d..94145b6e63b7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/cosine/median/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/dists/cosine/median/test/test.js @@ -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 median = require( './../lib' ); @@ -79,8 +77,6 @@ tape( 'if provided a nonpositive `s`, the function returns `NaN`', function test tape( 'the function returns the median of a raised cosine distribution', function test( t ) { var expected; - var delta; - var tol; var mu; var s; var y; @@ -92,13 +88,7 @@ tape( 'the function returns the median of a raised cosine distribution', functio for ( i = 0; i < mu.length; i++ ) { y = median( 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 = 1.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(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/cosine/median/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/cosine/median/test/test.native.js index f01cbd74cd4b..3219565ec020 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/cosine/median/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/cosine/median/test/test.native.js @@ -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' ); @@ -88,8 +86,6 @@ tape( 'if provided a nonpositive `s`, the function returns `NaN`', opts, functio tape( 'the function returns the median of a raised cosine distribution', opts, function test( t ) { var expected; - var delta; - var tol; var mu; var s; var y; @@ -101,13 +97,7 @@ tape( 'the function returns the median of a raised cosine distribution', opts, f for ( i = 0; i < mu.length; i++ ) { y = median( 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 = 1.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(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/logpmf/README.md b/lib/node_modules/@stdlib/stats/base/dists/degenerate/logpmf/README.md index 9bd59db4f12d..a34c51a090ef 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/logpmf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/logpmf/README.md @@ -125,7 +125,7 @@ for ( i = 0; i < 100; i++ ) { #### stdlib_base_dists_degenerate_logpmf( x, mu ) -Evaluate the natural logarithm of the [probability mass function][pmf] (PMF) for a [degenerate distribution][degenerate-distribution]. +Evaluates the natural logarithm of the [probability mass function][pmf] (PMF) for a [degenerate distribution][degenerate-distribution]. ```c double out = stdlib_base_dists_degenerate_logpmf( 2.0, 3.0 ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/benchmark/c/benchmark.c index 1d544ef512da..9ee8cc9ef2ec 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/benchmark/c/benchmark.c @@ -17,9 +17,9 @@ */ #include "stdlib/stats/base/dists/degenerate/stdev.h" -#include -#include #include +#include +#include #include #include @@ -27,10 +27,19 @@ #define ITERATIONS 1000000 #define REPEATS 3 +/** +* Prints the TAP version. +*/ static void print_version( void ) { printf( "TAP version 13\n" ); } +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ static void print_summary( int total, int passing ) { printf( "#\n" ); printf( "1..%d\n", total ); // TAP plan @@ -40,6 +49,11 @@ static void print_summary( int total, int passing ) { printf( "# ok\n" ); } +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ static void print_results( double elapsed ) { double rate = (double)ITERATIONS / elapsed; printf( " ---\n" ); @@ -49,49 +63,68 @@ static void print_results( double elapsed ) { printf( " ...\n" ); } +/** +* Returns a clock time. +* +* @return clock time +*/ static double tic( void ) { struct timeval now; gettimeofday( &now, NULL ); - return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; } +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ static double random_uniform( const double min, const double max ) { double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); - return min + ( v * ( max - min ) ); + return min + ( v*(max-min) ); } +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ static double benchmark( void ) { double elapsed; double mu[ 100 ]; double y; - double start; + double t; int i; for ( i = 0; i < 100; i++ ) { mu[ i ] = random_uniform( -20.0, 20.0 ); } - start = tic(); + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { y = stdlib_base_dists_degenerate_stdev( mu[ i % 100 ] ); - if ( isnan( y ) ) { + if ( y != y ) { printf( "should not return NaN\n" ); break; } } - elapsed = tic() - start; - - if ( isnan( y ) ) { + elapsed = tic() - t; + if ( y != y ) { printf( "should not return NaN\n" ); } return elapsed; } +/** +* Main execution sequence. +*/ int main( void ) { double elapsed; int i; - // Seed the random number generator: + // Use the current time to seed the random number generator: srand( time( NULL ) ); print_version(); @@ -99,7 +132,7 @@ int main( void ) { printf( "# c::%s\n", NAME ); elapsed = benchmark(); print_results( elapsed ); - printf( "ok %d benchmark finished\n", i + 1 ); + printf( "ok %d benchmark finished\n", i+1 ); } print_summary( REPEATS, REPEATS ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/include/stdlib/stats/base/dists/degenerate/stdev.h b/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/include/stdlib/stats/base/dists/degenerate/stdev.h index 2c0306b91790..367628709a93 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/include/stdlib/stats/base/dists/degenerate/stdev.h +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/include/stdlib/stats/base/dists/degenerate/stdev.h @@ -28,9 +28,6 @@ extern "C" { /** * Returns the standard deviation of a degenerate distribution centered at `mu`. -* -* @param mu constant value of the distribution -* @return standard deviation */ double stdlib_base_dists_degenerate_stdev( const double mu ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/src/addon.c index 880a08e50998..a04547262d27 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/src/addon.c @@ -16,8 +16,8 @@ * limitations under the License. */ -#include "stdlib/math/base/napi/unary.h" #include "stdlib/stats/base/dists/degenerate/stdev.h" +#include "stdlib/math/base/napi/unary.h" // cppcheck-suppress shadowFunction STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_dists_degenerate_stdev ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/src/main.c index 14c0e9d22a2b..e48b172ab408 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/stdev/src/main.c @@ -16,6 +16,7 @@ * limitations under the License. */ +#include "stdlib/stats/base/dists/degenerate/stdev.h" #include "stdlib/math/base/assert/is_nan.h" /** diff --git a/lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/test/test.native.js index 35ec3d09effc..80fd4941bcaf 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/weibull/cdf/test/test.native.js @@ -47,7 +47,7 @@ var opts = { // TESTS // -tape( 'main export is a function', opts, opts, function test( t ) { +tape( 'main export is a function', opts, function test( t ) { t.ok( true, __filename ); t.strictEqual( typeof cdf, 'function', 'main export is a function' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/weibull/logcdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/weibull/logcdf/test/test.native.js index bb26d94924c2..e44dd2ac5409 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/weibull/logcdf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/weibull/logcdf/test/test.native.js @@ -47,7 +47,7 @@ var opts = { // TESTS // -tape( 'main export is a function', opts, opts, opts, function test( t ) { +tape( 'main export is a function', opts, function test( t ) { t.ok( true, __filename ); t.strictEqual( typeof cdf, 'function', 'main export is a function' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/weibull/logpdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/weibull/logpdf/test/test.native.js index bc6b5af7702f..1120767706bf 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/weibull/logpdf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/weibull/logpdf/test/test.native.js @@ -48,7 +48,7 @@ var opts = { // TESTS // -tape( 'main export is a function', opts, opts, opts, function test( t ) { +tape( 'main export is a function', opts, function test( t ) { t.ok( true, __filename ); t.strictEqual( typeof cdf, 'function', 'main export is a function' ); t.end();