Skip to content

Commit e3d0470

Browse files
committed
fix: chi pdf c implementation and tests
--- 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: na - 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: na - 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 ec55d90 commit e3d0470

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

lib/node_modules/@stdlib/stats/base/dists/chi/pdf/benchmark/benchmark.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
var bench = require( '@stdlib/bench' );
2424
var Float64Array = require( '@stdlib/array/float64' );
25-
var uniform = require( '@stdlib/random/array/uniform' );
26-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
2726
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2827
var pkg = require( './../package.json' ).name;
2928
var pdf = require( './../lib' );
@@ -42,8 +41,8 @@ bench( pkg, function benchmark( b ) {
4241
x = new Float64Array( len );
4342
k = new Float64Array( len );
4443
for ( i = 0; i < len; i++ ) {
45-
x[ i ] = ( randu() * 20.0 ) - 10.0;
46-
k[ i ] = ( randu() * 20.0 ) + 0.1;
44+
x[ i ] = uniform( -10.0, 10.0 );
45+
k[ i ] = uniform( 0.1, 20.1 );
4746
}
4847

4948
b.tic();
@@ -61,7 +60,7 @@ bench( pkg, function benchmark( b ) {
6160
b.end();
6261
});
6362

64-
bench( pkg + ':factory', function benchmark( b ) {
63+
bench( pkg+':factory', function benchmark( b ) {
6564
var mypdf;
6665
var k;
6766
var x;
@@ -70,7 +69,10 @@ bench( pkg + ':factory', function benchmark( b ) {
7069

7170
k = 2.0;
7271
mypdf = pdf.factory( k );
73-
x = uniform( 100, -2.0, 2.0 );
72+
x = new Float64Array( 100 );
73+
for ( i = 0; i < 100; i++ ) {
74+
x[ i ] = uniform( -2.0, 2.0 );
75+
}
7476

7577
b.tic();
7678
for ( i = 0; i < b.iterations; i++ ) {

lib/node_modules/@stdlib/stats/base/dists/chi/pdf/benchmark/benchmark.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var opts = {
3939

4040
// MAIN //
4141

42-
bench( pkg + '::native', opts, function benchmark( b ) {
42+
bench( pkg+'::native', opts, function benchmark( b ) {
4343
var len;
4444
var k;
4545
var x;

lib/node_modules/@stdlib/stats/base/dists/chi/pdf/test/test.native.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,23 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, f
5959
t.end();
6060
});
6161

62-
tape( 'if provided a non-positive `k`, the function returns `NaN`', opts, function test( t ) {
62+
tape( 'if provided a negative `k`, the function returns `NaN`', opts, function test( t ) {
6363
var y;
6464

6565
y = pdf( 2.0, -1.0 );
6666
t.equal( isnan( y ), true, 'returns NaN' );
6767

68+
t.end();
69+
});
70+
71+
tape( 'if `k` equals `0`, the function evaluates a degenerate distribution centered at `0`', opts, function test( t ) {
72+
var y;
73+
74+
y = pdf( 0.0, 0.0 );
75+
t.equal( y, PINF, 'returns +infinity for x equal to 0' );
76+
6877
y = pdf( 2.0, 0.0 );
69-
t.equal( isnan( y ), true, 'returns NaN' );
78+
t.equal( y, 0.0, 'returns 0' );
7079

7180
t.end();
7281
});

0 commit comments

Comments
 (0)