Skip to content

Commit da1efe2

Browse files
Aadish JainAadish Jain
authored andcommitted
feat(negative-binomial-variance): changing r to be double instead of int64
1 parent c2e82dd commit da1efe2

File tree

13 files changed

+26
-140
lines changed

13 files changed

+26
-140
lines changed

lib/node_modules/@stdlib/math/base/napi/binary/include/stdlib/math/base/napi/binary.h

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -616,48 +616,6 @@
616616
}; \
617617
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_ll_d_init )
618618

619-
/**
620-
* Macro for registering a Node-API module exporting an interface invoking a binary function accepting signed 64-bit integers and a double-precision floating-point and returning a double-precision floating-point number.
621-
*
622-
* @param fcn binary function
623-
*
624-
* @example
625-
* #include <stdint.h>
626-
*
627-
* static double fcn( const int_64 x, const double y ) {
628-
* // ...
629-
* }
630-
*
631-
* // ...
632-
*
633-
* // Register a Node-API module:
634-
* STDLIB_MATH_BASE_NAPI_MODULE_LD_D( fcn );
635-
*/
636-
#define STDLIB_MATH_BASE_NAPI_MODULE_LD_D( fcn ) \
637-
static napi_value stdlib_math_base_napi_ld_d_wrapper( \
638-
napi_env env, \
639-
napi_callback_info info \
640-
) { \
641-
return stdlib_math_base_napi_ld_d( env, info, fcn ); \
642-
}; \
643-
static napi_value stdlib_math_base_napi_ld_d_init( \
644-
napi_env env, \
645-
napi_value exports \
646-
) { \
647-
napi_value fcn; \
648-
napi_status status = napi_create_function( \
649-
env, \
650-
"exports", \
651-
NAPI_AUTO_LENGTH, \
652-
stdlib_math_base_napi_ld_d_wrapper, \
653-
NULL, \
654-
&fcn \
655-
); \
656-
assert( status == napi_ok ); \
657-
return fcn; \
658-
}; \
659-
NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_ld_d_init )
660-
661619
/**
662620
* Macro for registering a Node-API module exporting an interface invoking a binary function accepting signed 32-bit integers and returning a single-precision floating-point number.
663621
*
@@ -772,11 +730,6 @@ napi_value stdlib_math_base_napi_cf_c( napi_env env, napi_callback_info info, st
772730
*/
773731
napi_value stdlib_math_base_napi_ll_d( napi_env env, napi_callback_info info, double (*fcn)( int64_t, int64_t ) );
774732

775-
/**
776-
* Invokes a binary function accepting a signed 64-bit integer and a double-precision floating-point number and returning a double-precision floating-point number.
777-
*/
778-
napi_value stdlib_math_base_napi_ld_d( napi_env env, napi_callback_info info, double (*fcn)( int64_t, double ) );
779-
780733
/**
781734
* Invokes a binary function accepting signed 32-bit integers and returning a single-precision floating-point number.
782735
*/

lib/node_modules/@stdlib/math/base/napi/binary/src/main.c

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -87,67 +87,6 @@ napi_value stdlib_math_base_napi_dd_d( napi_env env, napi_callback_info info, do
8787

8888
return v;
8989
}
90-
/**
91-
* Invokes a binary function accepting a signed 64-bit integer and a double-precision floating-point number and returning double-precision floating-point numbers.
92-
*
93-
* ## Notes
94-
*
95-
* - This function expects that the callback `info` argument provides access to the following JavaScript arguments:
96-
*
97-
* - `x`: input value.
98-
* - `y`: input value.
99-
*
100-
* @param env environment under which the function is invoked
101-
* @param info callback data
102-
* @param fcn binary function
103-
* @return function return value as a Node-API double-precision floating-point number
104-
*/
105-
napi_value stdlib_math_base_napi_ld_d( napi_env env, napi_callback_info info, double (*fcn)( int64_t, double ) ) {
106-
napi_status status;
107-
108-
size_t argc = 2;
109-
napi_value argv[ 2 ];
110-
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
111-
assert( status == napi_ok );
112-
113-
if ( argc < 2 ) {
114-
status = napi_throw_error( env, NULL, "invalid invocation. Must provide two numbers." );
115-
assert( status == napi_ok );
116-
return NULL;
117-
}
118-
119-
napi_valuetype vtype0;
120-
status = napi_typeof( env, argv[ 0 ], &vtype0 );
121-
assert( status == napi_ok );
122-
if ( vtype0 != napi_number ) {
123-
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." );
124-
assert( status == napi_ok );
125-
return NULL;
126-
}
127-
128-
napi_valuetype vtype1;
129-
status = napi_typeof( env, argv[ 1 ], &vtype1 );
130-
assert( status == napi_ok );
131-
if ( vtype1 != napi_number ) {
132-
status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
133-
assert( status == napi_ok );
134-
return NULL;
135-
}
136-
137-
int64_t x;
138-
status = napi_get_value_int64( env, argv[ 0 ], &x );
139-
assert( status == napi_ok );
140-
141-
double y;
142-
status = napi_get_value_double( env, argv[ 1 ], &y );
143-
assert( status == napi_ok );
144-
145-
napi_value v;
146-
status = napi_create_double( env, fcn( x, y ), &v );
147-
assert( status == napi_ok );
148-
149-
return v;
150-
}
15190

