Skip to content

Commit 6f9b439

Browse files
committed
chore: follow code conventions
--- 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: passed - 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: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - 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 ---
1 parent ce5ebfa commit 6f9b439

File tree

11 files changed

+256
-217
lines changed

11 files changed

+256
-217
lines changed

lib/node_modules/@stdlib/stats/base/dists/chi/stdev/README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ for ( i = 0; i < 10; i++ ) {
144144

145145
#### stdlib_base_dists_chi_stdev( k )
146146

147-
Returns the standard deviation of a chi distribution.
147+
Returns the [standard deviation][stdev] of a [chi][chi-distribution] distribution with degrees of freedom `k`.
148148

149149
```c
150150
double out = stdlib_base_dists_chi_stdev( 9.0 );
@@ -153,7 +153,7 @@ double out = stdlib_base_dists_chi_stdev( 9.0 );
153153

154154
The function accepts the following arguments:
155155

156-
- **k**: `[in] double` degrees of freedom (must be positive)
156+
- **k**: `[in] double` degrees of freedom
157157

158158
```c
159159
double stdlib_base_dists_chi_stdev( const double k );
@@ -179,27 +179,24 @@ double stdlib_base_dists_chi_stdev( const double k );
179179
180180
```c
181181
#include "stdlib/stats/base/dists/chi/stdev.h"
182-
#include <stdlib.h>
183182
#include <stdio.h>
183+
#include <stdlib.h>
184184
185185
static double random_uniform( const double min, const double max ) {
186186
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
187-
return min + ( v * ( max - min ) );
187+
return min + ( v * ( max-min ) );
188188
}
189189
190190
int main( void ) {
191191
double k;
192-
double result;
192+
double y;
193193
int i;
194194
195-
for ( i = 0; i < 10; i++ ) {
196-
k = random_uniform( 0.1, 10.0 ); // Ensure `k` is positive
197-
result = stdlib_base_dists_chi_stdev( k );
198-
199-
printf( "k: %lf, Standard Deviation: %lf \n", k, result );
195+
for ( i = 0; i < 25; i++ ) {
196+
k = random_uniform( 1.0, 10.0 );
197+
y = stdlib_base_dists_chi_stdev( k );
198+
printf( "k: %lf, SD(X;k): %lf\n", k, y );
200199
}
201-
202-
return 0;
203200
}
204201
```
205202

lib/node_modules/@stdlib/stats/base/dists/chi/stdev/benchmark/benchmark.native.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var Float64Array = require( '@stdlib/array/float64' );
26-
var randu = require( '@stdlib/random/base/randu' );
26+
var uniform = require( '@stdlib/random/base/uniform' );
2727
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var EPS = require( '@stdlib/constants/float64/eps' );
2829
var tryRequire = require( '@stdlib/utils/try-require' );
2930
var pkg = require( './../package.json' ).name;
3031

@@ -48,7 +49,7 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4849
len = 100;
4950
k = new Float64Array( len );
5051
for ( i = 0; i < len; i++ ) {
51-
k[ i ] = ( randu() * 10.0 ) + 0.1; // Ensure k > 0
52+
k[ i ] = uniform( EPS, 20.0 );
5253
}
5354

5455
b.tic();

lib/node_modules/@stdlib/stats/base/dists/chi/stdev/benchmark/c/benchmark.c

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

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

2626
#define NAME "chi-stdev"
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,57 +63,76 @@ 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 );
55-
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
74+
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 );
60-
return min + ( v * ( max - min ) );
86+
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;
6595
double k[ 100 ];
96+
double elapsed;
6697
double y;
67-
double start;
98+
double t;
6899
int i;
69100

70101
for ( i = 0; i < 100; i++ ) {
71-
k[ i ] = random_uniform( 0.1, 10.0 );
102+
k[ i ] = random_uniform( 1.0, 10.0 );
72103
}
73104

74-
start = tic();
105+
t = tic();
75106
for ( i = 0; i < ITERATIONS; i++ ) {
76107
y = stdlib_base_dists_chi_stdev( k[ i%100 ] );
77-
if ( isnan( y ) ) {
108+
if ( y != y ) {
78109
printf( "should not return NaN\n" );
79110
break;
80111
}
81112
}
82-
elapsed = tic() - start;
83-
84-
if ( isnan( y ) ) {
113+
elapsed = tic() - t;
114+
if ( y != y ) {
85115
printf( "should not return NaN\n" );
86116
}
87117
return elapsed;
88118
}
89119

120+
/**
121+
* Main execution sequence.
122+
*/
90123
int main( void ) {
91124
double elapsed;
92125
int i;
93126

94-
// Seed the random number generator:
127+
// Use the current time to seed the random number generator:
95128
srand( time( NULL ) );
96129

97130
print_version();
98131
for ( i = 0; i < REPEATS; i++ ) {
99132
printf( "# c::%s\n", NAME );
100133
elapsed = benchmark();
101134
print_results( elapsed );
102-
printf( "ok %d benchmark finished\n", i+1 );
135+
printf( "ok %d benchmark finished\n", i + 1 );
103136
}
104137
print_summary( REPEATS, REPEATS );
105138
}

0 commit comments

Comments
 (0)