Skip to content

Commit 618141f

Browse files
committed
refactor: apply suggestions from previous PRs
--- 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: na - 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 9791340 commit 618141f

File tree

8 files changed

+322
-313
lines changed

8 files changed

+322
-313
lines changed

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/variance/README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ for ( i = 0; i < 10; i++ ) {
175175

176176
#### stdlib_base_dists_hypergeometric_variance( N, K, n )
177177

178-
Returns the variance of a hypergeometric distribution.
178+
Returns the [variance][variance] of a [hypergeometric][hypergeometric-distribution] distribution with parameters `N` (population size), `K` (subpopulation size), and `n` (number of draws).
179179

180180
```c
181181
double out = stdlib_base_dists_hypergeometric_variance( 16, 11, 4 );
@@ -211,12 +211,14 @@ double stdlib_base_dists_hypergeometric_variance( const double N, const double K
211211
### Examples
212212
213213
```c
214+
#include "stdlib/math/base/special/round.h"
214215
#include "stdlib/stats/base/dists/hypergeometric/variance.h"
215-
#include <stdlib.h>
216216
#include <stdio.h>
217+
#include <stdlib.h>
217218
218-
static int random_integer( const int min, const int max ) {
219-
return min + rand() % ( max - min + 1 );
219+
static double random_uniform( const double min, const double max ) {
220+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
221+
return min + ( v * ( max - min ) );
220222
}
221223
222224
int main( void ) {
@@ -227,15 +229,12 @@ int main( void ) {
227229
int i;
228230
229231
for ( i = 0; i < 10; i++ ) {
230-
N = random_integer( 10, 100 );
231-
K = random_integer( 1, N );
232-
n = random_integer( 1, N );
232+
N = stdlib_base_round( random_uniform( 0.0, 20.0 ) );
233+
K = stdlib_base_round( random_uniform( 0.0, N ) );
234+
n = stdlib_base_round( random_uniform( 0.0, K ) );
233235
v = stdlib_base_dists_hypergeometric_variance( N, K, n );
234-
235-
printf( "N: %lf, K: %lf, n: %lf, Variance: %lf\n", N, K, n, v );
236+
printf( "N: %lf, K: %lf, n: %lf, Var(X;N,K,n): %lf\n", N, K, n, v );
236237
}
237-
238-
return 0;
239238
}
240239
```
241240

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
/**
2-
* @license Apache-2.0
3-
*
4-
* Copyright (c) 2025 The Stdlib Authors.
5-
*
6-
* Licensed under the Apache License, Version 2.0 (the "License");
7-
* you may not use this file except in compliance with the License.
8-
* You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing, software
13-
* distributed under the License is distributed on an "AS IS" BASIS,
14-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
* See the License for the specific language governing permissions and
16-
* limitations under the License.
17-
*/
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
1818

1919
#include "stdlib/stats/base/dists/hypergeometric/variance.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

@@ -28,114 +28,114 @@
2828
#define REPEATS 3
2929

3030
/**
31-
* Prints the TAP version.
32-
*/
31+
* Prints the TAP version.
32+
*/
3333
static void print_version( void ) {
34-
printf( "TAP version 13\n" );
34+
printf( "TAP version 13\n" );
3535
}
3636

3737
/**
38-
* Prints the TAP summary.
39-
*
40-
* @param total total number of tests
41-
* @param passing total number of passing tests
42-
*/
38+
* Prints the TAP summary.
39+
*
40+
* @param total total number of tests
41+
* @param passing total number of passing tests
42+
*/
4343
static void print_summary( int total, int passing ) {
44-
printf( "#\n" );
45-
printf( "1..%d\n", total ); // TAP plan
46-
printf( "# total %d\n", total );
47-
printf( "# pass %d\n", passing );
48-
printf( "#\n" );
49-
printf( "# ok\n" );
44+
printf( "#\n" );
45+
printf( "1..%d\n", total ); // TAP plan
46+
printf( "# total %d\n", total );
47+
printf( "# pass %d\n", passing );
48+
printf( "#\n" );
49+
printf( "# ok\n" );
5050
}
5151

5252
/**
53-
* Prints benchmarks results.
54-
*
55-
* @param elapsed elapsed time in seconds
56-
*/
53+
* Prints benchmarks results.
54+
*
55+
* @param elapsed elapsed time in seconds
56+
*/
5757
static void print_results( double elapsed ) {
58-
double rate = (double)ITERATIONS / elapsed;
59-
printf( " ---\n" );
60-
printf( " iterations: %d\n", ITERATIONS );
61-
printf( " elapsed: %0.9f\n", elapsed );
62-
printf( " rate: %0.9f\n", rate );
63-
printf( " ...\n" );
58+
double rate = (double)ITERATIONS / elapsed;
59+
printf( " ---\n" );
60+
printf( " iterations: %d\n", ITERATIONS );
61+
printf( " elapsed: %0.9f\n", elapsed );
62+
printf( " rate: %0.9f\n", rate );
63+
printf( " ...\n" );
6464
}
6565

6666
/**
67-
* Returns a clock time.
68-
*
69-
* @return clock time
70-
*/
67+
* Returns a clock time.
68+
*
69+
* @return clock time
70+
*/
7171
static double tic( void ) {
72-
struct timeval now;
73-
gettimeofday( &now, NULL );
74-
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
72+
struct timeval now;
73+
gettimeofday( &now, NULL );
74+
return (double)now.tv_sec + (double)now.tv_usec / 1.0e6;
7575
}
7676

7777
/**
78-
* Generates a random integer on the interval [min,max].
79-
*
80-
* @param min minimum value (inclusive)
81-
* @param max maximum value (inclusive)
82-
* @return random integer
83-
*/
78+
* Generates a random integer on the interval [min,max].
79+
*
80+
* @param min minimum value (inclusive)
81+
* @param max maximum value (inclusive)
82+
* @return random integer
83+
*/
8484
static int random_integer( const int min, const int max ) {
85-
return min + rand() % ( max - min + 1 );
85+
return min + rand() % ( max - min + 1 );
8686
}
8787

8888
/**
89-
* Runs a benchmark.
90-
*
91-
* @return elapsed time in seconds
92-
*/
89+
* Runs a benchmark.
90+
*
91+
* @return elapsed time in seconds
92+
*/
9393
static double benchmark( void ) {
94-
double elapsed;
95-
double N[ 100 ];
96-
double K[ 100 ];
97-
double n[ 100 ];
98-
double v;
99-
double t;
100-
int i;
94+
double elapsed;
95+
double N[ 100 ];
96+
double K[ 100 ];
97+
double n[ 100 ];
98+
double v;
99+
double t;
100+
int i;
101101

102-
for ( i = 0; i < 100; i++ ) {
103-
N[ i ] = (double)random_integer( 10, 100 );
104-
K[ i ] = (double)random_integer( 1, (int)N[ i ] );
105-
n[ i ] = (double)random_integer( 1, (int)N[ i ] );
106-
}
102+
for ( i = 0; i < 100; i++ ) {
103+
N[ i ] = (double)random_integer( 10, 100 );
104+
K[ i ] = (double)random_integer( 1, (int)N[ i ] );
105+
n[ i ] = (double)random_integer( 1, (int)N[ i ] );
106+
}
107107

108-
t = tic();
109-
for ( i = 0; i < ITERATIONS; i++ ) {
110-
v = stdlib_base_dists_hypergeometric_variance( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] );
111-
if ( v != v ) {
112-
printf( "should not return NaN\n" );
113-
break;
114-
}
115-
}
116-
elapsed = tic() - t;
117-
if ( v != v ) {
118-
printf( "should not return NaN\n" );
119-
}
120-
return elapsed;
108+
t = tic();
109+
for ( i = 0; i < ITERATIONS; i++ ) {
110+
v = stdlib_base_dists_hypergeometric_variance( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] );
111+
if ( v != v ) {
112+
printf( "should not return NaN\n" );
113+
break;
114+
}
115+
}
116+
elapsed = tic() - t;
117+
if ( v != v ) {
118+
printf( "should not return NaN\n" );
119+
}
120+
return elapsed;
121121
}
122122

123123
/**
124-
* Main execution sequence.
125-
*/
124+
* Main execution sequence.
125+
*/
126126
int main( void ) {
127-
double elapsed;
128-
int i;
127+
double elapsed;
128+
int i;
129129

130-
// Use the current time to seed the random number generator:
131-
srand( time( NULL ) );
130+
// Use the current time to seed the random number generator:
131+
srand( time( NULL ) );
132132

133-
print_version();
134-
for ( i = 0; i < REPEATS; i++ ) {
135-
printf( "# c::%s\n", NAME );
136-
elapsed = benchmark();
137-
print_results( elapsed );
138-
printf( "ok %d benchmark finished\n", i+1 );
139-
}
140-
print_summary( REPEATS, REPEATS );
133+
print_version();
134+
for ( i = 0; i < REPEATS; i++ ) {
135+
printf( "# c::%s\n", NAME );
136+
elapsed = benchmark();
137+
print_results( elapsed );
138+
printf( "ok %d benchmark finished\n", i + 1 );
139+
}
140+
print_summary( REPEATS, REPEATS );
141141
}

0 commit comments

Comments
 (0)