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

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

-->

# izamax

> Find the index of the first element having maximum |Re(.)| + |Im(.)|.

<section class="usage">

## Usage

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

#### izamax( N, x, strideX )

Finds the index of the first element having maximum |Re(.)| + |Im(.)|.

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );

var idx = izamax( x.length, x, 1 );
// returns 1
```

The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Complex128Array`][@stdlib/array/complex128].
- **strideX**: index increment for `x`.

The `N` and `strideX` parameters determine which elements in `x` are accessed at runtime. For example, to traverse every other value,

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );

var idx = izamax( 2, x, 2 );
// returns 1
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

// Initial array:
var x0 = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );

// Create an offset view:
var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

// Find index of element having maximum |Re(.)| + |Im(.)|:
var idx = izamax( 2, x1, 1 );
// returns 1
```

#### izamax.ndarray( N, x, strideX, offsetX )

Finds the index of the first element having maximum |Re(.)| + |Im(.)| using alternative indexing semantics.

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );

var idx = izamax.ndarray( x.length, x, 1, 0 );
// returns 1
```

The function has the following additional parameters:

- **offsetX**: starting index.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the `offsetX` parameter supports indexing semantics based on a starting index. For example, to start from the second index,

```javascript
var Complex128Array = require( '@stdlib/array/complex128' );

var x = new Complex128Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 ] );

var idx = izamax.ndarray( 3, x, 1, 1 );
// returns 2
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- If `N < 1`, both functions return `-1`.
- `izamax()` corresponds to the [BLAS][blas] level 1 function [`izamax`][izamax].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var izamax = require( '@stdlib/blas/base/izamax' );

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

// Generate random input array:
var x = filledarrayBy( 10, 'complex128', rand );
console.log( x.toString() );

var idx = izamax( x.length, x, 1 );
console.log( idx );
```

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

#### c_izamax( N, \*X, strideX )

Finds the index of the first element having maximum |Re(.)| + |Im(.)|.

```c
const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0, 2.0 };

CBLAS_INT idx = c_izamax( 3, (void *)x, 1 );
// returns 1
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] void*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.

```c
CBLAS_INT c_izamax( const CBLAS_INT N, const void *X, const CBLAS_INT strideX );
```

#### c_izamax_ndarray( N, \*X, strideX, offsetX )

Finds the index of the first element having maximum |Re(.)| + |Im(.)| using alternative indexing semantics.

```c
const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0, 2.0 };

CBLAS_INT idx = c_izamax_ndarray( 3, (void *)x, 1, 0 );
// returns 1
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] void*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.

```c
CBLAS_INT c_izamax_ndarray( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
```

</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/izamax.h"
#include <stdio.h>

int main( void ) {
// Create a strided array:
const double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 };

// Specify the number of elements:
const int N = 4;

// Specify stride:
const int strideX = 1;

// Compute the index of the maximum value:
CBLAS_INT idx = c_izamax( N, (void *)x, strideX );

// Print the result:
printf( "index value: %d\n", idx );

// Compute the index of the maximum value:
idx = c_izamax_ndarray( N, (void *)x, -strideX, N-1 );

// Print the result:
printf( "index value: %d\n", idx );
}
```

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

[izamax]: https://netlib.org/lapack/explore-html/d0/da5/izamax_8f.html

[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

</section>

<!-- /.links -->
Loading
Loading