Skip to content

Commit c155b43

Browse files
committed
refactor: reapply suggestions from PR review
--- 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: 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: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent ab08e1e commit c155b43

File tree

5 files changed

+48
-14
lines changed

5 files changed

+48
-14
lines changed

lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ double stdlib_base_dists_degenerate_mgf( const double t, const double mu );
195195
### Examples
196196
197197
```c
198-
#include "stdlib/math/base/special/round.h"
199198
#include "stdlib/stats/base/dists/degenerate/mgf.h"
199+
#include "stdlib/math/base/special/round.h"
200200
#include <stdlib.h>
201201
#include <stdio.h>
202202

lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/benchmark/c/benchmark.c

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,29 @@
1717
*/
1818

1919
#include "stdlib/stats/base/dists/degenerate/mgf.h"
20-
#include <math.h>
21-
#include <stdio.h>
2220
#include <stdlib.h>
21+
#include <stdio.h>
22+
#include <math.h>
2323
#include <time.h>
2424
#include <sys/time.h>
2525

2626
#define NAME "degenerate-mgf"
2727
#define ITERATIONS 1000000
2828
#define REPEATS 3
2929

30+
/**
31+
* Prints the TAP version.
32+
*/
3033
static void print_version( void ) {
3134
printf( "TAP version 13\n" );
3235
}
3336

37+
/**
38+
* Prints the TAP summary.
39+
*
40+
* @param total total number of tests
41+
* @param passing total number of passing tests
42+
*/
3443
static void print_summary( int total, int passing ) {
3544
printf( "#\n" );
3645
printf( "1..%d\n", total ); // TAP plan
@@ -40,6 +49,11 @@ static void print_summary( int total, int passing ) {
4049
printf( "# ok\n" );
4150
}
4251

52+
/**
53+
* Prints benchmarks results.
54+
*
55+
* @param elapsed elapsed time in seconds
56+
*/
4357
static void print_results( double elapsed ) {
4458
double rate = (double)ITERATIONS / elapsed;
4559
printf( " ---\n" );
@@ -49,34 +63,51 @@ static void print_results( double elapsed ) {
4963
printf( " ...\n" );
5064
}
5165

66+
/**
67+
* Returns a clock time.
68+
*
69+
* @return clock time
70+
*/
5271
static double tic( void ) {
5372
struct timeval now;
5473
gettimeofday( &now, NULL );
5574
return (double)now.tv_sec + (double)now.tv_usec / 1.0e6;
5675
}
5776

77+
/**
78+
* Generates a random number on the interval [min,max).
79+
*
80+
* @param min minimum value (inclusive)
81+
* @param max maximum value (exclusive)
82+
* @return random number
83+
*/
5884
static double random_uniform( const double min, const double max ) {
5985
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
6086
return min + ( v * ( max - min ) );
6187
}
6288

89+
/**
90+
* Runs a benchmark.
91+
*
92+
* @return elapsed time in seconds
93+
*/
6394
static double benchmark( void ) {
64-
double elapsed;
65-
double t[ 100 ];
6695
double mu[ 100 ];
67-
double y;
96+
double t[ 100 ];
97+
double elapsed;
6898
double start;
99+
double y;
69100
int i;
70101

71102
for ( i = 0; i < 100; i++ ) {
72-
t[ i ] = random_uniform( -10.0, 10.0 );
73-
mu[ i ] = random_uniform( -20.0, 20.0 );
103+
t[ i ] = random_uniform( -10.0, 0.0 );
104+
mu[ i ] = random_uniform( -50.0, 50.0 );
74105
}
75106

76107
start = tic();
77108
for ( i = 0; i < ITERATIONS; i++ ) {
78109
y = stdlib_base_dists_degenerate_mgf( t[ i % 100 ], mu[ i % 100 ] );
79-
if ( y != y ) { // Check for NaN
110+
if ( y != y ) {
80111
printf( "should not return NaN\n" );
81112
break;
82113
}
@@ -89,11 +120,14 @@ static double benchmark( void ) {
89120
return elapsed;
90121
}
91122

123+
/**
124+
* Main execution sequence.
125+
*/
92126
int main( void ) {
93127
double elapsed;
94128
int i;
95129

96-
// Seed the random number generator:
130+
// Use the current time to seed the random number generator:
97131
srand( time( NULL ) );
98132

99133
print_version();

lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/examples/c/example.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/math/base/special/round.h"
2019
#include "stdlib/stats/base/dists/degenerate/mgf.h"
21-
#include <stdio.h>
20+
#include "stdlib/math/base/special/round.h"
2221
#include <stdlib.h>
22+
#include <stdio.h>
2323

2424
static double random_uniform( const double min, const double max ) {
2525
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );

lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/lib/native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var addon = require( './../src/addon.node' );
3030
*
3131
* @private
3232
* @param {number} t - input value
33-
* @param {number} mu - constant value of the distribution
33+
* @param {number} mu - value at which to center the distribution
3434
* @returns {number} evaluated MGF
3535
*
3636
* @example

lib/node_modules/@stdlib/stats/base/dists/degenerate/mgf/src/addon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "stdlib/math/base/napi/binary.h"
2019
#include "stdlib/stats/base/dists/degenerate/mgf.h"
20+
#include "stdlib/math/base/napi/binary.h"
2121

2222
// cppcheck-suppress shadowFunction
2323
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_degenerate_mgf )

0 commit comments

Comments
 (0)