Skip to content

Commit

Permalink
chore: minor clean-up
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: 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
---
  • Loading branch information
Planeshifter committed Jan 20, 2025
1 parent a99f045 commit c4ef550
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
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 median = 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 median 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 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();
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 median 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 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,29 @@
*/

#include "stdlib/stats/base/dists/degenerate/stdev.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <sys/time.h>

#define NAME "degenerate-stdev"
#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
Expand All @@ -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" );
Expand All @@ -49,57 +63,76 @@ 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();
for ( i = 0; i < REPEATS; i++ ) {
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 );
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include "stdlib/stats/base/dists/degenerate/stdev.h"
#include "stdlib/math/base/assert/is_nan.h"

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c4ef550

Please sign in to comment.