Skip to content

Commit 6faca94

Browse files
committed
feat: add benchmarks & missing imports to main
--- 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: na - 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 31bbbaf commit 6faca94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5890
-4
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var floor = require( '@stdlib/math/base/special/floor' );
27+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
29+
var pkg = require( './../package.json' ).name;
30+
var someBy = require( './../lib/10d_blocked.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var types = [ 'float64' ];
36+
var order = 'column-major';
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Predicate function.
43+
*
44+
* @param {*} value - ndarray element
45+
* @returns {boolean} result
46+
*/
47+
function clbk( value ) {
48+
return value > 0.0;
49+
}
50+
51+
/**
52+
* Creates a benchmark function.
53+
*
54+
* @private
55+
* @param {PositiveInteger} len - ndarray length
56+
* @param {NonNegativeIntegerArray} shape - ndarray shape
57+
* @param {string} xtype - ndarray data type
58+
* @returns {Function} benchmark function
59+
*/
60+
function createBenchmark( len, shape, xtype ) {
61+
var x;
62+
var n;
63+
64+
x = discreteUniform( len, 1, 100 );
65+
x = {
66+
'dtype': xtype,
67+
'data': x,
68+
'shape': shape,
69+
'strides': shape2strides( shape, order ),
70+
'offset': 0,
71+
'order': order
72+
};
73+
n = 5;
74+
return benchmark;
75+
76+
/**
77+
* Benchmark function.
78+
*
79+
* @private
80+
* @param {Benchmark} b - benchmark instance
81+
*/
82+
function benchmark( b ) {
83+
var out;
84+
var i;
85+
86+
b.tic();
87+
for ( i = 0; i < b.iterations; i++ ) {
88+
out = someBy( x, n, clbk );
89+
if ( typeof out !== 'boolean' ) {
90+
b.fail( 'should return a boolean' );
91+
}
92+
}
93+
b.toc();
94+
if ( !isBoolean( out ) ) {
95+
b.fail( 'should return a boolean' );
96+
}
97+
b.pass( 'benchmark finished' );
98+
b.end();
99+
}
100+
}
101+
102+
103+
// MAIN //
104+
105+
/**
106+
* Main execution sequence.
107+
*
108+
* @private
109+
*/
110+
function main() {
111+
var len;
112+
var min;
113+
var max;
114+
var sh;
115+
var t1;
116+
var f;
117+
var i;
118+
var j;
119+
120+
min = 1; // 10^min
121+
max = 6; // 10^max
122+
123+
for ( j = 0; j < types.length; j++ ) {
124+
t1 = types[ j ];
125+
for ( i = min; i <= max; i++ ) {
126+
len = pow( 10, i );
127+
128+
sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ];
129+
f = createBenchmark( len, sh, t1 );
130+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
131+
132+
sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ];
133+
f = createBenchmark( len, sh, t1 );
134+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
135+
136+
len = floor( pow( len, 1.0/10.0 ) );
137+
sh = [ len, len, len, len, len, len, len, len, len, len ];
138+
len *= pow( len, 9 );
139+
f = createBenchmark( len, sh, t1 );
140+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
141+
}
142+
}
143+
}
144+
145+
main();
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var floor = require( '@stdlib/math/base/special/floor' );
27+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
29+
var pkg = require( './../package.json' ).name;
30+
var someBy = require( './../lib/10d_blocked.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var types = [ 'float64' ];
36+
var order = 'row-major';
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Predicate function.
43+
*
44+
* @param {*} value - ndarray element
45+
* @returns {boolean} result
46+
*/
47+
function clbk( value ) {
48+
return value > 0.0;
49+
}
50+
51+
/**
52+
* Creates a benchmark function.
53+
*
54+
* @private
55+
* @param {PositiveInteger} len - ndarray length
56+
* @param {NonNegativeIntegerArray} shape - ndarray shape
57+
* @param {string} xtype - ndarray data type
58+
* @returns {Function} benchmark function
59+
*/
60+
function createBenchmark( len, shape, xtype ) {
61+
var x;
62+
var n;
63+
64+
x = discreteUniform( len, 1, 100 );
65+
x = {
66+
'dtype': xtype,
67+
'data': x,
68+
'shape': shape,
69+
'strides': shape2strides( shape, order ),
70+
'offset': 0,
71+
'order': order
72+
};
73+
n = 5;
74+
return benchmark;
75+
76+
/**
77+
* Benchmark function.
78+
*
79+
* @private
80+
* @param {Benchmark} b - benchmark instance
81+
*/
82+
function benchmark( b ) {
83+
var out;
84+
var i;
85+
86+
b.tic();
87+
for ( i = 0; i < b.iterations; i++ ) {
88+
out = someBy( x, n, clbk );
89+
if ( typeof out !== 'boolean' ) {
90+
b.fail( 'should return a boolean' );
91+
}
92+
}
93+
b.toc();
94+
if ( !isBoolean( out ) ) {
95+
b.fail( 'should return a boolean' );
96+
}
97+
b.pass( 'benchmark finished' );
98+
b.end();
99+
}
100+
}
101+
102+
103+
// MAIN //
104+
105+
/**
106+
* Main execution sequence.
107+
*
108+
* @private
109+
*/
110+
function main() {
111+
var len;
112+
var min;
113+
var max;
114+
var sh;
115+
var t1;
116+
var f;
117+
var i;
118+
var j;
119+
120+
min = 1; // 10^min
121+
max = 6; // 10^max
122+
123+
for ( j = 0; j < types.length; j++ ) {
124+
t1 = types[ j ];
125+
for ( i = min; i <= max; i++ ) {
126+
len = pow( 10, i );
127+
128+
sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ];
129+
f = createBenchmark( len, sh, t1 );
130+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
131+
132+
sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ];
133+
f = createBenchmark( len, sh, t1 );
134+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
135+
136+
len = floor( pow( len, 1.0/10.0 ) );
137+
sh = [ len, len, len, len, len, len, len, len, len, len ];
138+
len *= pow( len, 9 );
139+
f = createBenchmark( len, sh, t1 );
140+
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
141+
}
142+
}
143+
}
144+
145+
main();

0 commit comments

Comments
 (0)