Skip to content
Open
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
278 changes: 278 additions & 0 deletions lib/node_modules/@stdlib/blas/base/zrotg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
<!--

@license Apache-2.0

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

-->

# zrotg

> Construct a Givens plane rotation.

<section class="usage">

## Usage

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

#### zrotg( za, zb )

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

```javascript
var Complex128 = require( '@stdlib/complex/float64/ctor' );

var za = new Complex128( 4.0, 3.0 );
var zb = new Complex128( 0.0, 0.0 );

var out = zrotg( za, zb );
// returns <Float64Array>[ 4.0, 3.0, 1.0, 0.0, 0.0 ]
```

The function has the following parameters:

- **za**: rotational elimination parameter (complex number).
- **zb**: rotational elimination parameter (complex number).

The function returns an array with the following elements:

- **r**: real part of the rotated vector (real number).
- **r_imag**: imaginary part of the rotated vector (real number).
- **c**: cosine of the rotation angle (real number).
- **s**: real part of the sine of the rotation angle (real number).
- **s_imag**: imaginary part of the sine of the rotation angle (real number).

#### zrotg.assign( za, zb, out, stride, offset )

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

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

var za = new Complex128( 4.0, 3.0 );
var zb = new Complex128( 0.0, 0.0 );

var out = new Float64Array( 5 );

var y = zrotg.assign( za, zb, out, 1, 0 );
// returns <Float64Array>[ 4.0, 3.0, 1.0, 0.0, 0.0 ]

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

</section>

<!-- /.usage -->

<section class="notes">

## Notes

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

</section>

<!-- /.notes -->

<section class="examples">

## Examples

```javascript
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var zrotg = require( '@stdlib/blas/base/zrotg' );

var out;
var i;

function rand() {
return new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
}

for ( i = 0; i < 100; i++ ) {
out = zrotg( rand(), rand() );
console.log( out );
}
```

</section>

<!-- /.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/zrotg.h"
```

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

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

```c
#include "stdlib/complex/float64/ctor.h"

double Out[ 5 ];
const stdlib_complex128_t a = stdlib_complex128( 4.0, 3.0 );
const stdlib_complex128_t b = stdlib_complex128( 0.0, 0.0 );

c_zrotg( a, b, Out, 1 );
// Out => [ 4.0, 3.0, 1.0, 0.0, 0.0 ]
```

The function accepts the following arguments:

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

```c
void c_zrotg( const stdlib_complex128_t a, const stdlib_complex128_t b, double *Out, const CBLAS_INT strideOut );
```

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

Constructs a Givens plane rotation provided two double-precision complex floating-point values `a` and `b` using alternative indexing semantics.

```c
#include "stdlib/complex/float64/ctor.h"

double Out[ 5 ];
const stdlib_complex128_t a = stdlib_complex128( 4.0, 3.0 );
const stdlib_complex128_t b = stdlib_complex128( 0.0, 0.0 );

c_zrotg_assign( a, b, Out, 1, 0 );
// Out => [ 4.0, 3.0, 1.0, 0.0, 0.0 ]
```

The function accepts the following arguments:

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

```c
void c_zrotg_assign( const stdlib_complex128_t a, const stdlib_complex128_t b, double *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/zrotg.h"
#include "stdlib/complex/float64/ctor.h"
#include <stdio.h>

int main( void ) {
// Specify rotational elimination parameters:
const stdlib_complex128_t a = stdlib_complex128( 4.0, 3.0 );
const stdlib_complex128_t b = stdlib_complex128( 0.0, 0.0 );
int i;

// Create output array:
double Out[ 5 ];

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

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

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

// Apply plane rotation using alternative indexing semantics:
c_zrotg_assign( a, b, Out, strideOut, 0 );

// Print the result:
for ( i = 0; i < 5; i++ ) {
printf( "Out[%d] = %lf\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">

</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

[blas-zrotg]: https://www.netlib.org/lapack/explore-html/d7/dc5/group__rotg_ga97ce56a6808661b36ab62269393ac10e.html

</section>

<!-- /.links -->
103 changes: 103 additions & 0 deletions lib/node_modules/@stdlib/blas/base/zrotg/benchmark/benchmark.assign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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/base/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var zrotg = require( './../lib/assign.js' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) { // eslint-disable-line no-unused-vars
var za;
var zb;
var z;

za = new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
zb = new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
z = new Float64Array( 5 );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
zrotg( za, zb, z, 1, 0 );
if ( isnan( z[ i%4 ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( z[ i%4 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':len='+len, f );

Check warning on line 99 in lib/node_modules/@stdlib/blas/base/zrotg/benchmark/benchmark.assign.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use `@stdlib/string/format` instead of string concatenation for benchmark descriptions
}
}

main();
Loading