Skip to content

Commit 5bad1e8

Browse files
committed
chore: minor clean-up
--- 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: 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: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - 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 ---
1 parent fde535d commit 5bad1e8

File tree

13 files changed

+319
-279
lines changed

13 files changed

+319
-279
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ double out = stdlib_base_dists_binomial_pmf( 3.0, 20, 0.2 );
186186
The function accepts the following arguments:
187187

188188
- **x**: `[in] double` input value.
189-
- **n**: `[in] double` number of trials.
189+
- **n**: `[in] int32_t` number of trials.
190190
- **p**: `[in] double` success probability.
191191

192192
```c
193-
double stdlib_base_dists_binomial_pmf( const double x, const double n, const double p );
193+
double stdlib_base_dists_binomial_pmf( const double x, const int32_t n, const double p );
194194
```
195195
196196
</section>
@@ -212,27 +212,33 @@ double stdlib_base_dists_binomial_pmf( const double x, const double n, const dou
212212
### Examples
213213
214214
```c
215-
#include "stdlib/stats/base/dists/invgamma/variance.h"
215+
#include "stdlib/stats/base/dists/binomial/pmf.h"
216216
#include <stdlib.h>
217217
#include <stdio.h>
218+
#include <stdint.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
225+
static int32_t random_int( const int32_t min, const int32_t max ) {
226+
return min + (int32_t)( random_uniform( 0.0, 1.0 ) * ( max - min + 1 ) );
227+
}
228+
224229
int main( void ) {
225-
double x;
226-
double n;
230+
int32_t n;
227231
double p;
232+
double x;
228233
double y;
229234
int i;
235+
230236
for ( i = 0; i < 25; i++ ) {
231-
x = random_uniform( 0.0, 20.0 );
232-
n = random_uniform( 0.0, 20.0 );
233-
n = random_uniform( 0.0, 1.0 );
237+
n = random_int( 1, 20 );
238+
x = random_uniform( 0.0, (double)n );
239+
p = random_uniform( 0.0, 1.0 );
234240
y = stdlib_base_dists_binomial_pmf( x, n, p );
235-
printf( "x: %lf, n: %lf, p: %lf pmf(x, n, p): %lf\n", x, n, p, y );
241+
printf( "x: %.4f, n: %d, p: %.4f, P(X = x;n,p): %.4f\n", x, n, p, y );
236242
}
237243
}
238244
```

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var Float64Array = require( '@stdlib/array/float64' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2627
var tryRequire = require( '@stdlib/utils/try-require' );
27-
var ceil = require( '@stdlib/math/base/special/ceil' );
28-
var randu = require( '@stdlib/random/base/randu' );
2928
var isnan = require( '@stdlib/math/base/assert/is-nan' );
3029
var pkg = require( './../package.json' ).name;
3130

@@ -49,14 +48,9 @@ bench( pkg+'::native', opts, function benchmark( b ) {
4948
var i;
5049

5150
len = 100;
52-
x = new Float64Array( len );
53-
n = new Float64Array( len );
54-
p = new Float64Array( len );
55-
for ( i = 0; i < len; i++ ) {
56-
x[ i ] = ceil( randu()*50.0 );
57-
y[ i ] = ceil( randu()*50.0 );
58-
p[ i ] = randu();
59-
}
51+
x = discreteUniform( len, 0, 50 );
52+
n = discreteUniform( len, 1, 100 );
53+
p = uniform( len, 0.0, 1.0 );
6054

6155
b.tic();
6256
for ( i = 0; i < b.iterations; i++ ) {

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

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,82 @@ endif
4545
endif
4646
endif
4747

48+
# Define the program used for compiling C source files:
49+
ifdef C_COMPILER
50+
CC := $(C_COMPILER)
51+
else
52+
CC := gcc
53+
endif
54+
55+
# Define the command-line options when compiling C files:
56+
CFLAGS ?= \
57+
-std=c99 \
58+
-O3 \
59+
-Wall \
60+
-pedantic
61+
62+
# Determine whether to generate position independent code ([1][1], [2][2]).
63+
#
64+
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
65+
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
66+
ifeq ($(OS), WINNT)
67+
fPIC ?=
68+
else
69+
fPIC ?= -fPIC
70+
endif
71+
72+
# List of C targets:
73+
c_targets := benchmark.out
74+
4875

4976
# RULES #
5077

5178
#/
52-
# Removes generated files for building an add-on.
79+
# Compiles C source files.
80+
#
81+
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
82+
# @param {string} [CFLAGS] - C compiler options
83+
# @param {(string|void)} [fPIC] - compiler flag indicating whether to generate position independent code (e.g., `-fPIC`)
84+
#
85+
# @example
86+
# make
87+
#
88+
# @example
89+
# make all
90+
#/
91+
all: $(c_targets)
92+
93+
.PHONY: all
94+
95+
#/
96+
# Compiles C source files.
97+
#
98+
# @private
99+
# @param {string} CC - C compiler
100+
# @param {string} CFLAGS - C compiler flags
101+
# @param {(string|void)} fPIC - compiler flag indicating whether to generate position independent code
102+
#/
103+
$(c_targets): %.out: %.c
104+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) -o $@ $< -lm
105+
106+
#/
107+
# Runs compiled benchmarks.
53108
#
54109
# @example
55-
# make clean-addon
110+
# make run
56111
#/
57-
clean-addon:
58-
$(QUIET) -rm -f *.o *.node
112+
run: $(c_targets)
113+
$(QUIET) ./$<
59114

60-
.PHONY: clean-addon
115+
.PHONY: run
61116

62117
#/
63118
# Removes generated files.
64119
#
65120
# @example
66121
# make clean
67122
#/
68-
clean: clean-addon
123+
clean:
124+
$(QUIET) -rm -f *.o *.out
69125

70126
.PHONY: clean

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

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

19-
#include "stdlib/stats/base/dists/invgamma/pmf.h"
19+
#include "stdlib/stats/base/dists/binomial/pmf.h"
2020
#include <stdlib.h>
2121
#include <stdio.h>
22+
#include <stdint.h>
2223
#include <math.h>
2324
#include <time.h>
2425
#include <sys/time.h>
2526

26-
#define NAME "pmf"
27+
#define NAME "binomial-pmf"
2728
#define ITERATIONS 1000000
2829
#define REPEATS 3
2930

@@ -86,24 +87,35 @@ static double random_uniform( const double min, const double max ) {
8687
return min + ( v*(max-min) );
8788
}
8889

90+
/**
91+
* Generates a random integer on the interval [min,max].
92+
*
93+
* @param min minimum value (inclusive)
94+
* @param max maximum value (inclusive)
95+
* @return random integer
96+
*/
97+
static int32_t random_int( const int32_t min, const int32_t max ) {
98+
return min + (int32_t)( random_uniform( 0.0, 1.0 ) * ( max - min + 1 ) );
99+
}
100+
89101
/**
90102
* Runs a benchmark.
91103
*
92104
* @return elapsed time in seconds
93105
*/
94106
static double benchmark( void ) {
95107
double elapsed;
96-
double n[ 100 ];
97-
double p[ 100 ];
108+
double p[ 100 ];
98109
double x[ 100 ];
110+
int32_t n[ 100 ];
99111
double y;
100112
double t;
101113
int i;
102114

103115
for ( i = 0; i < 100; i++ ) {
104-
n[ i ] = random_uniform( 0.0, 20.0 );
116+
n[ i ] = random_int( 1, 50 );
105117
p[ i ] = random_uniform( 0.0, 1.0 );
106-
x[ i ] = random_uniform( 0.0, 20.0 );
118+
x[ i ] = random_uniform( 0.0, (double)n[ i ] );
107119
}
108120

109121
t = tic();

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

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,102 @@ endif
4545
endif
4646
endif
4747

48+
# Define the program used for compiling C source files:
49+
ifdef C_COMPILER
50+
CC := $(C_COMPILER)
51+
else
52+
CC := gcc
53+
endif
54+
55+
# Define the command-line options when compiling C files:
56+
CFLAGS ?= \
57+
-std=c99 \
58+
-O3 \
59+
-Wall \
60+
-pedantic
61+
62+
# Determine whether to generate position independent code ([1][1], [2][2]).
63+
#
64+
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
65+
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
66+
ifeq ($(OS), WINNT)
67+
fPIC ?=
68+
else
69+
fPIC ?= -fPIC
70+
endif
71+
72+
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
73+
INCLUDE ?=
74+
75+
# List of source files:
76+
SOURCE_FILES ?=
77+
78+
# List of libraries (e.g., `-lopenblas -lpthread`):
79+
LIBRARIES ?=
80+
81+
# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
82+
LIBPATH ?=
83+
84+
# List of C targets:
85+
c_targets := example.out
86+
4887

4988
# RULES #
5089

5190
#/
52-
# Removes generated files for building an add-on.
91+
# Compiles source files.
92+
#
93+
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
94+
# @param {string} [CFLAGS] - C compiler options
95+
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
96+
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
97+
# @param {string} [SOURCE_FILES] - list of source files
98+
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
99+
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
100+
#
101+
# @example
102+
# make
103+
#
104+
# @example
105+
# make all
106+
#/
107+
all: $(c_targets)
108+
109+
.PHONY: all
110+
111+
#/
112+
# Compiles C source files.
113+
#
114+
# @private
115+
# @param {string} CC - C compiler (e.g., `gcc`)
116+
# @param {string} CFLAGS - C compiler options
117+
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
118+
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
119+
# @param {string} SOURCE_FILES - list of source files
120+
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121+
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122+
#/
123+
$(c_targets): %.out: %.c
124+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
125+
126+
#/
127+
# Runs compiled examples.
53128
#
54129
# @example
55-
# make clean-addon
130+
# make run
56131
#/
57-
clean-addon:
58-
$(QUIET) -rm -f *.o *.node
132+
run: $(c_targets)
133+
$(QUIET) ./$<
59134

60-
.PHONY: clean-addon
135+
.PHONY: run
61136

62137
#/
63138
# Removes generated files.
64139
#
65140
# @example
66141
# make clean
67142
#/
68-
clean: clean-addon
143+
clean:
144+
$(QUIET) -rm -f *.o *.out
69145

70146
.PHONY: clean

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

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

19-
#include "stdlib/stats/base/dists/invgamma/pmf.h"
19+
#include "stdlib/stats/base/dists/binomial/pmf.h"
2020
#include <stdlib.h>
2121
#include <stdio.h>
22+
#include <stdint.h>
2223

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

29+
static int32_t random_int( const int32_t min, const int32_t max ) {
30+
return min + (int32_t)( random_uniform( 0.0, 1.0 ) * ( max - min + 1 ) );
31+
}
32+
2833
int main( void ) {
29-
double n;
34+
int32_t n;
3035
double p;
31-
double x;
36+
double x;
3237
double y;
3338
int i;
3439

3540
for ( i = 0; i < 25; i++ ) {
36-
n = random_uniform( 0.0, 20.0 );
37-
x = random_uniform( 0.0, 20.0 );
38-
p = random_uniform( 0.0, 1.0 );
41+
n = random_int( 1, 20 );
42+
x = random_uniform( 0.0, (double)n );
43+
p = random_uniform( 0.0, 1.0 );
3944
y = stdlib_base_dists_binomial_pmf( x, n, p );
40-
printf( "x: %lf, n: %lf, p: %lf pmf( x, n, p ): %lf\n", x, n, p, y );
45+
printf( "x: %.4f, n: %d, p: %.4f, P(X = x;n,p): %.4f\n", x, n, p, y );
4146
}
4247
}

0 commit comments

Comments
 (0)