Skip to content

Commit 44aba3a

Browse files
committed
refactor: update implementation
1 parent 6a08ba7 commit 44aba3a

File tree

17 files changed

+531
-124
lines changed

17 files changed

+531
-124
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 Float64Array = require( '@stdlib/array/float64' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var floor = require( '@stdlib/math/base/special/floor' );
29+
var pkg = require( './../package.json' ).name;
30+
var drotg = require( './../lib/assign.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var options = {
36+
'dtype': 'float64'
37+
};
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark() {
49+
var x = uniform( -10.0, 10.0, options );
50+
var y = uniform( -10.0, 10.0, options );
51+
return benchmark;
52+
53+
/**
54+
* Benchmark function.
55+
*
56+
* @private
57+
* @param {Benchmark} b - benchmark instance
58+
*/
59+
function benchmark( b ) {
60+
var z;
61+
var i;
62+
63+
b.tic();
64+
for ( i = 0; i < b.iterations; i++ ) {
65+
out = new Float64Array( 4 );
66+
z = drotg( x, y, out, 1, 0 );
67+
if ( isnan( z[ i%z.length ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
}
71+
b.toc();
72+
if ( isnan( z[ i%z.length ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
}
78+
}
79+
80+
81+
// MAIN //
82+
83+
/**
84+
* Main execution sequence.
85+
*
86+
* @private
87+
*/
88+
function main() {
89+
var N;
90+
var min;
91+
var max;
92+
var f;
93+
var i;
94+
95+
min = 1; // 10^min
96+
max = 6; // 10^max
97+
98+
for ( i = min; i <= max; i++ ) {
99+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
100+
f = createBenchmark( N );
101+
bench( pkg+':assign:size='+(N*N), f );
102+
}
103+
}
104+
105+
main();
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 Float64Array = require( '@stdlib/array/float64' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var pow = require( '@stdlib/math/base/special/pow' );
29+
var floor = require( '@stdlib/math/base/special/floor' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
var pkg = require( '@stdlib/blas/base/drotg/package.json' ).name;
32+
33+
34+
// VARIABLES //
35+
36+
var drotg = tryRequire( resolve( __dirname, './../lib/assign.native.js' ) );
37+
var opts = {
38+
'skip': ( drotg instanceof Error )
39+
};
40+
var options = {
41+
'dtype': 'float64'
42+
};
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @returns {Function} benchmark function
52+
*/
53+
function createBenchmark() {
54+
var x = uniform( -10.0, 10.0, options );
55+
var y = uniform( -10.0, 10.0, options );
56+
return benchmark;
57+
58+
/**
59+
* Benchmark function.
60+
*
61+
* @private
62+
* @param {Benchmark} b - benchmark instance
63+
*/
64+
function benchmark( b ) {
65+
var z;
66+
var i;
67+
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
out = new Float64Array( 4 );
71+
z = drotg( x, y, out, 1, 0 );
72+
if ( isnan( z[ i%z.length ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
}
76+
b.toc();
77+
if ( isnan( z[ i%z.length ] ) ) {
78+
b.fail( 'should not return NaN' );
79+
}
80+
b.pass( 'benchmark finished' );
81+
b.end();
82+
}
83+
}
84+
85+
86+
// MAIN //
87+
88+
/**
89+
* Main execution sequence.
90+
*
91+
* @private
92+
*/
93+
function main() {
94+
var min;
95+
var max;
96+
var N;
97+
var f;
98+
var i;
99+
100+
min = 1; // 10^min
101+
max = 6; // 10^max
102+
103+
for ( i = min; i <= max; i++ ) {
104+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
105+
f = createBenchmark( N );
106+
bench( pkg+'::native:assign:size='+(N*N), opts, f );
107+
}
108+
}
109+
110+
main();
Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2023 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,68 +21,83 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
24+
var uniform = require( '@stdlib/random/base/uniform' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26-
var Float64Array = require( '@stdlib/array/float64' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
2728
var pkg = require( './../package.json' ).name;
28-
var drotg = require( './../lib' );
29+
var drotg = require( './../lib/drotg.js' );
2930

3031

3132
// VARIABLES //
3233

33-
var OPTS = {
34+
var options = {
3435
'dtype': 'float64'
3536
};
3637

3738

38-
// MAIN //
39+
// FUNCTIONS //
3940

40-
bench( pkg, function benchmark( b ) {
41-
var out;
42-
var x;
43-
var y;
44-
var i;
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @returns {Function} benchmark function
46+
*/
47+
function createBenchmark() {
48+
var x = uniform( -10.0, 10.0 );
49+
var y = uniform( -10.0, 10.0 );
50+
return benchmark;
4551

46-
x = discreteUniform( 100, -5, 5, OPTS );
47-
y = discreteUniform( 100, -5, 5, OPTS );
52+
/**
53+
* Benchmark function.
54+
*
55+
* @private
56+
* @param {Benchmark} b - benchmark instance
57+
*/
58+
function benchmark( b ) {
59+
var z;
60+
var i;
4861

49-
b.tic();
50-
for ( i = 0; i < b.iterations; i++ ) {
51-
out = drotg( x[ i%x.length ], y[ i%y.length ] );
52-
if ( isnan( out[ i%4 ] ) ) {
62+
b.tic();
63+
for ( i = 0; i < b.iterations; i++ ) {
64+
z = drotg( x, y );
65+
if ( isnan( z[ i%z.length ] ) ) {
66+
b.fail( 'should not return NaN' );
67+
}
68+
}
69+
b.toc();
70+
if ( isnan( z[ i%z.length ] ) ) {
5371
b.fail( 'should not return NaN' );
5472
}
73+
b.pass( 'benchmark finished' );
74+
b.end();
5575
}
56-
b.toc();
57-
if ( isnan( out[ i%4 ] ) ) {
58-
b.fail( 'should not return NaN' );
59-
}
60-
b.pass( 'benchmark finished' );
61-
b.end();
62-
});
63-
64-
bench( pkg+':assign', function benchmark( b ) {
65-
var out;
66-
var x;
67-
var y;
68-
var z;
76+
}
77+
78+
79+
// MAIN //
80+
81+
/**
82+
* Main execution sequence.
83+
*
84+
* @private
85+
*/
86+
function main() {
87+
var min;
88+
var max;
89+
var N;
90+
var f;
6991
var i;
7092

71-
x = discreteUniform( 100, -5, 5, OPTS );
72-
y = discreteUniform( 100, -5, 5, OPTS );
73-
out = new Float64Array( 4 );
93+
min = 1; // 10^min
94+
max = 6; // 10^max
7495

75-
b.tic();
76-
for ( i = 0; i < b.iterations; i++ ) {
77-
z = drotg.assign( x[ i%x.length ], y[ i%y.length ], out, 1, 0 );
78-
if ( typeof z !=='object' ) {
79-
b.fail( 'should return an array' );
80-
}
96+
for ( i = min; i <= max; i++ ) {
97+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
98+
f = createBenchmark( N );
99+
bench( pkg+':size='+(N*N), f );
81100
}
82-
b.toc();
83-
if ( isnan( z[ i%4 ] ) ) {
84-
b.fail( 'should return the output array' );
85-
}
86-
b.pass( 'benchmark finished' );
87-
b.end();
88-
});
101+
}
102+
103+
main();

0 commit comments

Comments
 (0)