Skip to content

feat: add C implementation and refactor of blas/base/srotg #4762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions lib/node_modules/@stdlib/blas/base/srotg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,137 @@ for ( i = 0; i < 100; i++ ) {

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/blas/base/srotg.h"
```

#### c_srotg( a, b, \*Out, strideOut )

Constructs a Givens plane rotation provided two single-precision floating-point values `a` and `b`.

```c
float Out[4];
c_srotg( 0.0, 2.0, Out, 1 );
// Out => <Float32Array>[ 2.0, 1.0, 0.0, 1.0 ]
```

The function accepts the following arguments:

- **a**: `[in] float` rotational elimination parameter.
- **b**: `[in] float` rotational elimination parameter.
- **Out**: `[inout] float*` output array.
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.

```c
void c_srotg_assign( float a, float b, float* Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut );
```

#### c_srotg_assign(a, b, \*Out, strideOut, offsetOut )

Constructs a Givens plane rotation provided two single-precision floating-point values `a` and `b` and assigns results to an output array.

```c
float Out[4];
c_srotg_assign( 0.0, 2.0, Out, 1, 0 );
// Out => <Float32Array>[ 2.0, 1.0, 0.0, 1.0 ]
```

The function accepts the following arguments:

- **a**: `[in] float` rotational elimination parameter.
- **b**: `[in] float` rotational elimination parameter.
- **Out**: `[inout] float*` output array.
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.

Givens transformation.

```c
void c_srotg_assign( float a, float b, float* Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/blas/base/srotg.h"
#include <stdio.h>

int main( void ) {
// Specify rotational elimination parameter:
const float a = 0.0;
const float b = 2.0;
int i;

// Create strided arrays:
float Out[4];

// Specify stride lengths:
const int strideOut = 1;

// Apply plane rotation:
c_srotg( a, b, Out, strideOut );

// Print the result:
for ( i = 0; i < 4; i++ ) {
printf( "Out[%d] = %f\n", i, Out[i] );
}

// Apply plane rotation
c_srotg_assign( a, b, Out, strideOut, 0 );

// Print the result:
for ( i = 0; i < 4; i++ ) {
printf( "Out[%d] = %f\n", i, Out[i] );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var tryRequire = require( '@stdlib/utils/try-require' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var srotg = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( srotg instanceof Error )
};


// VARIABLES //

var OPTS = {
'dtype': 'float32'
};


// MAIN //

bench( pkg, opts, function benchmark( b ) {
var out;
var x;
var y;
var i;

x = uniform( 100, -5, 5, OPTS );
y = uniform( 100, -5, 5, OPTS );
out = uniform( 4, 0, 0, OPTS );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
srotg( x[ i%x.length ], y[ i%y.length ], out, 1, 0 );
if ( typeof out !=='object' ) {
b.fail( 'should return an array' );
}
}
b.toc();
if ( isnanf( out[ i%4 ] ) ) {
b.fail( 'should return the output array' );
}
b.pass( 'benchmark finished' );
b.end();
});
13 changes: 6 additions & 7 deletions lib/node_modules/@stdlib/blas/base/srotg/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
// MODULES //

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

Expand All @@ -43,8 +42,8 @@ bench( pkg, function benchmark( b ) {
var y;
var i;

x = discreteUniform( 100, -5, 5, OPTS );
y = discreteUniform( 100, -5, 5, OPTS );
x = uniform( 100, -5, 5, OPTS );
y = uniform( 100, -5, 5, OPTS );

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

x = discreteUniform( 100, -5, 5, OPTS );
y = discreteUniform( 100, -5, 5, OPTS );
out = new Float32Array( 4 );
x = uniform( 100, -5, 5, OPTS );
y = uniform( 100, -5, 5, OPTS );
out = uniform( 4, 0, 0, OPTS );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var tryRequire = require( '@stdlib/utils/try-require' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var srotg = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( srotg instanceof Error )
};


// VARIABLES //

var OPTS = {
'dtype': 'float32'
};


// MAIN //

bench( pkg, opts, function benchmark( b ) {
var out;
var x;
var y;
var i;

x = uniform( 100, -5, 5, OPTS );
y = uniform( 100, -5, 5, OPTS );
out = uniform( 4, 0, 0, OPTS );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
srotg( x[ i%x.length ], y[ i%y.length ], out, 1 );
if ( typeof out !=='object' ) {
b.fail( 'should return an array' );
}
}
b.toc();
if ( isnanf( out[ i%4 ] ) ) {
b.fail( 'should return the output array' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading