Skip to content

feat: add blas/base/srotmg #4710

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

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
119 changes: 119 additions & 0 deletions lib/node_modules/@stdlib/blas/base/srotmg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<!--

@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.

-->

# srotmg

> Constructs the parameters for a modified Givens plane rotation.

<section class="usage">

## Usage

```javascript
var srotmg = require( '@stdlib/blas/base/srotmg' );
```

#### srotmg( d1, d2, x1, y1 )

Constructs a Givens plane rotation provided four single-precision floating-point values `d1`, `d2`, `x1` and `y1`.

```javascript
var out = srotmg( 5.0, 4.0, 1.0, -2.0 );
// returns <Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5 ]
```

The function has the following parameters:

- **d1**: scaling factor for the first vector component.
- **d2**: scaling factor for the second vector component.
- **x1**: first component of the first vector.
- **y1**: first component of the second vector.

#### srotmg.assign( d1, d2, x1, y1, out, stride, offset )

Constructs a Givens plane rotation provided two single-precision floating-point values `d1`, `d2`, `x1` and `y1` and assigns results to an output array.

```javascript
var Float32Array = require( '@stdlib/array/float32' );

var out = new Float32Array( 5 );

var y = srotmg.assign( 5.0, 4.0, 1.0, -2.0, out, 1, 0 );
// returns <Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5 ]

var bool = ( y === out );
// returns true
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- `srotmg()` corresponds to the [BLAS][blas] level 1 function [`srotmg`][srotmg].

</section>

<!-- /.notes -->

<section class="examples">

```javascript
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var srotmg = require( '@stdlib/blas/base/srotmg' );

