Skip to content
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

feat: add @stdlib/blas/base/drotg #929

Merged
merged 27 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
114 changes: 114 additions & 0 deletions lib/node_modules/@stdlib/blas/base/drotg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<!--

@license Apache-2.0

Copyright (c) 2023 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.

-->

# drotg

> Construct a Givens plane rotation.

<section class="usage">

## Usage

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

#### drotg( a, b )

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

```javascript
var out = drotg( 0.0, 2.0 );
// returns <Float64Array>[ 2.0, 1.0, 0.0, 1.0 ]
```

The function has the following parameters:

- **a**: rotational elimination parameter.
- **b**: rotational elimination parameter.

#### drotg.assign( a, b, out, stride, offset )

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

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var out = new Float64Array( 4 );

var y = drotg.assign( 0.0, 2.0, out, 1, 0 );
// returns <Float64Array>[ 2.0, 1.0, 0.0, 1.0 ]

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

</section>

<!-- /.usage -->

<section class="notes">

## Notes

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

</section>

<!-- /.notes -->

<section class="examples">

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

var out;
var i;

for ( i = 0; i < 100; i++ ) {
out = drotg( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
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

[drotg]: https://netlib.org/lapack/explore-html/df/d28/group__single__blas__level1_gaafa91c51f75df6c3f2182032a221c2db.html

</section>

<!-- /.links -->
88 changes: 88 additions & 0 deletions lib/node_modules/@stdlib/blas/base/drotg/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float32Array = require( '@stdlib/array/float32' );
kgryte marked this conversation as resolved.
Show resolved Hide resolved
var pkg = require( './../package.json' ).name;
var drotg = require( './../lib' );


// VARIABLES //

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


// MAIN //

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

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = drotg( x[ i%x.length ], y[ i%y.length ] );
if ( isnan( out[ i%4 ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( out[ i%4 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+':assign', function benchmark( b ) {
var out;
var x;
var y;
var z;
var i;

x = discreteUniform( 100, -5, 5, OPTS );
y = discreteUniform( 100, -5, 5, OPTS );
out = new Float32Array( 4 );
kgryte marked this conversation as resolved.
Show resolved Hide resolved

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = drotg.assign( x[ i%x.length ], y[ i%y.length ], out, 1, 0 );
if ( typeof z !=='object' ) {
b.fail( 'should return an array' );
}
}
b.toc();
if ( isnan( z[ i%4 ] ) ) {
b.fail( 'should return the output array' );
}
b.pass( 'benchmark finished' );
b.end();
});
60 changes: 60 additions & 0 deletions lib/node_modules/@stdlib/blas/base/drotg/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

{{alias}}( a, b )
Constructs a Givens plane rotation from two double-precision floating-point
numbers.

Parameters
----------
a: float
Rotational elimination parameter.

b: float
Rotational elimination parameter.

Returns
-------
out: Float64Array
Computed values.

Examples
--------
> var out = {{alias}}( 0.0, 2.0 )
<Float64Array>[ 2.0, 1.0, 0.0, 1.0 ]


{{alias}}.assign( a, b, out, stride, offset )
Constructs a Givens plane rotation from two double-precision floating-point
numbers and assigns the results to an output array.

Parameters
----------
a: float
Rotational elimination parameter.

b: float
Rotational elimination parameter.

out: Float64Array
Output array.

stride: integer
Output array stride.

offset: integer
Output array index offset.

Returns
-------
out: Float64Array
Output array.

Examples
--------
> var out = new {{alias:@stdlib/array/float64}}( 4 );
> var y = {{alias}}.assign( 0.0, 2.0, out, 1, 0 )
<Float64Array>[ 2.0, 1.0, 0.0, 1.0 ]
> var bool = ( y === out )
true

See Also
--------
92 changes: 92 additions & 0 deletions lib/node_modules/@stdlib/blas/base/drotg/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2023 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: 2.0

/**
* Inteface describing `drotg`.
*/
interface Routine {
/**
* Constructs a Givens plane rotation.
*
* @param a - rotational elimination parameter
* @param b - rotational elimination parameter
* @returns output array
*
* @example
* var out = drotg( 0.0, 2.0 );
* // returns <Float64Array>[ 2.0, 1.0, 0.0, 1.0 ]
*
* @example
* var out = drotg( 6.0, -8.0 );
* // returns <Float64Array>[ 10.0, ~-1.666, -0.6, 0.8 ]
*/
( a: number, b: number ): Float64Array;

/**
* Constructs a Givens plane rotation.
*
* @param a - rotational elimination parameter
* @param b - rotational elimination parameter
* @param out - output array
* @param stride - index increment
* @param offset - starting index
* @returns output array
*
* @example
* var Float64Array = require( `@stdlib/array/float64` );
*
* var out = new Float64Array( 4 );
*
* var y = drotg.assign( 0.0, 2.0, out, 1, 0 );
* // returns <Float64Array>[ 2.0, 1.0, 0.0, 1.0 ]
*
* var bool = ( y === out );
* // returns true
*/
assign( a: number, b: number, out: Float64Array, stride: number, offset: number ): Float64Array; // tslint-disable-line max-line-length
}

/**
* Constructs a Givens plane rotation.
*
* @param a - rotational elimination parameter
* @param b - rotational elimination parameter
* @returns output array
*
* @example
* var out = drotg( 0.0, 2.0 );
* // returns <Float64Array>[ 2.0, 1.0, 0.0, 1.0 ]
*
* @example
* var Float64Array = require( `@stdlib/array/float64` );
*
* var out = new Float64Array( 4 );
* var y = drotg.assign( 0.0, 2.0, out, 1, 0 );
* // returns <Float64Array>[ 2.0, 1.0, 0.0, 1.0 ]
*
* var bool = ( y === out );
* // returns true
*/
declare var drotg: Routine;


// EXPORTS //

export = drotg;
Loading