Skip to content

Commit b2830ef

Browse files
feat: added new implementation and other minor updates
1 parent ae7d13b commit b2830ef

File tree

16 files changed

+109
-90
lines changed

16 files changed

+109
-90
lines changed

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,20 @@ for ( i = 0; i < 10; i++ ) {
169169

170170
#### stdlib_base_dists_binomial_mode( n, p )
171171

172-
Returns the [mode][mode] of a [binomial][binomial-distribution] distribution with parameters `n` (number of trials) and `p` (success probability).
172+
Returns the [mode][mode] of a [binomial][binomial-distribution] distribution with number of trials `n` and success probability `p`.
173173

174174
```c
175-
double out = stdlib_base_dists_binomial_mode( 10, 0.5 );
176-
// returns 5
175+
double out = stdlib_base_dists_binomial_mode( 100, 0.1 );
176+
// returns 10
177177
```
178178

179179
The function accepts the following arguments:
180180

181-
- **n**: `[in] int` number of trials.
181+
- **n**: `[in] int32_t` number of trials.
182182
- **p**: `[in] double` success probability.
183183

184184
```c
185-
double stdlib_base_dists_binomial_mode( const int n, const double p );
185+
double stdlib_base_dists_binomial_mode( const int32_t n, const double p );
186186
```
187187
188188
</section>
@@ -205,25 +205,30 @@ double stdlib_base_dists_binomial_mode( const int n, const double p );
205205
206206
```c
207207
#include "stdlib/stats/base/dists/binomial/mode.h"
208+
#include "stdlib/math/base/special/ceil.h"
208209
#include <stdlib.h>
210+
#include <stdint.h>
209211
#include <stdio.h>
210212
211213
static double random_uniform( const double min, const double max ) {
212214
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
213-
return min + ( v*(max-min) );
215+
return min + ( v * (max - min) );
214216
}
215217
216218
int main( void ) {
217-
int n;
219+
int32_t n;
218220
double p;
219221
double y;
220222
int i;
223+
221224
for ( i = 0; i < 25; i++ ) {
222-
n = (int)( random_uniform( 1.0, 20.0 ) );
225+
n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
223226
p = random_uniform( 0.0, 1.0 );
224227
y = stdlib_base_dists_binomial_mode( n, p );
225228
printf( "n: %d, p: %lf, mode(X;n,p): %lf\n", n, p, y );
226229
}
230+
231+
return 0;
227232
}
228233
```
229234

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/benchmark/benchmark.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2018 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,9 +21,10 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var ceil = require( '@stdlib/math/base/special/ceil' );
25+
var Int32Array = require( '@stdlib/array/int32' );
2526
var Float64Array = require( '@stdlib/array/float64' );
26-
var floor = require( '@stdlib/math/base/special/floor' );
27+
var randu = require( '@stdlib/random/base/randu' );
2728
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2829
var pkg = require( './../package.json' ).name;
2930
var mode = require( './../lib' );
@@ -39,10 +40,10 @@ bench( pkg, function benchmark( b ) {
3940
var i;
4041

4142
len = 100;
42-
n = new Float64Array( len );
43+
n = new Int32Array( len );
4344
p = new Float64Array( len );
4445
for ( i = 0; i < len; i++ ) {
45-
n[ i ] = floor( ( randu()*100.0 ) + 1.0 );
46+
n[ i ] = ceil( randu() * 100.0 );
4647
p[ i ] = randu();
4748
}
4849

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/benchmark/benchmark.native.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,11 +22,12 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25+
var Int32Array = require( '@stdlib/array/int32' );
2526
var Float64Array = require( '@stdlib/array/float64' );
26-
var floor = require( '@stdlib/math/base/special/floor' );
27+
var tryRequire = require( '@stdlib/utils/try-require' );
28+
var ceil = require( '@stdlib/math/base/special/ceil' );
2729
var randu = require( '@stdlib/random/base/randu' );
2830
var isnan = require( '@stdlib/math/base/assert/is-nan' );
29-
var tryRequire = require( '@stdlib/utils/try-require' );
3031
var pkg = require( './../package.json' ).name;
3132

3233

@@ -48,11 +49,11 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4849
var i;
4950

5051
len = 100;
51-
n = new Float64Array( len );
52+
n = new Int32Array( len );
5253
p = new Float64Array( len );
5354
for ( i = 0; i < len; i++ ) {
54-
n[ i ] = floor( ( randu()*100.0 ) + 1.0 ); // Ensure n >= 1
55-
p[ i ] = randu(); // Ensure p in [0, 1]
55+
n[ i ] = ceil( randu() * 100.0 );
56+
p[ i ] = randu();
5657
}
5758

5859
b.tic();

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/benchmark/c/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2024 The Stdlib Authors.
4+
# Copyright (c) 2025 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -143,4 +143,4 @@ run: $(c_targets)
143143
clean:
144144
$(QUIET) -rm -f *.o *.out
145145

146-
.PHONY: clean
146+
.PHONY: clean

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/benchmark/c/benchmark.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -17,7 +17,9 @@
1717
*/
1818

1919
#include "stdlib/stats/base/dists/binomial/mode.h"
20+
#include "stdlib/math/base/special/ceil.h"
2021
#include <stdlib.h>
22+
#include <stdint.h>
2123
#include <stdio.h>
2224
#include <math.h>
2325
#include <time.h>
@@ -37,8 +39,8 @@ static void print_version( void ) {
3739
/**
3840
* Prints the TAP summary.
3941
*
40-
* @param total total number of tests
41-
* @param passing total number of passing tests
42+
* @param total total number of tests
43+
* @param passing total number of passing tests
4244
*/
4345
static void print_summary( int total, int passing ) {
4446
printf( "#\n" );
@@ -52,7 +54,7 @@ static void print_summary( int total, int passing ) {
5254
/**
5355
* Prints benchmarks results.
5456
*
55-
* @param elapsed elapsed time in seconds
57+
* @param elapsed elapsed time in seconds
5658
*/
5759
static void print_results( double elapsed ) {
5860
double rate = (double)ITERATIONS / elapsed;
@@ -93,20 +95,20 @@ static double random_uniform( const double min, const double max ) {
9395
*/
9496
static double benchmark( void ) {
9597
double elapsed;
96-
double n[ 100 ];
98+
int32_t n[ 100 ];
9799
double p[ 100 ];
98100
double y;
99101
double t;
100102
int i;
101103

102104
for ( i = 0; i < 100; i++ ) {
103-
n[ i ] = random_uniform( 1.0, 100.0 ); // Ensure n >= 1
104-
p[ i ] = random_uniform( 0.0, 1.0 ); // Ensure p in [0, 1]
105+
n[ i ] = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
106+
p[ i ] = random_uniform( 0.0, 1.0 );
105107
}
106108

107109
t = tic();
108110
for ( i = 0; i < ITERATIONS; i++ ) {
109-
y = stdlib_base_dists_binomial_mode( n[ i%100 ], p[ i%100 ] );
111+
y = stdlib_base_dists_binomial_mode( n[ i % 100 ], p[ i % 100 ] );
110112
if ( y != y ) {
111113
printf( "should not return NaN\n" );
112114
break;

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/binding.gyp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @license Apache-2.0
22
#
3-
# Copyright (c) 2024 The Stdlib Authors.
3+
# Copyright (c) 2025 The Stdlib Authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -167,4 +167,4 @@
167167
], # end actions
168168
}, # end target copy_addon
169169
], # end targets
170-
}
170+
}

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/examples/c/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#/
22
# @license Apache-2.0
33
#
4-
# Copyright (c) 2024 The Stdlib Authors.
4+
# Copyright (c) 2025 The Stdlib Authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -143,4 +143,4 @@ run: $(c_targets)
143143
clean:
144144
$(QUIET) -rm -f *.o *.out
145145

146-
.PHONY: clean
146+
.PHONY: clean

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/examples/c/example.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -17,25 +17,28 @@
1717
*/
1818

1919
#include "stdlib/stats/base/dists/binomial/mode.h"
20+
#include "stdlib/math/base/special/ceil.h"
2021
#include <stdlib.h>
22+
#include <stdint.h>
2123
#include <stdio.h>
22-
#include <math.h>
2324

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

2930
int main( void ) {
31+
int32_t n;
3032
double p;
31-
double n;
3233
double y;
3334
int i;
3435

3536
for ( i = 0; i < 25; i++ ) {
36-
n = (double)floor(random_uniform( 1.0, 101.0 ));
37+
n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
3738
p = random_uniform( 0.0, 1.0 );
3839
y = stdlib_base_dists_binomial_mode( n, p );
39-
printf( "n: %lf, p: %lf, mode(X;n,p): %lf\n", n, p, y );
40+
printf( "n: %d, p: %lf, mode(X;n,p): %lf\n", n, p, y );
4041
}
42+
43+
return 0;
4144
}

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/include.gypi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @license Apache-2.0
22
#
3-
# Copyright (c) 2024 The Stdlib Authors.
3+
# Copyright (c) 2025 The Stdlib Authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -50,4 +50,4 @@
5050
'<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
5151
],
5252
}, # end variables
53-
}
53+
}

lib/node_modules/@stdlib/stats/base/dists/binomial/mode/include/stdlib/stats/base/dists/binomial/mode.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -19,6 +19,8 @@
1919
#ifndef STDLIB_STATS_BASE_DISTS_BINOMIAL_MODE_H
2020
#define STDLIB_STATS_BASE_DISTS_BINOMIAL_MODE_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,13 +29,9 @@ extern "C" {
2729
#endif
2830

2931
/**
30-
* Returns the mode of a binomial distribution.
31-
*
32-
* @param n number of trials (non-negative integer)
33-
* @param p success probability (0 <= p <= 1)
34-
* @return mode of the binomial distribution
32+
* Returns the mode of a binomial distribution with number of trials `n` and success probability `p`.
3533
*/
36-
double stdlib_base_dists_binomial_mode( const double n, const double p );
34+
double stdlib_base_dists_binomial_mode( const int32_t n, const double p );
3735

3836
#ifdef __cplusplus
3937
}

0 commit comments

Comments
 (0)