Skip to content

Commit cd1a5a6

Browse files
gururaj1512kgryte
andauthored
feat: add stats/strided/sztest2
PR-URL: #7642 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent b6328d9 commit cd1a5a6

33 files changed

+5201
-0
lines changed

lib/node_modules/@stdlib/stats/strided/sztest2/README.md

Lines changed: 420 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var normal = require( '@stdlib/random/array/normal' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' );
28+
var pkg = require( './../package.json' ).name;
29+
var sztest2 = require( './../lib/sztest2.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float32'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} len - array length
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( len ) {
49+
var results;
50+
var x;
51+
var y;
52+
53+
results = new Results();
54+
x = normal( len, 0.0, 1.0, options );
55+
y = normal( len, 0.0, 1.0, options );
56+
57+
return benchmark;
58+
59+
function benchmark( b ) {
60+
var out;
61+
var i;
62+
63+
b.tic();
64+
for ( i = 0; i < b.iterations; i++ ) {
65+
out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, results );
66+
if ( isnanf( out.statistic ) ) {
67+
b.fail( 'should not return NaN' );
68+
}
69+
}
70+
b.toc();
71+
if ( isnanf( out.statistic ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
b.pass( 'benchmark finished' );
75+
b.end();
76+
}
77+
}
78+
79+
80+
// MAIN //
81+
82+
/**
83+
* Main execution sequence.
84+
*
85+
* @private
86+
*/
87+
function main() {
88+
var len;
89+
var min;
90+
var max;
91+
var f;
92+
var i;
93+
94+
min = 1; // 10^min
95+
max = 6; // 10^max
96+
97+
for ( i = min; i <= max; i++ ) {
98+
len = pow( 10, i );
99+
f = createBenchmark( len );
100+
bench( pkg+':len='+len, f );
101+
}
102+
}
103+
104+
main();
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var normal = require( '@stdlib/random/array/normal' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var tryRequire = require( '@stdlib/utils/try-require' );
29+
var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' );
30+
var pkg = require( './../package.json' ).name;
31+
32+
33+
// VARIABLES //
34+
35+
var sztest2 = tryRequire( resolve( __dirname, './../lib/sztest2.native.js' ) );
36+
var opts = {
37+
'skip': ( sztest2 instanceof Error )
38+
};
39+
var options = {
40+
'dtype': 'float32'
41+
};
42+
43+
44+
// FUNCTIONS //
45+
46+
/**
47+
* Creates a benchmark function.
48+
*
49+
* @private
50+
* @param {PositiveInteger} len - array length
51+
* @returns {Function} benchmark function
52+
*/
53+
function createBenchmark( len ) {
54+
var results;
55+
var x;
56+
var y;
57+
58+
results = new Results();
59+
x = normal( len, 0.0, 1.0, options );
60+
y = normal( len, 0.0, 1.0, options );
61+
62+
return benchmark;
63+
64+
function benchmark( b ) {
65+
var out;
66+
var i;
67+
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, results );
71+
if ( isnanf( out.statistic ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
}
75+
b.toc();
76+
if ( isnanf( out.statistic ) ) {
77+
b.fail( 'should not return NaN' );
78+
}
79+
b.pass( 'benchmark finished' );
80+
b.end();
81+
}
82+
}
83+
84+
85+
// MAIN //
86+
87+
/**
88+
* Main execution sequence.
89+
*
90+
* @private
91+
*/
92+
function main() {
93+
var len;
94+
var min;
95+
var max;
96+
var f;
97+
var i;
98+
99+
min = 1; // 10^min
100+
max = 6; // 10^max
101+
102+
for ( i = min; i <= max; i++ ) {
103+
len = pow( 10, i );
104+
f = createBenchmark( len );
105+
bench( pkg+'::native:len='+len, opts, f );
106+
}
107+
}
108+
109+
main();
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var normal = require( '@stdlib/random/array/normal' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' );
28+
var pkg = require( './../package.json' ).name;
29+
var sztest2 = require( './../lib/ndarray.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float32'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} len - array length
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( len ) {
49+
var results;
50+
var x;
51+
var y;
52+
53+
results = new Results();
54+
x = normal( len, 0.0, 1.0, options );
55+
y = normal( len, 0.0, 1.0, options );
56+
57+
return benchmark;
58+
59+
function benchmark( b ) {
60+
var out;
61+
var i;
62+
63+
b.tic();
64+
for ( i = 0; i < b.iterations; i++ ) {
65+
out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results );
66+
if ( isnanf( out.statistic ) ) {
67+
b.fail( 'should not return NaN' );
68+
}
69+
}
70+
b.toc();
71+
if ( isnanf( out.statistic ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
b.pass( 'benchmark finished' );
75+
b.end();
76+
}
77+
}
78+
79+
80+
// MAIN //
81+
82+
/**
83+
* Main execution sequence.
84+
*
85+
* @private
86+
*/
87+
function main() {
88+
var len;
89+
var min;
90+
var max;
91+
var f;
92+
var i;
93+
94+
min = 1; // 10^min
95+
max = 6; // 10^max
96+
97+
for ( i = min; i <= max; i++ ) {
98+
len = pow( 10, i );
99+
f = createBenchmark( len );
100+
bench( pkg+':len='+len, f );
101+
}
102+
}
103+
104+
main();

0 commit comments

Comments
 (0)