Skip to content

Latest commit

 

History

History
295 lines (182 loc) · 7.03 KB

File metadata and controls

295 lines (182 loc) · 7.03 KB

izamax

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

Usage

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

izamax( N, x, strideX )

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

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.
  • 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,

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

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.

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

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

Notes

  • If N < 1, both functions return -1.
  • izamax() corresponds to the BLAS level 1 function izamax.

Examples

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 );

C APIs

Usage

#include "stdlib/blas/base/izamax.h"

c_izamax( N, *X, strideX )

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

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

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.
CBLAS_INT c_izamax_ndarray( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );

Examples

#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 );
}