Skip to content

Commit 60ec33b

Browse files
committed
chore: 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 e0354c6 commit 60ec33b

File tree

6 files changed

+60
-24
lines changed

6 files changed

+60
-24
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ double stdlib_base_dists_degenerate_pmf( const double x, const double mu );
160160
### Examples
161161
162162
```c
163-
#include "stdlib/math/base/special/round.h"
164163
#include "stdlib/stats/base/dists/degenerate/pmf.h"
164+
#include "stdlib/math/base/special/round.h"
165165
#include <stdlib.h>
166166
#include <stdio.h>
167167
@@ -172,8 +172,8 @@ static double random_uniform( const double min, const double max ) {
172172
173173
int main( void ) {
174174
double result;
175-
double x;
176175
double mu;
176+
double x;
177177
int i;
178178
179179
for ( i = 0; i < 10; i++ ) {

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

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,30 @@
1717
*/
1818

1919
#include "stdlib/stats/base/dists/degenerate/pmf.h"
20-
#include <math.h>
21-
#include <stdio.h>
20+
#include "stdlib/math/base/special/ceil.h"
2221
#include <stdlib.h>
22+
#include <stdio.h>
23+
#include <math.h>
2324
#include <time.h>
2425
#include <sys/time.h>
2526

2627
#define NAME "degenerate-pmf"
2728
#define ITERATIONS 1000000
2829
#define REPEATS 3
2930

31+
/**
32+
* Prints the TAP version.
33+
*/
3034
static void print_version( void ) {
3135
printf( "TAP version 13\n" );
3236
}
3337

38+
/**
39+
* Prints the TAP summary.
40+
*
41+
* @param total total number of tests
42+
* @param passing total number of passing tests
43+
*/
3444
static void print_summary( int total, int passing ) {
3545
printf( "#\n" );
3646
printf( "1..%d\n", total ); // TAP plan
@@ -40,6 +50,11 @@ static void print_summary( int total, int passing ) {
4050
printf( "# ok\n" );
4151
}
4252

53+
/**
54+
* Prints benchmarks results.
55+
*
56+
* @param elapsed elapsed time in seconds
57+
*/
4358
static void print_results( double elapsed ) {
4459
double rate = (double)ITERATIONS / elapsed;
4560
printf( " ---\n" );
@@ -49,34 +64,51 @@ static void print_results( double elapsed ) {
4964
printf( " ...\n" );
5065
}
5166

67+
/**
68+
* Returns a clock time.
69+
*
70+
* @return clock time
71+
*/
5272
static double tic( void ) {
5373
struct timeval now;
5474
gettimeofday( &now, NULL );
55-
return (double)now.tv_sec + (double)now.tv_usec / 1.0e6;
75+
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
5676
}
5777

78+
/**
79+
* Generates a random number on the interval [min,max).
80+
*
81+
* @param min minimum value (inclusive)
82+
* @param max maximum value (exclusive)
83+
* @return random number
84+
*/
5885
static double random_uniform( const double min, const double max ) {
5986
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
60-
return min + ( v * ( max - min ) );
87+
return min + ( v*(max-min) );
6188
}
6289

90+
/**
91+
* Runs a benchmark.
92+
*
93+
* @return elapsed time in seconds
94+
*/
6395
static double benchmark( void ) {
64-
double elapsed;
65-
double x[ 100 ];
6696
double mu[ 100 ];
67-
double y;
97+
double x[ 100 ];
98+
double elapsed;
6899
double start;
100+
double y;
69101
int i;
70102

71103
for ( i = 0; i < 100; i++ ) {
72-
x[ i ] = random_uniform( -10.0, 10.0 );
73-
mu[ i ] = random_uniform( -20.0, 20.0 );
104+
x[ i ] = stdlib_base_ceil( random_uniform( -100.0, 0.0 ) );
105+
mu[ i ] = random_uniform( -50.0, 50.0 );
74106
}
75107

76108
start = tic();
77109
for ( i = 0; i < ITERATIONS; i++ ) {
78110
y = stdlib_base_dists_degenerate_pmf( x[ i % 100 ], mu[ i % 100 ] );
79-
if ( isnan( y ) ) { // Check for NaN
111+
if ( isnan( y ) ) {
80112
printf( "should not return NaN\n" );
81113
break;
82114
}
@@ -89,11 +121,14 @@ static double benchmark( void ) {
89121
return elapsed;
90122
}
91123

124+
/**
125+
* Main execution sequence.
126+
*/
92127
int main( void ) {
93128
double elapsed;
94129
int i;
95130

96-
// Seed the random number generator:
131+
// Use the current time to seed the random number generator:
97132
srand( time( NULL ) );
98133

99134
print_version();

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

Lines changed: 3 additions & 3 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/pmf.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 );
@@ -28,8 +28,8 @@ static double random_uniform( const double min, const double max ) {
2828

2929
int main( void ) {
3030
double result;
31-
double x;
3231
double mu;
32+
double x;
3333
int i;
3434

3535
for ( i = 0; i < 10; i++ ) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ var addon = require( './../src/addon.node' );
3434
* @returns {number} evaluated probability mass function
3535
*
3636
* @example
37-
* var y = pmf( 3.0, 3.0 );
38-
* // returns 1.0
39-
*
40-
* @example
4137
* var y = pmf( 2.0, 3.0 );
4238
* // returns 0.0
4339
*
4440
* @example
45-
* var y = pmf( NaN, 2.0 );
41+
* var y = pmf( 3.0, 3.0 );
42+
* // returns 1.0
43+
*
44+
* @example
45+
* var y = pmf( NaN, 0.0 );
4646
* // returns NaN
4747
*
4848
* @example
49-
* var y = pmf( 3.0, NaN );
49+
* var y = pmf( 0.0, NaN );
5050
* // returns NaN
5151
*/
5252
function pmf( x, mu ) {

lib/node_modules/@stdlib/stats/base/dists/degenerate/pmf/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"libraries": [],
5555
"libpath": [],
5656
"dependencies": [
57-
"@stdlib/math/base/assert/is-nan"
57+
"@stdlib/math/base/assert/is-nan",
58+
"@stdlib/math/base/special/ceil"
5859
]
5960
},
6061
{

lib/node_modules/@stdlib/stats/base/dists/degenerate/pmf/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/pmf.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_pmf )

0 commit comments

Comments
 (0)