Skip to content

Commit eaccd6c

Browse files
Krishna-Sharma-ganandkaranubcstdlib-botPlaneshifter
authored
fix: update C implementation for stats/base/dists/kumaraswamy/median
PR-URL: #5452 Closes: #5047 Co-authored-by: Karan Anand <[email protected]> Co-authored-by: stdlib-bot <[email protected]> Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]> Reviewed-by: Karan Anand <[email protected]> Signed-off-by: Gautam sharma <[email protected]>
1 parent d8cd158 commit eaccd6c

File tree

12 files changed

+108
-61
lines changed

12 files changed

+108
-61
lines changed

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ for ( i = 0; i < 10; i++ ) {
174174
Returns the [median][median] of a [Kumaraswamy's double bounded][kumaraswamy-distribution] distribution with first shape parameter `a` and second shape parameter `b`.
175175

176176
```c
177-
double out = stdlib_base_dists_kumaraswamy_median( 2.0, 3.0 );
178-
// returns ~1.817
177+
double out = stdlib_base_dists_kumaraswamy_median( 1.0, 1.0 );
178+
// returns 0.5
179179
```
180180

181181
The function accepts the following arguments:
@@ -212,7 +212,7 @@ double stdlib_base_dists_kumaraswamy_median( const double a, const double b );
212212
213213
static double random_uniform( const double min, const double max ) {
214214
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
215-
return min + ( v * (max - min) );
215+
return min + ( v*(max-min) );
216216
}
217217
218218
int main( void ) {
@@ -225,7 +225,7 @@ int main( void ) {
225225
a = random_uniform( 0.1, 10.0 );
226226
b = random_uniform( 0.1, 10.0 );
227227
y = stdlib_base_dists_kumaraswamy_median( a, b );
228-
printf( "a: %lf, b: %lf, Median(a, b): %lf\n", a, b, y );
228+
printf( "a: %lf, b: %lf, Median(X;a,b): %lf\n", a, b, y );
229229
}
230230
231231
return 0;

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/benchmark/benchmark.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var Float64Array = require( '@stdlib/array/float64' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2727
var EPS = require( '@stdlib/constants/float64/eps' );
2828
var pkg = require( './../package.json' ).name;
@@ -42,8 +42,8 @@ bench( pkg, function benchmark( b ) {
4242
alpha = new Float64Array( len );
4343
beta = new Float64Array( len );
4444
for ( i = 0; i < len; i++ ) {
45-
alpha[ i ] = ( randu() * 10.0 ) + EPS;
46-
beta[ i ] = ( randu() * 10.0 ) + EPS;
45+
alpha[ i ] = uniform( EPS, 10.0 );
46+
beta[ i ] = uniform( EPS, 10.0 );
4747
}
4848

4949
b.tic();

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/benchmark/benchmark.native.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
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 EPS = require( '@stdlib/constants/float64/eps' );
2828
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2929
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -51,8 +51,8 @@ bench( pkg+'::native', opts, function benchmark( b ) {
5151
alpha = new Float64Array( len );
5252
beta = new Float64Array( len );
5353
for ( i = 0; i < len; i++ ) {
54-
alpha[ i ] = ( randu() * 10.0 ) + EPS;
55-
beta[ i ] = ( randu() * 10.0 ) + EPS;
54+
alpha[ i ] = uniform( EPS, 10.0 );
55+
beta[ i ] = uniform( EPS, 10.0 );
5656
}
5757

5858
b.tic();

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/benchmark/c/benchmark.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ static double random_uniform( const double min, const double max ) {
9393
* @return elapsed time in seconds
9494
*/
9595
static double benchmark( void ) {
96-
double elapsed;
9796
double a[ 100 ];
9897
double b[ 100 ];
98+
double elapsed;
9999
double y;
100100
double t;
101101
int i;

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/examples/c/example.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int main( void ) {
3636
b = random_uniform( 0.1, 10.0 );
3737

3838
y = stdlib_base_dists_kumaraswamy_median( a, b );
39-
printf( "a: %lf, b: %lf, Median(a,b): %lf\n", a, b, y );
39+
printf( "a: %lf, b: %lf, Median(X;a,b): %lf\n", a, b, y );
4040
}
4141

4242
return 0;

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/include/stdlib/stats/base/dists/kumaraswamy/median.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C" {
2727
#endif
2828

2929
/**
30-
* Returns the median of a Kumaraswamy distribution.
30+
* Returns the median of a Kumaraswamy's double bounded distribution.
3131
*/
3232
double stdlib_base_dists_kumaraswamy_median( const double a, const double b );
3333

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/lib/native.js

+25-9
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,39 @@ var addon = require( './../src/addon.node' );
2626
// MAIN //
2727

2828
/**
29-
* Returns the median of a Kumaraswamy distribution.
29+
* Returns the median of a Kumaraswamy's double bounded distribution.
3030
*
3131
* @private
32-
* @param {number} a - shape parameter
33-
* @param {number} b - shape parameter
34-
* @returns {number} median
32+
* @param {PositiveNumber} a - first shape parameter
33+
* @param {PositiveNumber} b - second shape parameter
34+
* @returns {PositiveNumber} median
3535
*
3636
* @example
37-
* var v = median( 2.0, 3.0 );
38-
* // returns ~0.2062994740159002
37+
* var v = median( 0.5, 1.0 );
38+
* // returns 0.25
3939
*
4040
* @example
41-
* var v = median( 1.0, 5.0 );
42-
* // returns ~0.12944943670387588
41+
* var v = median( 4.0, 12.0 );
42+
* // returns ~0.487
4343
*
4444
* @example
45-
* var v = median( 2.0, -0.5 );
45+
* var v = median( 12.0, 2.0 );
46+
* // returns ~0.903
47+
*
48+
* @example
49+
* var v = median( 1.0, -0.1 );
50+
* // returns NaN
51+
*
52+
* @example
53+
* var v = median( -0.1, 1.0 );
54+
* // returns NaN
55+
*
56+
* @example
57+
* var v = median( 2.0, NaN );
58+
* // returns NaN
59+
*
60+
* @example
61+
* var v = median( NaN, 2.0 );
4662
* // returns NaN
4763
*/
4864
function median( a, b ) {

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/manifest.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"dependencies": [
4141
"@stdlib/math/base/napi/binary",
4242
"@stdlib/math/base/assert/is-nan",
43-
"@stdlib/math/base/special/pow",
44-
"@stdlib/constants/float64/eps"
43+
"@stdlib/math/base/special/pow"
4544
]
4645
},
4746
{
@@ -74,8 +73,7 @@
7473
"libpath": [],
7574
"dependencies": [
7675
"@stdlib/math/base/assert/is-nan",
77-
"@stdlib/math/base/special/pow",
78-
"@stdlib/constants/float64/eps"
76+
"@stdlib/math/base/special/pow"
7977
]
8078
}
8179
]

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/src/main.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
#include "stdlib/math/base/special/pow.h"
2222

2323
/**
24-
* Returns the median of a Kumaraswamy distribution.
24+
* Returns the median of a Kumaraswamy's double bounded distribution.
2525
*
2626
* @param a first shape parameter
2727
* @param b second shape parameter
2828
* @return median
2929
*
3030
* @example
31-
* double y = stdlib_base_dists_kumaraswamy_median( 2.0, 3.0 );
32-
* // returns 1.0
31+
* double y = stdlib_base_dists_kumaraswamy_median( 0.5, 1.0 );
32+
* // returns 0.25
3333
*/
3434
double stdlib_base_dists_kumaraswamy_median( const double a, const double b ) {
3535
if (
@@ -39,5 +39,5 @@ double stdlib_base_dists_kumaraswamy_median( const double a, const double b ) {
3939
) {
4040
return 0.0/0.0; // NaN
4141
}
42-
return 1.0 - stdlib_base_pow( 0.5, 1.0 / b );
42+
return stdlib_base_pow( 1.0 - stdlib_base_pow( 2.0, -1.0/b ), 1.0/a );
4343
}

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/test/fixtures/julia/runner.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Generate fixture data and write to file.
2626
2727
# Arguments
2828
29-
* `a`: shape parameter a (must be positive)
30-
* `b`: shape parameter b (must be positive)
29+
* `a`: first shape parameter
30+
* `b`: second shape parameter
3131
* `name::AbstractString`: output filename
3232
3333
# Examples

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/test/test.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ tape( 'main export is a function', function test( t ) {
4444

4545
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
4646
var v = median( NaN, 0.5 );
47-
t.equal( isnan( v ), true, 'returns NaN' );
47+
t.equal( isnan( v ), true, 'returns expected value' );
4848

4949
v = median( 10.0, NaN );
50-
t.equal( isnan( v ), true, 'returns NaN' );
50+
t.equal( isnan( v ), true, 'returns expected value' );
5151

5252
t.end();
5353
});
@@ -56,25 +56,25 @@ tape( 'if provided a nonpositive `a`, the function returns `NaN`', function test
5656
var y;
5757

5858
y = median( 0.0, 2.0 );
59-
t.equal( isnan( y ), true, 'returns NaN' );
59+
t.equal( isnan( y ), true, 'returns expected value' );
6060

6161
y = median( -1.0, 2.0 );
62-
t.equal( isnan( y ), true, 'returns NaN' );
62+
t.equal( isnan( y ), true, 'returns expected value' );
6363

6464
y = median( -1.0, 2.0 );
65-
t.equal( isnan( y ), true, 'returns NaN' );
65+
t.equal( isnan( y ), true, 'returns expected value' );
6666

6767
y = median( NINF, 1.0 );
68-
t.equal( isnan( y ), true, 'returns NaN' );
68+
t.equal( isnan( y ), true, 'returns expected value' );
6969

7070
y = median( NINF, PINF );
71-
t.equal( isnan( y ), true, 'returns NaN' );
71+
t.equal( isnan( y ), true, 'returns expected value' );
7272

7373
y = median( NINF, NINF );
74-
t.equal( isnan( y ), true, 'returns NaN' );
74+
t.equal( isnan( y ), true, 'returns expected value' );
7575

7676
y = median( NINF, NaN );
77-
t.equal( isnan( y ), true, 'returns NaN' );
77+
t.equal( isnan( y ), true, 'returns expected value' );
7878

7979
t.end();
8080
});
@@ -83,25 +83,25 @@ tape( 'if provided a nonpositive `b`, the function returns `NaN`', function test
8383
var y;
8484

8585
y = median( 2.0, 0.0 );
86-
t.equal( isnan( y ), true, 'returns NaN' );
86+
t.equal( isnan( y ), true, 'returns expected value' );
8787

8888
y = median( 2.0, -1.0 );
89-
t.equal( isnan( y ), true, 'returns NaN' );
89+
t.equal( isnan( y ), true, 'returns expected value' );
9090

9191
y = median( 2.0, -1/0 );
92-
t.equal( isnan( y ), true, 'returns NaN' );
92+
t.equal( isnan( y ), true, 'returns expected value' );
9393

9494
y = median( 1.0, NINF );
95-
t.equal( isnan( y ), true, 'returns NaN' );
95+
t.equal( isnan( y ), true, 'returns expected value' );
9696

9797
y = median( PINF, NINF );
98-
t.equal( isnan( y ), true, 'returns NaN' );
98+
t.equal( isnan( y ), true, 'returns expected value' );
9999

100100
y = median( NINF, NINF );
101-
t.equal( isnan( y ), true, 'returns NaN' );
101+
t.equal( isnan( y ), true, 'returns expected value' );
102102

103103
y = median( NaN, NINF );
104-
t.equal( isnan( y ), true, 'returns NaN' );
104+
t.equal( isnan( y ), true, 'returns expected value' );
105105

106106
t.end();
107107
});

Diff for: lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/median/test/test.native.js

+46-13
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,64 @@ tape( 'main export is a function', opts, function test( t ) {
5353

5454
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) {
5555
var v = median( NaN, 0.5 );
56-
t.equal( isnan( v ), true, 'returns NaN' );
56+
t.equal( isnan( v ), true, 'returns expected value' );
5757

58-
v = median( 10, NaN );
59-
t.equal( isnan( v ), true, 'returns NaN' );
58+
v = median( 10.0, NaN );
59+
t.equal( isnan( v ), true, 'returns expected value' );
6060

61-
v = median( NaN, NaN );
62-
t.equal( isnan( v ), true, 'returns NaN' );
61+
t.end();
62+
});
63+
64+
tape( 'if provided a nonpositive `a`, the function returns `NaN`', opts, function test( t ) {
65+
var y;
66+
67+
y = median( 0.0, 2.0 );
68+
t.equal( isnan( y ), true, 'returns expected value' );
69+
70+
y = median( -1.0, 2.0 );
71+
t.equal( isnan( y ), true, 'returns expected value' );
72+
73+
y = median( -1.0, 2.0 );
74+
t.equal( isnan( y ), true, 'returns expected value' );
75+
76+
y = median( NINF, 1.0 );
77+
t.equal( isnan( y ), true, 'returns expected value' );
78+
79+
y = median( NINF, PINF );
80+
t.equal( isnan( y ), true, 'returns expected value' );
81+
82+
y = median( NINF, NINF );
83+
t.equal( isnan( y ), true, 'returns expected value' );
84+
85+
y = median( NINF, NaN );
86+
t.equal( isnan( y ), true, 'returns expected value' );
6387

6488
t.end();
6589
});
6690

67-
tape( 'if provided a nonpositive `gamma`, the function always returns `NaN`', opts, function test( t ) {
91+
tape( 'if provided a nonpositive `b`, the function returns `NaN`', opts, function test( t ) {
6892
var y;
6993

70-
y = median( 0.0, 0.0 );
71-
t.equal( isnan( y ), true, 'returns NaN' );
94+
y = median( 2.0, 0.0 );
95+
t.equal( isnan( y ), true, 'returns expected value' );
7296

73-
y = median( 0.0, -1.0 );
74-
t.equal( isnan( y ), true, 'returns NaN' );
97+
y = median( 2.0, -1.0 );
98+
t.equal( isnan( y ), true, 'returns expected value' );
7599

76-
y = median( 0.0, NINF );
77-
t.equal( isnan( y ), true, 'returns NaN' );
100+
y = median( 2.0, -1/0 );
101+
t.equal( isnan( y ), true, 'returns expected value' );
102+
103+
y = median( 1.0, NINF );
104+
t.equal( isnan( y ), true, 'returns expected value' );
78105

79106
y = median( PINF, NINF );
80-
t.equal( isnan( y ), true, 'returns NaN' );
107+
t.equal( isnan( y ), true, 'returns expected value' );
108+
109+
y = median( NINF, NINF );
110+
t.equal( isnan( y ), true, 'returns expected value' );
111+
112+
y = median( NaN, NINF );
113+
t.equal( isnan( y ), true, 'returns expected value' );
81114

82115
t.end();
83116
});

0 commit comments

Comments
 (0)