Skip to content

Commit 119efae

Browse files
committed
fix: correct implementation
--- 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: na - 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: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - 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: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent d8d17b5 commit 119efae

File tree

11 files changed

+93
-143
lines changed

11 files changed

+93
-143
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,12 @@ double out = stdlib_base_dists_hypergeometric_skewness( 16, 11, 4 );
184184

185185
The function accepts the following arguments:
186186

187-
- **N**: `[in] double` population size.
188-
- **K**: `[in] double` subpopulation size.
189-
- **n**: `[in] double` number of draws.
187+
- **N**: `[in] int32_t` population size.
188+
- **K**: `[in] int32_t` subpopulation size.
189+
- **n**: `[in] int32_t` number of draws.
190190

191191
```c
192-
double stdlib_base_dists_hypergeometric_skewness ( const double N, const double K, const double n );
192+
double stdlib_base_dists_hypergeometric_skewness ( const int32_t N, const int32_t K, const int32_t n );
193193
```
194194
195195
</section>
@@ -211,29 +211,30 @@ double stdlib_base_dists_hypergeometric_skewness ( const double N, const double
211211
### Examples
212212
213213
```c
214-
#include "stdlib/math/base/special/round.h"
215214
#include "stdlib/stats/base/dists/hypergeometric/skewness.h"
216-
#include <stdio.h>
215+
#include "stdlib/math/base/special/ceil.h"
217216
#include <stdlib.h>
217+
#include <stdint.h>
218+
#include <stdio.h>
218219
219220
static double random_uniform( const double min, const double max ) {
220221
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
221222
return min + ( v * ( max - min ) );
222223
}
223224
224225
int main( void ) {
225-
double skew;
226-
double N;
227-
double K;
228-
double n;
226+
int32_t N;
227+
int32_t K;
228+
int32_t n;
229+
double y;
229230
int i;
230231
231232
for ( i = 0; i < 10; i++ ) {
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 ) );
235-
skew = stdlib_base_dists_hypergeometric_skewness( N, K, n );
236-
printf( "N: %lf, K: %lf, n: %lf, skew(X;N,K,n): %lf\n", N, K, n, skew );
233+
N = stdlib_base_ceil( random_uniform( 10.0, 100.0 ) );
234+
K = stdlib_base_ceil( random_uniform( 0.0, N - 1 ) );
235+
n = stdlib_base_ceil( random_uniform( 0.0, N - 1 ) );
236+
y = stdlib_base_dists_hypergeometric_skewness( N, K, n );
237+
printf( "N: %d, K: %d, n: %d, skew(X;N,K,n): %lf\n", N, K, n, y );
237238
}
238239
}
239240
```

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var uniform = require( '@stdlib/random/base/uniform' );
25-
var randu = require( '@stdlib/random/base/randu' );
26-
var ceil = require( '@stdlib/math/base/special/ceil' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
2726
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2827
var pkg = require( './../package.json' ).name;
2928
var skewness = require( './../lib' );
@@ -32,18 +31,26 @@ var skewness = require( './../lib' );
3231
// MAIN //
3332

3433
bench( pkg, function benchmark( b ) {
34+
var len;
3535
var N;
3636
var K;
3737
var n;
3838
var y;
3939
var i;
4040

41+
len = 100;
42+
N = new Float64Array( len );
43+
K = new Float64Array( len );
44+
n = new Float64Array( len );
45+
for ( i = 0; i < len; i++ ) {
46+
N[ i ] = discreteUniform( 10, 100 );
47+
K[ i ] = discreteUniform( 1, N[ i ] - 1 );
48+
n[ i ] = discreteUniform( 1, N[ i ] - 1 );
49+
}
50+
4151
b.tic();
4252
for ( i = 0; i < b.iterations; i++ ) {
43-
N = ceil( uniform( 10.0, 100.0 ) );
44-
K = ceil( randu()*(N-1) );
45-
n = ceil( randu()*(N-1) );
46-
y = skewness( N, K, n );
53+
y = skewness( N[ i % len ], K[ i % len ], n[ i % len ] );
4754
if ( isnan( y ) ) {
4855
b.fail( 'should not return NaN' );
4956
}

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/benchmark.native.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var Float64Array = require( '@stdlib/array/float64' );
26-
var uniform = require( '@stdlib/random/base/uniform' );
27-
var randu = require( '@stdlib/random/base/randu' );
26+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
2827
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2928
var tryRequire = require( '@stdlib/utils/try-require' );
30-
var round = require( '@stdlib/math/base/special/round' );
3129
var pkg = require( './../package.json' ).name;
3230

3331

@@ -54,9 +52,9 @@ bench( pkg+'::native', opts, function benchmark( b ) {
5452
K = new Float64Array( len );
5553
n = new Float64Array( len );
5654
for ( i = 0; i < len; i++ ) {
57-
N[ i ] = round( uniform( 10.0, 100.0 ) );
58-
K[ i ] = round( randu() * N[ i ] );
59-
n[ i ] = round( randu() * N[ i ] );
55+
N[ i ] = discreteUniform( 10, 100 );
56+
K[ i ] = discreteUniform( 1, N[ i ] - 1 );
57+
n[ i ] = discreteUniform( 1, N[ i ] - 1 );
6058
}
6159

6260
b.tic();

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/benchmark/c/benchmark.c

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

19-
#include "stdlib/math/base/special/round.h"
2019
#include "stdlib/stats/base/dists/hypergeometric/skewness.h"
21-
#include <math.h>
22-
#include <stdio.h>
20+
#include "stdlib/math/base/special/ceil.h"
2321
#include <stdlib.h>
22+
#include <stdint.h>
23+
#include <stdio.h>
2424
#include <time.h>
2525
#include <sys/time.h>
2626

@@ -94,29 +94,29 @@ static double random_uniform( const double min, const double max ) {
9494
*/
9595
static double benchmark( void ) {
9696
double elapsed;
97-
double N[ 100 ];
98-
double K[ 100 ];
99-
double n[ 100 ];
100-
double skew;
97+
int32_t N[ 100 ];
98+
int32_t K[ 100 ];
99+
int32_t n[ 100 ];
100+
double y;
101101
double t;
102102
int i;
103103

104104
for ( i = 0; i < 100; i++ ) {
105-
N[ i ] = stdlib_base_round( random_uniform( 1.0, 100.0 ) );
106-
K[ i ] = stdlib_base_round( random_uniform( 0.0, N[ i ] ) );
107-
n[ i ] = stdlib_base_round( random_uniform( 0.0, N[ i ] ) );
105+
N[ i ] = stdlib_base_ceil( random_uniform( 10.0, 100.0 ) );
106+
K[ i ] = stdlib_base_ceil( random_uniform( 0.0, N[ i ] - 1 ) );
107+
n[ i ] = stdlib_base_ceil( random_uniform( 0.0, N[ i ] - 1 ) );
108108
}
109109

110110
t = tic();
111111
for ( i = 0; i < ITERATIONS; i++ ) {
112-
skew = stdlib_base_dists_hypergeometric_skewness( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] );
113-
if ( skew != skew ) { // Check for NaN
112+
y = stdlib_base_dists_hypergeometric_skewness( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] );
113+
if ( y != y ) {
114114
printf( "should not return NaN\n" );
115115
break;
116116
}
117117
}
118118
elapsed = tic() - t;
119-
if ( skew != skew ) {
119+
if ( y != y ) {
120120
printf( "should not return NaN\n" );
121121
}
122122
return elapsed;

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/examples/c/example.c

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

19-
#include "stdlib/math/base/special/round.h"
2019
#include "stdlib/stats/base/dists/hypergeometric/skewness.h"
21-
#include <stdio.h>
20+
#include "stdlib/math/base/special/ceil.h"
2221
#include <stdlib.h>
22+
#include <stdint.h>
23+
#include <stdio.h>
2324

2425
static double random_uniform( const double min, const double max ) {
2526
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
2627
return min + ( v * ( max - min ) );
2728
}
2829

2930
int main( void ) {
30-
double skew;
31-
double N;
32-
double K;
33-
double n;
31+
int32_t N;
32+
int32_t K;
33+
int32_t n;
34+
double y;
3435
int i;
3536

3637
for ( i = 0; i < 10; i++ ) {
37-
N = stdlib_base_round( random_uniform( 0.0, 20.0 ) );
38-
K = stdlib_base_round( random_uniform( 0.0, N ) );
39-
n = stdlib_base_round( random_uniform( 0.0, K ) );
40-
skew = stdlib_base_dists_hypergeometric_skewness( N, K, n );
41-
printf( "N: %lf, K: %lf, n: %lf, skew(X;N,K,n): %lf\n", N, K, n, skew );
38+
N = stdlib_base_ceil( random_uniform( 10.0, 100.0 ) );
39+
K = stdlib_base_ceil( random_uniform( 0.0, N - 1 ) );
40+
n = stdlib_base_ceil( random_uniform( 0.0, N - 1 ) );
41+
y = stdlib_base_dists_hypergeometric_skewness( N, K, n );
42+
printf( "N: %d, K: %d, n: %d, skew(X;N,K,n): %lf\n", N, K, n, y );
4243
}
4344
}

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/include/stdlib/stats/base/dists/hypergeometric/skewness.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#ifndef STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_SKEWNESS_H
2020
#define STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_SKEWNESS_H
2121

22+
#include <stdint.h>
23+
2224
/*
2325
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
2426
*/
@@ -27,14 +29,9 @@ extern "C" {
2729
#endif
2830

2931
/**
30-
* Returns the skewness of a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`.
31-
*
32-
* @param N population size
33-
* @param K subpopulation size
34-
* @param n number of draws
35-
* @return skewness of the distribution
32+
* Returns the skewness of a hypergeometric distribution.
3633
*/
37-
double stdlib_base_dists_hypergeometric_skewness( const double N, const double K, const double n );
34+
double stdlib_base_dists_hypergeometric_skewness( const int32_t N, const int32_t K, const int32_t n );
3835

3936
#ifdef __cplusplus
4037
}

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/lib/native.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,32 @@ var addon = require( './../src/addon.node' );
2626
// MAIN //
2727

2828
/**
29-
* Returns the skewness of a hypergeometric distribution with population size `N`, subpopulation size `K`, and number of draws `n`.
29+
* Returns the skewness of a hypergeometric distribution.
3030
*
3131
* @private
32-
* @param {number} N - population size
33-
* @param {number} K - subpopulation size
34-
* @param {number} n - number of draws
32+
* @param {NonNegativeInteger} N - population size
33+
* @param {NonNegativeInteger} K - subpopulation size
34+
* @param {NonNegativeInteger} n - number of draws
3535
* @returns {number} skewness
3636
*
3737
* @example
38-
* var skew = skewness( 16, 11, 4 );
38+
* var v = skewness( 16, 11, 4 );
3939
* // returns ~-0.258
4040
*
4141
* @example
42-
* var skew = skewness( 4, 2, 2 );
42+
* var v = skewness( 4, 2, 2 );
4343
* // returns 0.0
4444
*
4545
* @example
46-
* var skew = skewness( 10, 5, 12 );
46+
* var v = skewness( 10, 5, 12 );
4747
* // returns NaN
4848
*
4949
* @example
50-
* var skew = skewness( 10.3, 10, 4 );
50+
* var v = skewness( 20, -2, 10 );
5151
* // returns NaN
5252
*
5353
* @example
54-
* var skew = skewness( 10, 5.5, 4 );
55-
* // returns NaN
56-
*
57-
* @example
58-
* var skew = skewness( 10, 5, 4.5 );
59-
* // returns NaN
60-
*
61-
* @example
62-
* var skew = skewness( NaN, 10, 4 );
63-
* // returns NaN
64-
*
65-
* @example
66-
* var skew = skewness( 20, NaN, 4 );
67-
* // returns NaN
68-
*
69-
* @example
70-
* var skew = skewness( 20, 10, NaN );
54+
* var v = skewness( -2, 4, 2 );
7155
* // returns NaN
7256
*/
7357
function skewness( N, K, n ) {

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/manifest.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"libpath": [],
4040
"dependencies": [
4141
"@stdlib/math/base/napi/ternary",
42-
"@stdlib/math/base/assert/is-nonnegative-integer",
4342
"@stdlib/constants/float64/pinf",
4443
"@stdlib/math/base/special/sqrt"
4544
]
@@ -56,10 +55,9 @@
5655
"libraries": [],
5756
"libpath": [],
5857
"dependencies": [
59-
"@stdlib/math/base/assert/is-nonnegative-integer",
6058
"@stdlib/constants/float64/pinf",
6159
"@stdlib/math/base/special/sqrt",
62-
"@stdlib/math/base/special/round"
60+
"@stdlib/math/base/special/ceil"
6361
]
6462
},
6563
{
@@ -74,10 +72,9 @@
7472
"libraries": [],
7573
"libpath": [],
7674
"dependencies": [
77-
"@stdlib/math/base/assert/is-nonnegative-integer",
78-
"@stdlib/math/base/special/round",
75+
"@stdlib/math/base/special/sqrt",
7976
"@stdlib/constants/float64/pinf",
80-
"@stdlib/math/base/special/sqrt"
77+
"@stdlib/math/base/special/ceil"
8178
]
8279
}
8380
]

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/addon.c

Lines changed: 2 additions & 2 deletions
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/ternary.h"
2019
#include "stdlib/stats/base/dists/hypergeometric/skewness.h"
20+
#include "stdlib/math/base/napi/ternary.h"
2121

2222
// cppcheck-suppress shadowFunction
23-
STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_hypergeometric_skewness )
23+
STDLIB_MATH_BASE_NAPI_MODULE_III_D( stdlib_base_dists_hypergeometric_skewness )

lib/node_modules/@stdlib/stats/base/dists/hypergeometric/skewness/src/main.c

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

19-
#include "stdlib/constants/float64/pinf.h"
20-
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
21-
#include "stdlib/math/base/special/sqrt.h"
2219
#include "stdlib/stats/base/dists/hypergeometric/skewness.h"
20+
#include "stdlib/math/base/special/sqrt.h"
21+
#include "stdlib/constants/float64/pinf.h"
2322

2423
/**
2524
* Returns the skewness of a hypergeometric distribution.
@@ -33,13 +32,20 @@
3332
* double skew = stdlib_base_dists_hypergeometric_skewness( 16, 11, 4 );
3433
* // returns ~-0.258
3534
*/
36-
double stdlib_base_dists_hypergeometric_skewness( const double N, const double K, const double n ) {
37-
if ( !stdlib_base_is_nonnegative_integer( N ) || !stdlib_base_is_nonnegative_integer( K ) || !stdlib_base_is_nonnegative_integer( n ) || N == STDLIB_CONSTANT_FLOAT64_PINF || K == STDLIB_CONSTANT_FLOAT64_PINF || K > N || n > N ) {
38-
return NAN;
39-
}
40-
41-
double p = ( N - ( 2 * K ) ) * stdlib_base_sqrt( N - 1 ) * ( N - ( 2 * n ) );
42-
double q = stdlib_base_sqrt( n * K * ( N - K ) * ( N - n ) ) * ( N - 2 );
35+
double stdlib_base_dists_hypergeometric_skewness( const int32_t N, const int32_t K, const int32_t n ) {
36+
double N_d;
37+
double K_d;
38+
double n_d;
39+
double p;
40+
double q;
4341

42+
if ( N < 0 || K < 0 || n < 0 || N == STDLIB_CONSTANT_FLOAT64_PINF || K == STDLIB_CONSTANT_FLOAT64_PINF || K > N || n > N ) {
43+
return 0.0/0.0; // NaN
44+
}
45+
N_d = (double)N;
46+
K_d = (double)K;
47+
n_d = (double)n;
48+
p = ( N_d - ( 2.0 * K_d ) ) * stdlib_base_sqrt( N_d - 1.0 ) * ( N_d - ( 2.0 * n_d ) );
49+
q = stdlib_base_sqrt( n_d * K_d * ( N_d - K_d ) * ( N_d - n_d ) ) * ( N_d - 2.0 );
4450
return p / q;
4551
}

0 commit comments

Comments
 (0)