Skip to content

Commit 383e49c

Browse files
chore: added benchmarks 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: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - 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: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: failed ---
1 parent 758dc37 commit 383e49c

File tree

20 files changed

+675
-140
lines changed

20 files changed

+675
-140
lines changed

lib/node_modules/@stdlib/blas/base/srotg/README.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,137 @@ for ( i = 0; i < 100; i++ ) {
9292

9393
<!-- /.examples -->
9494

95+
<!-- C interface documentation. -->
96+
97+
* * *
98+
99+
<section class="c">
100+
101+
## C APIs
102+
103+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
104+
105+
<section class="intro">
106+
107+
</section>
108+
109+
<!-- /.intro -->
110+
111+
<!-- C usage documentation. -->
112+
113+
<section class="usage">
114+
115+
### Usage
116+
117+
```c
118+
#include "stdlib/blas/base/srotg.h"
119+
```
120+
121+
#### c_srotg( a, b, \*Out, strideOut )
122+
123+
Constructs a Givens plane rotation provided two single-precision floating-point values `a` and `b`.
124+
125+
```c
126+
float Out[4];
127+
c_srotg( 0.0, 2.0, Out, 1 );
128+
// Out => <Float32Array>[ 2.0, 1.0, 0.0, 1.0 ]
129+
```
130+
131+
The function accepts the following arguments:
132+
133+
- **a**: `[in] float` rotational elimination parameter.
134+
- **b**: `[in] float` rotational elimination parameter.
135+
- **Out**: `[inout] float*` output array.
136+
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
137+
138+
```c
139+
void c_srotg_assign( float a, float b, float* Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut );
140+
```
141+
142+
#### c_srotg_assign(a, b, \*Out, strideOut, offsetOut )
143+
144+
Constructs a Givens plane rotation provided two single-precision floating-point values `a` and `b` and assigns results to an output array.
145+
146+
```c
147+
float Out[4];
148+
c_srotg_assign( 0.0, 2.0, Out, 1, 0 );
149+
// Out => <Float32Array>[ 2.0, 1.0, 0.0, 1.0 ]
150+
```
151+
152+
The function accepts the following arguments:
153+
154+
- **a**: `[in] float` rotational elimination parameter.
155+
- **b**: `[in] float` rotational elimination parameter.
156+
- **Out**: `[inout] float*` output array.
157+
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
158+
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.
159+
160+
Givens transformation.
161+
162+
```c
163+
void c_srotg_assign( float a, float b, float* Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut );
164+
```
165+
166+
</section>
167+
168+
<!-- /.usage -->
169+
170+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
171+
172+
<section class="notes">
173+
174+
</section>
175+
176+
<!-- /.notes -->
177+
178+
<!-- C API usage examples. -->
179+
180+
<section class="examples">
181+
182+
### Examples
183+
184+
```c
185+
#include "stdlib/blas/base/srotg.h"
186+
#include <stdio.h>
187+
188+
int main( void ) {
189+
// Specify rotational elimination parameter:
190+
const float a = 0.0;
191+
const float b = 2.0;
192+
int i;
193+
194+
// Create strided arrays:
195+
float Out[4];
196+
197+
// Specify stride lengths:
198+
const int strideOut = 1;
199+
200+
// Apply plane rotation:
201+
c_srotg( a, b, Out, strideOut );
202+
203+
// Print the result:
204+
for ( i = 0; i < 4; i++ ) {
205+
printf( "Out[%d] = %f\n", i, Out[i] );
206+
}
207+
208+
// Apply plane rotation
209+
c_srotg_assign( a, b, Out, strideOut, 0 );
210+
211+
// Print the result:
212+
for ( i = 0; i < 4; i++ ) {
213+
printf( "Out[%d] = %f\n", i, Out[i] );
214+
}
215+
}
216+
```
217+
218+
</section>
219+
220+
<!-- /.examples -->
221+
222+
</section>
223+
224+
<!-- /.c -->
225+
95226
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
96227
97228
<section class="related">
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 tryRequire = require( '@stdlib/utils/try-require' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
27+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
28+
var pkg = require( './../package.json' ).name;
29+
30+
31+
// VARIABLES //
32+
33+
var srotg = tryRequire( resolve( __dirname, './../lib/native.js' ) );
34+
var opts = {
35+
'skip': ( srotg instanceof Error )
36+
};
37+
38+
39+
// VARIABLES //
40+
41+
var OPTS = {
42+
'dtype': 'float32'
43+
};
44+
45+
46+
// MAIN //
47+
48+
bench( pkg, opts, function benchmark( b ) {
49+
var out;
50+
var x;
51+
var y;
52+
var i;
53+
54+
x = uniform( 100, -5, 5, OPTS );
55+
y = uniform( 100, -5, 5, OPTS );
56+
out = uniform( 4, 0, 0, OPTS );
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
srotg( x[ i%x.length ], y[ i%y.length ], out, 1, 0 );
61+
if ( typeof out !=='object' ) {
62+
b.fail( 'should return an array' );
63+
}
64+
}
65+
b.toc();
66+
if ( isnanf( out[ i%4 ] ) ) {
67+
b.fail( 'should return the output array' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
});

lib/node_modules/@stdlib/blas/base/srotg/benchmark/benchmark.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2525
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26-
var Float32Array = require( '@stdlib/array/float32' );
2726
var pkg = require( './../package.json' ).name;
2827
var srotg = require( './../lib' );
2928

@@ -43,8 +42,8 @@ bench( pkg, function benchmark( b ) {
4342
var y;
4443
var i;
4544

46-
x = discreteUniform( 100, -5, 5, OPTS );
47-
y = discreteUniform( 100, -5, 5, OPTS );
45+
x = uniform( 100, -5, 5, OPTS );
46+
y = uniform( 100, -5, 5, OPTS );
4847

4948
b.tic();
5049
for ( i = 0; i < b.iterations; i++ ) {
@@ -68,9 +67,9 @@ bench( pkg+':assign', function benchmark( b ) {
6867
var z;
6968
var i;
7069

71-
x = discreteUniform( 100, -5, 5, OPTS );
72-
y = discreteUniform( 100, -5, 5, OPTS );
73-
out = new Float32Array( 4 );
70+
x = uniform( 100, -5, 5, OPTS );
71+
y = uniform( 100, -5, 5, OPTS );
72+
out = uniform( 4, 0, 0, OPTS );
7473

7574
b.tic();
7675
for ( i = 0; i < b.iterations; i++ ) {

lib/node_modules/@stdlib/blas/base/srotg/benchmark/benchmark.native.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var tryRequire = require( '@stdlib/utils/try-require' );
26-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
2727
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
28-
var Float32Array = require( '@stdlib/array/float32' );
2928
var pkg = require( './../package.json' ).name;
3029

3130

@@ -52,13 +51,13 @@ bench( pkg, opts, function benchmark( b ) {
5251
var y;
5352
var i;
5453

55-
x = discreteUniform( 100, -5, 5, OPTS );
56-
y = discreteUniform( 100, -5, 5, OPTS );
57-
out = new Float32Array( 4 );
54+
x = uniform( 100, -5, 5, OPTS );
55+
y = uniform( 100, -5, 5, OPTS );
56+
out = uniform( 4, 0, 0, OPTS );
5857

5958
b.tic();
6059
for ( i = 0; i < b.iterations; i++ ) {
61-
srotg( x[ i%x.length ], y[ i%y.length ], out, 1, 0 );
60+
srotg( x[ i%x.length ], y[ i%y.length ], out, 1 );
6261
if ( typeof out !=='object' ) {
6362
b.fail( 'should return an array' );
6463
}

lib/node_modules/@stdlib/blas/base/srotg/benchmark/c/benchmark.c renamed to lib/node_modules/@stdlib/blas/base/srotg/benchmark/c/benchmark.length.c

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static double random_uniform( const double min, const double max ) {
9393
*
9494
* @return elapsed time in seconds
9595
*/
96-
static double benchmark( void ) {
96+
static double benchmark1( void ) {
9797
double elapsed;
9898
float a[ 100 ];
9999
float b[ 100 ];
@@ -108,7 +108,40 @@ static double benchmark( void ) {
108108

109109
t = tic();
110110
for ( i = 0; i < ITERATIONS; i++ ) {
111-
srotg( a[ i % 100 ], b[ i % 100 ], Out, 1, 0 );
111+
c_srotg( a[ i % 100 ], b[ i % 100 ], Out, 1 );
112+
if ( stdlib_base_is_nan( Out[0] ) || stdlib_base_is_nan( Out[1] ) || stdlib_base_is_nan( Out[2] ) || stdlib_base_is_nan( Out[3] ) ) {
113+
printf( "should not return NaN\n" );
114+
break;
115+
}
116+
}
117+
elapsed = tic() - t;
118+
if ( stdlib_base_is_nan( Out[0] ) || stdlib_base_is_nan( Out[1] ) || stdlib_base_is_nan( Out[2] ) || stdlib_base_is_nan( Out[3] ) ) {
119+
printf( "should not return NaN\n" );
120+
}
121+
return elapsed;
122+
}
123+
124+
/**
125+
* Runs a benchmark.
126+
*
127+
* @return elapsed time in seconds
128+
*/
129+
static double benchmark2( void ) {
130+
double elapsed;
131+
float a[ 100 ];
132+
float b[ 100 ];
133+
float Out[ 4 ];
134+
double t;
135+
int i;
136+
137+
for ( i = 0; i < 100; i++ ) {
138+
a[ i ] = random_uniform( 0.0, 100.0 );
139+
b[ i ] = random_uniform( 0.0, 100.0 ) - 50.0;
140+
}
141+
142+
t = tic();
143+
for ( i = 0; i < ITERATIONS; i++ ) {
144+
c_srotg_assign( a[ i % 100 ], b[ i % 100 ], Out, 1, 0 );
112145
if ( stdlib_base_is_nan( Out[0] ) || stdlib_base_is_nan( Out[1] ) || stdlib_base_is_nan( Out[2] ) || stdlib_base_is_nan( Out[3] ) ) {
113146
printf( "should not return NaN\n" );
114147
break;
@@ -126,17 +159,36 @@ static double benchmark( void ) {
126159
*/
127160
int main( void ) {
128161
double elapsed;
162+
int count;
163+
int iter;
164+
int len;
129165
int i;
130-
166+
int j;
131167
// Use the current time to seed the random number generator:
132168
srand( time( NULL ) );
133-
134169
print_version();
135-
for ( i = 0; i < REPEATS; i++ ) {
136-
printf( "# c::%s\n", NAME );
137-
elapsed = benchmark();
138-
print_results( elapsed );
139-
printf( "ok %d benchmark finished\n", i+1 );
170+
count = 0;
171+
for ( i = MIN; i <= MAX; i++ ) {
172+
len = pow( 10, i );
173+
iter = ITERATIONS / pow( 10, i-1 );
174+
for ( j = 0; j < REPEATS; j++ ) {
175+
count += 1;
176+
printf( "# c::%s:len=%d\n", NAME, len );
177+
elapsed = benchmark1( iter, len );
178+
print_results( iter, elapsed );
179+
printf( "ok %d benchmark finished\n", count );
180+
}
181+
}
182+
for ( i = MIN; i <= MAX; i++ ) {
183+
len = pow( 10, i );
184+
iter = ITERATIONS / pow( 10, i-1 );
185+
for ( j = 0; j < REPEATS; j++ ) {
186+
count += 1;
187+
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
188+
elapsed = benchmark2( iter, len );
189+
print_results( iter, elapsed );
190+
printf( "ok %d benchmark finished\n", count );
191+
}
140192
}
141-
print_summary( REPEATS, REPEATS );
193+
print_summary( count, count );
142194
}

0 commit comments

Comments
 (0)