Return the first index of a specified search element in a single-precision floating-point strided array.
var sindexOf = require( '@stdlib/blas/ext/base/sindex-of' );Returns the first index of a specified search element in a single-precision floating-point strided array.
var Float32Array = require( '@stdlib/array/float32' );
var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ] );
var idx = sindexOf( x.length, 3.0, x, 1 );
// returns 2The function has the following parameters:
- N: number of indexed elements.
- searchElement: search element.
- x: input
Float32Array. - strideX: stride length.
If the function is unable to find a search element, the function returns -1.
var Float32Array = require( '@stdlib/array/float32' );
var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ] );
var idx = sindexOf( x.length, 8.0, x, 1 );
// returns -1The N and stride parameters determine which elements in the strided array are accessed at runtime. For example, to search every other element:
var Float32Array = require( '@stdlib/array/float32' );
var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ] );
var idx = sindexOf( 4, -1.0, x, 2 );
// returns 3Note that indexing is relative to the first index. To introduce an offset, use typed array views.
var Float32Array = require( '@stdlib/array/float32' );
// Initial array...
var x0 = new Float32Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
// Create an offset view...
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
// Find index...
var idx = sindexOf( 3, -6.0, x1, 2 );
// returns 2Returns the first index of a specified search element in a single-precision floating-point strided array using alternative indexing semantics.
var Float32Array = require( '@stdlib/array/float32' );
var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ] );
var idx = sindexOf.ndarray( x.length, 3.0, x, 1, 0 );
// returns 2The function has the following additional parameters:
- offsetX: starting index.
While typed array views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of the strided array
var Float32Array = require( '@stdlib/array/float32' );
var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ] );
var idx = sindexOf.ndarray( 3, 3.0, x, 1, x.length-3 );
// returns 2- When searching for a search element, the function checks for equality using the strict equality operator
===. As a consequence,NaNvalues are considered distinct, and-0and+0are considered the same.
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var sindexOf = require( '@stdlib/blas/ext/base/sindex-of' );
var x = discreteUniform( 10, -100, 100, {
'dtype': 'float32'
});
console.log( x );
var idx = sindexOf( x.length, 80.0, x, 1 );
console.log( idx );#include "stdlib/blas/ext/base/sindex_of.h"Returns the first index of a specified search element in a single-precision floating-point strided array.
float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
int idx = stdlib_strided_sindex_of( 4, 3.0f, x, 1 );
// returns 2The function accepts the following arguments:
- N:
[in] CBLAS_INTnumber of indexed elements. - searchElement:
[in] floatsearch element. - X:
[in] float*input array. - strideX:
[in] CBLAS_INTstride length.
CBLAS_INT N stdlib_strided_sindex_of( const CBLAS_INT N, const float searchElement, const float *X, const CBLAS_INT strideX );Returns the first index of a specified search element in a single-precision floating-point strided array using alternative indexing semantics.
float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
int idx = stdlib_strided_sindex_of_ndarray( 4, 3.0f, x, 1, 0 );
// returns 2The function accepts the following arguments:
- N:
[in] CBLAS_INTnumber of indexed elements. - searchElement:
[in] floatsearch element. - X:
[in] float*input array. - strideX:
[in] CBLAS_INTstride length. - offsetX:
[in] CBLAS_INTstarting index.
CBLAS_INT stdlib_strided_sindex_of_ndarray( const CBLAS_INT N, const float searchElement, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );#include "stdlib/blas/ext/base/sindex_of.h"
#include <stdio.h>
int main( void ) {
// Create a strided array:
float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f };
// Specify the number of indexed elements:
const int N = 8;
// Specify a stride:
const int strideX = 1;
// Perform a search:
int idx = stdlib_strided_sindex_of( N, 5.0f, x, strideX );
// Print the result:
printf( "index value: %d\n", idx );
}