Skip to content

Commit d477f6b

Browse files
committed
chore: 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: 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: passed - task: lint_javascript_benchmarks status: passed - 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: 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 68510c1 commit d477f6b

File tree

5 files changed

+138
-49
lines changed

5 files changed

+138
-49
lines changed

lib/node_modules/@stdlib/stats/base/dists/bradford/variance/benchmark/benchmark.native.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench/harness' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26-
var uniform = require( '@stdlib/random/base/uniform' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
2828
var pkg = require( './../package.json' ).name;
2929

@@ -39,14 +39,19 @@ var opts = {
3939
// MAIN //
4040

4141
bench( pkg+'::native', opts, function benchmark( b ) {
42+
var opts;
4243
var c;
4344
var y;
4445
var i;
4546

47+
opts = {
48+
'dtype': 'float64'
49+
};
50+
c = uniform( 100, 0.1, 10.0, opts );
51+
4652
b.tic();
4753
for ( i = 0; i < b.iterations; i++ ) {
48-
c = uniform( 0.1, 10.0 );
49-
y = variance( c );
54+
y = variance( c[ i % c.length ] );
5055
if ( isnan( y ) ) {
5156
b.fail( 'should not return NaN' );
5257
}

lib/node_modules/@stdlib/stats/base/dists/bradford/variance/benchmark/c/Makefile

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,102 @@ endif
4545
endif
4646
endif
4747

48-
# Define the command for removing files and directories:
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
4966
ifeq ($(OS), WINNT)
50-
CLEAN := del
51-
RMDIR := rmdir /Q /S
67+
fPIC ?=
5268
else
53-
CLEAN := rm -f
54-
RMDIR := rm -rf
69+
fPIC ?= -fPIC
5570
endif
5671

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 := benchmark.out
86+
5787

5888
# RULES #
5989

60-
# Remove generated files.
90+
#/
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 benchmarks.
128+
#
129+
# @example
130+
# make run
131+
#/
132+
run: $(c_targets)
133+
$(QUIET) ./$<
134+
135+
.PHONY: run
136+
137+
#/
138+
# Removes generated files.
139+
#
140+
# @example
141+
# make clean
142+
#/
61143
clean:
62-
$(QUIET) $(CLEAN) *.o *.obj *.exe
144+
$(QUIET) -rm -f *.o *.out
63145

64146
.PHONY: clean

lib/node_modules/@stdlib/stats/base/dists/bradford/variance/benchmark/c/benchmark.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,10 @@ static double benchmark( void ) {
9999
double y;
100100
int i;
101101

102-
// Generate test data:
103102
for ( i = 0; i < 100; i++ ) {
104103
c[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 );
105104
}
106105

107-
// Run the benchmark:
108106
t = tic();
109107
for ( i = 0; i < ITERATIONS; i++ ) {
110108
y = stdlib_base_dists_bradford_variance( c[ i % 100 ] );
@@ -125,21 +123,17 @@ static double benchmark( void ) {
125123
*/
126124
int main( void ) {
127125
double elapsed;
128-
int count;
129126
int i;
130127

131128
// Use the current time to seed the pseudorandom number generator:
132129
srand( time( NULL ) );
133130

134131
print_version();
135-
count = 0;
136132
for ( i = 0; i < REPEATS; i++ ) {
137-
count += 1;
138133
printf( "# c::%s\n", NAME );
139134
elapsed = benchmark();
140-
printf( "ok %d benchmark finished\n", count );
141135
print_results( elapsed );
142-
printf( "\n" );
136+
printf( "ok %d benchmark finished\n", i+1 );
143137
}
144-
print_summary( count, count );
138+
print_summary( REPEATS, REPEATS );
145139
}

lib/node_modules/@stdlib/stats/base/dists/bradford/variance/lib/native.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ var addon = require( './../src/addon.node' );
5656
* var v = variance( NaN );
5757
* // returns NaN
5858
*/
59-
var variance = addon;
59+
function variance( c ) {
60+
return addon( c );
61+
}
6062

6163

6264
// EXPORTS //

lib/node_modules/@stdlib/stats/base/dists/bradford/variance/test/test.native.js

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ var opts = {
3939

4040
// FIXTURES //
4141

42-
var data = require( './fixtures/python/small_c.json' );
42+
var smallC = require( './fixtures/python/small_c.json' );
43+
var largeC = require( './fixtures/python/large_c.json' );
4344

4445

4546
// TESTS //
@@ -56,64 +57,69 @@ tape( 'if provided `NaN` for `c`, the function returns `NaN`', opts, function te
5657
t.end();
5758
});
5859

59-
tape( 'if provided a nonpositive `c`, the function returns `NaN`', opts, function test( t ) {
60+
tape( 'if provided `c <= 0`, the function returns `NaN`', opts, function test( t ) {
6061
var v;
6162

6263
v = variance( 0.0 );
63-
t.equal( isnan( v ), true, 'returns NaN' );
64+
t.equal( isnan( v ), true, 'returns expected value' );
6465

6566
v = variance( -1.0 );
66-
t.equal( isnan( v ), true, 'returns NaN' );
67+
t.equal( isnan( v ), true, 'returns expected value' );
6768

6869
v = variance( NINF );
69-
t.equal( isnan( v ), true, 'returns NaN' );
70+
t.equal( isnan( v ), true, 'returns expected value' );
7071

7172
t.end();
7273
});
7374

74-
tape( 'the function returns the variance of a Bradford distribution', opts, function test( t ) {
75+
tape( 'the function returns the variance of a Bradford distribution given small parameter `c`', opts, function test( t ) {
7576
var expected;
7677
var delta;
7778
var tol;
78-
var c;
79-
var v;
8079
var i;
80+
var c;
81+
var y;
8182

82-
// Use tolerance for floating-point comparison
83-
tol = 100.0 * EPS; // ~2.22e-14
84-
expected = data.expected;
85-
c = data.c;
86-
for ( i = 0; i < c.length; i++ ) {
87-
v = variance( c[i] );
88-
if ( v === expected[ i ] ) {
89-
t.equal( v, expected[ i ], 'returns expected value' );
83+
expected = smallC.expected;
84+
c = smallC.c;
85+
for ( i = 0; i < expected.length; i++ ) {
86+
y = variance( c[i] );
87+
if ( y === expected[i] ) {
88+
t.equal( y, expected[i], 'c: '+c[i]+', y: '+y+', expected: '+expected[i] );
9089
} else {
91-
delta = abs( v - expected[ i ] );
92-
t.ok( delta <= tol, 'within tolerance. c: ' + c[i] + '. Expected: ' + expected[i] + '. Actual: ' + v + '. Tolerance: ' + tol + '.' );
90+
delta = abs( y - expected[ i ] );
91+
92+
/*
93+
* NOTE: the tolerance is set high in this case due to:
94+
*
95+
* 1. The shape parameter being very small which causes differences in the `ln` calculations when compared to the test fixtures by SciPy.
96+
* 2. The expected values being very small.
97+
*/
98+
tol = 643.0 * EPS * abs( expected[ i ] );
99+
t.ok( delta <= tol, 'within tolerance. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
93100
}
94101
}
95102
t.end();
96103
});
97104

98-
tape( 'the function returns the variance of a Bradford distribution (test fixtures)', opts, function test( t ) {
105+
tape( 'the function returns the variance of a Bradford distribution given large parameter `c`', opts, function test( t ) {
99106
var expected;
100107
var delta;
101108
var tol;
102-
var c;
103-
var v;
104109
var i;
110+
var c;
111+
var y;
105112

106-
// We test against more stringent tolerance here given the ln operations in the implementation
107-
tol = 100.0 * EPS; // ~2.22e-14
108-
expected = data.expected;
109-
c = data.c;
113+
expected = largeC.expected;
114+
c = largeC.c;
110115
for ( i = 0; i < expected.length; i++ ) {
111-
v = variance( c[i] );
112-
if ( v === expected[ i ] ) {
113-
t.equal( v, expected[ i ], 'returns expected value' );
116+
y = variance( c[i] );
117+
if ( y === expected[i] ) {
118+
t.equal( y, expected[i], 'c: '+c[i]+', y: '+y+', expected: '+expected[i] );
114119
} else {
115-
delta = abs( v - expected[ i ] );
116-
t.ok( delta <= tol, 'within tolerance. c: ' + c[i] + '. Expected: ' + expected[i] + '. Actual: ' + v + '. Tolerance: ' + tol + '.' );
120+
delta = abs( y - expected[ i ] );
121+
tol = 15.2 * EPS * abs( expected[ i ] );
122+
t.ok( delta <= tol, 'within tolerance. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
117123
}
118124
}
119125
t.end();

0 commit comments

Comments
 (0)