15291
/**
15392
* Invokes a binary function accepting and returning single-precision floating-point numbers.

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ double v = stdlib_base_dists_negative_binomial_variance( 100, 0.2 );
174174

175175
The function accepts the following arguments:
176176

177-
- **r**: `[in] int` number of successes until experiment is stopped.
177+
- **r**: `[in] double` number of successes until experiment is stopped.
178178
- **p**: `[in] double` success probability.
179179

180180
```c
181-
double stdlib_base_dists_negative_binomial_variance( const int64_t r, const double p );
181+
double stdlib_base_dists_negative_binomial_variance( const double r, const double p );
182182
```
183183
184184
</section>
@@ -202,7 +202,6 @@ double stdlib_base_dists_negative_binomial_variance( const int64_t r, const doub
202202
```c
203203
#include "stdlib/stats/base/dists/negative-binomial/variance.h"
204204
#include <stdlib.h>
205-
#include <stdint.h>
206205
#include <stdio.h>
207206
208207
static double random_uniform( const double min, const double max ) {
@@ -211,17 +210,17 @@ static double random_uniform( const double min, const double max ) {
211210
}
212211
213212
int main( void ) {
214-
int64_t r;
213+
double r;
215214
double p;
216215
double v;
217216
int i;
218217
219218
220219
for ( i = 0; i < 10; i++ ) {
221-
r = (int64_t)random_uniform( -1.0, 100.0 );
220+
r = random_uniform( -1.0, 100.0 );
222221
p = random_uniform( 0.0, 1.0 );
223222
v = stdlib_base_dists_negative_binomial_variance( r, p );
224-
printf( "r: %ld, p: %lf, Var(X;r,p): %lf\n", r, p, v );
223+
printf( "r: %lf, p: %lf, Var(X;r,p): %lf\n", r, p, v );
225224
}
226225
}
227226
```

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/benchmark/benchmark.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var bench = require( '@stdlib/bench' );
2424
var Float64Array = require( '@stdlib/array/float64' );
2525
var randu = require( '@stdlib/random/base/randu' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27-
var floor = require( '@stdlib/math/base/special/floor' );
2827
var pkg = require( './../package.json' ).name;
2928
var variance = require( './../lib' );
3029

@@ -42,7 +41,7 @@ bench(pkg, function benchmark(b) {
4241
r = new Float64Array(len);
4342
p = new Float64Array(len);
4443
for (i = 0; i < len; i++) {
45-
r[i] = floor((randu() * 10.0) + 1.0); // Treat r as int64_t
44+
r[i] = (randu() * 10.0) + 1.0; // Treat r as double
4645
p[i] = (randu() * 0.8) + 0.1;
4746
}
4847

@@ -67,7 +66,7 @@ bench(pkg + ':direct', function benchmark(b) {
6766
var y;
6867
var i;
6968

70-
r = 5;
69+
r = 5.0; // Treat r as double
7170
p = 0.5;
7271

7372
b.tic();

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/benchmark/benchmark.native.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ var Float64Array = require( '@stdlib/array/float64' );
2626
var randu = require( '@stdlib/random/base/randu' );
2727
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
29-
var floor = require( '@stdlib/math/base/special/floor' );
3029
var pkg = require( './../package.json' ).name;
3130

3231

@@ -51,7 +50,7 @@ bench(pkg + '::native', opts, function benchmark(b) {
5150
r = new Float64Array(len);
5251
p = new Float64Array(len);
5352
for (i = 0; i < len; i++) {
54-
r[i] = floor((randu() * 10.0) + 1.0);
53+
r[i] = (randu() * 10.0) + 1.0; // Treat r as double
5554
p[i] = (randu() * 0.8) + 0.1;
5655
}
5756

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/benchmark/c/benchmark.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <sys/time.h>
2020
#include "stdlib/stats/base/dists/negative-binomial/variance.h"
2121
#include <math.h>
22-
#include <stdint.h>
2322
#include <stdio.h>
2423
#include <stdlib.h>
2524
#include <time.h>
@@ -94,14 +93,14 @@ static double random_uniform( const double min, const double max ) {
9493
*/
9594
static double benchmark( void ) {
9695
double elapsed;
97-
int64_t r[ 100 ];
96+
double r[ 100 ];
9897
double p[ 100 ];
9998
double v;
10099
double t;
101100
int i;
102101

103102
for ( i = 0; i < 100; i++ ) {
104-
r[ i ] = (int64_t)random_uniform( 1.0, 10.0 );
103+
r[ i ] = random_uniform( 1.0, 10.0 );
105104
p[ i ] = random_uniform( 0.1, 0.9 );
106105
}
107106

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/examples/c/example.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "stdlib/stats/base/dists/negative-binomial/variance.h"
20-
#include <stdint.h>
2120
#include <stdio.h>
2221
#include <stdlib.h>
2322

@@ -27,15 +26,15 @@ static double random_uniform( const double min, const double max ) {
2726
}
2827

2928
int main( void ) {
30-
int64_t r;
29+
double r;
3130
double p;
3231
double v;
3332
int i;
3433

3534
for ( i = 0; i < 25; i++ ) {
36-
r = (int64_t)random_uniform( 1.0, 10.0 );
35+
r = random_uniform( 1.0, 10.0 );
3736
p = random_uniform( 0.1, 0.9 );
3837
v = stdlib_base_dists_negative_binomial_variance( r, p );
39-
printf( "r: %ld, p: %lf, Var(r,p): %lf\n", r, p, v );
38+
printf( "r: %lf, p: %lf, Var(r,p): %lf\n", r, p, v );
4039
}
4140
}

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/examples/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ for ( i = 0; i < 10; i++ ) {
3030
r = randu() * 100;
3131
p = randu();
3232
v = variance( r, p );
33-
console.log( 'r: %d, p: %d, Var(X;r,p): %d', r, p.toFixed( 4 ), v.toFixed( 4 ) );
33+
console.log( 'r: %lf, p: %lf, Var(X;r,p): %lf', r, p.toFixed( 4 ), v.toFixed( 4 ) );
3434
}

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/include/stdlib/stats/base/dists/negative-binomial/variance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern "C" {
3131
/**
3232
* Computes the variance for a negative binomial distribution with number of successes `r` and success probability `p`.
3333
*/
34-
double stdlib_base_dists_negative_binomial_variance( const int64_t r, const double p );
34+
double stdlib_base_dists_negative_binomial_variance( const double r, const double p );
3535

3636
#ifdef __cplusplus
3737
}

lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/lib/native.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,27 @@ var addon = require( './../src/addon.node' );
3434
* @returns {number} evaluated variance
3535
*
3636
* @example
37-
* var v = variance( 10, 0.5 );
37+
* var v = variance( 10.0, 0.5 );
3838
* // returns 20.0
3939
*
4040
* @example
41-
* var v = variance( 5, 0.2 );
41+
* var v = variance( 5.0, 0.2 );
4242
* // returns 100.0
4343
*
4444
* @example
4545
* var v = variance( NaN, 0.5 );
4646
* // returns NaN
4747
*
4848
* @example
49-
* var v = variance( 10, NaN );
49+
* var v = variance( 10.0, NaN );
5050
* // returns NaN
5151
*
5252
* @example
53-
* var v = variance( -1, 0.5 );
53+
* var v = variance( -1.0, 0.5 );
5454
* // returns NaN
5555
*
5656
* @example
57-
* var v = variance( 10, 1.5 );
57+
* var v = variance( 10.0, 1.5 );
5858
* // returns NaN
5959
*/
6060
function variance(r, p) {

0 commit comments

Comments
 (0)