var out;
var i;
for ( i = 0; i < 100; i++ ) {
d1 = discreteUniform( -5, 5 );
d2 = discreteUniform( -5, 5 );
x1 = discreteUniform( -5, 5 );
y1 = discreteUniform( -5, 5 );
out = srotmg( d1, d2, x1, y1 );
console.log( out );
}
```

</section>

<!-- /.examples -->

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

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[blas]: http://www.netlib.org/blas

[srotmg]: http://www.netlib.org/lapack/explore-html/df/d28/group__single__blas__level1.html

</section>

<!-- /.links -->
96 changes: 96 additions & 0 deletions lib/node_modules/@stdlib/blas/base/srotmg/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* @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 bench = require( '@stdlib/bench' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var Float32Array = require( '@stdlib/array/float32' );
var pkg = require( './../package.json' ).name;
var srotmg = require( './../lib' );


// VARIABLES //

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


// MAIN //

bench( pkg, function benchmark( b ) {
var out;
var d1;
var d2;
var x1;
var y1;
var i;

d1 = discreteUniform( 100, -5, 5, OPTS );
d2 = discreteUniform( 100, -5, 5, OPTS );
x1 = discreteUniform( 100, -5, 5, OPTS );
y1 = discreteUniform( 100, -5, 5, OPTS );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = srotmg( d1[ i%d1.length ], d2[ i%d2.length ], x1[ i%x1.length ], y1[ i%y1.length ] );

Check warning on line 55 in lib/node_modules/@stdlib/blas/base/srotmg/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 99. Maximum allowed is 80
if ( isnanf( out[ i%5 ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnanf( out[ i%5 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+':assign', function benchmark( b ) {
var out;
var d1;
var d2;
var x1;
var y1;
var z;
var i;

d1 = discreteUniform( 100, -5, 5, OPTS );
d2 = discreteUniform( 100, -5, 5, OPTS );
x1 = discreteUniform( 100, -5, 5, OPTS );
y1 = discreteUniform( 100, -5, 5, OPTS );
out = new Float32Array( 5 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = srotmg.assign( d1[ i%d1.length ], d2[ i%d2.length ], x1[ i%x1.length ], y1[ i%y1.length ], out, 1, 0 );

Check warning on line 85 in lib/node_modules/@stdlib/blas/base/srotmg/benchmark/benchmark.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 115. Maximum allowed is 80
if ( typeof z !=='object' ) {
b.fail( 'should return an array' );
}
}
b.toc();
if ( isnanf( z[ i%5 ] ) ) {
b.fail( 'should return the output array' );
}
b.pass( 'benchmark finished' );
b.end();
});
71 changes: 71 additions & 0 deletions lib/node_modules/@stdlib/blas/base/srotmg/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

{{alias}}( d1, d2, x1, y1 )
Constructs the parameters for a modified Givens plane rotation.

Parameters
----------
d1: float
Scaling factor for the first vector component.

d2: float
Scaling factor for the second vector component.

x1: float
First component of the first vector.

y1: float
First component of the second vector.

Returns
-------
out: Float32Array
Computed values.

Examples
--------
> var out = {{alias}}( 5.0, 4.0, 1.0, -2.0 )
<Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5 ]


{{alias}}.assign( d1, d2, x1, y1, out, stride, offset )
Constructs the parameters for a modified Givens plane rotation and assigns
results to an output array.

Parameters
----------
d1: float
Scaling factor for the first vector component.

d2: float
Scaling factor for the second vector component.

x1: float
First component of the first vector.

y1: float
First component of the second vector.

out: Float32Array
Output array.

stride: integer
Output array stride.

offset: integer
Output array index offset.

Returns
-------
out: Float32Array
Output array.

Examples
--------
> var out = new {{alias:@stdlib/array/float32}}( 5 );
> var y = {{alias}}.assign( 5.0, 4.0, 1.0, -2.0, out, 1, 0 )
<Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5 ]
> var bool = ( y === out )
true

See Also
--------
101 changes: 101 additions & 0 deletions lib/node_modules/@stdlib/blas/base/srotmg/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* @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.
*/

// TypeScript Version: 4.1

/**
* Inteface describing `srotmg`.
*/
interface Routine {
/**
* Constructs the parameters for a modified Givens plane rotation.
*
* @param d1 - scaling factor for the first vector component
* @param d2 - scaling factor for the second vector component
* @param x1 - first component of the first vector
* @param y1 - first component of the second vector
* @returns - output array containing the rotation parameters
*
* @example
* var out = srotmg( 5.0, 4.0, 1.0, -2.0 );
* // returns <Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5 ]
*
* @example
* var out = srotmg( 4.0, 6.0, 2.0, 1.0 );
* // returns <Float32Array>[ 0.0, 0.0, -0.5, 0.75, 0.0 ]
*/
( d1: number, d2: number, x1: number, y1: number ): Float32Array;

/**
* Constructs the parameters for a modified Givens plane rotation and assigns results to an output array.
*
* @param d1 - scaling factor for the first vector component
* @param d2 - scaling factor for the second vector component
* @param x1 - first component of the first vector
* @param y1 - first component of the second vector
* @param out - output array
* @param stride - index increment
* @param offset - starting index
* @returns - output array containing the rotation parameters
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
*
* var out = new Float32Array( 5 );
*
* var y = srotmg.assign( 5.0, 4.0, 1.0, -2.0, new Float32Array( 5 ), 1, 0 );
* // returns <Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5 ]
*
* var bool = (y === out);
* // returns true
*/
assign( d1: number, d2: number, x1: number, y1: number, out: Float32Array, stride: number, offset: number ): Float32Array;
}

/**
* Constructs the parameters for a modified Givens plane rotation.
*
* @param d1 - scaling factor for the first vector component
* @param d2 - scaling factor for the second vector component
* @param x1 - first component of the first vector
* @param y1 - first component of the second vector
* @param out - output array
* @param stride - index increment
* @param offset - starting index
* @returns - output array containing the rotation parameters
*
* @example
* var out = srotmg( 5.0, 4.0, 1.0, -2.0 );
* // returns <Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5 ]
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
*
* var out = new Float32Array( 5 );
*
* var y = srotmg.assign( 5.0, 4.0, 1.0, -2.0, new Float32Array( 5 ), 1, 0 );
* // returns <Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5 ]
*
* var bool = (y === out);
* // returns true
*/
declare var srotmg: Routine;

// EXPORTS //

export = srotmg;
Loading