Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 15 additions & 15 deletions lib/node_modules/@stdlib/blas/ext/base/sindex-of/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

# sindexOf

> Return the index of a specified search element in a single-precision floating-point strided array.
> Return the first index of a specified search element in a single-precision floating-point strided array.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

Expand All @@ -42,7 +42,7 @@ var sindexOf = require( '@stdlib/blas/ext/base/sindex-of' );

#### sindexOf( N, searchElement, x, strideX )

Returns the index of a specified search element in a single-precision floating-point strided array.
Returns the first index of a specified search element in a single-precision floating-point strided array.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
Expand Down Expand Up @@ -100,7 +100,7 @@ var idx = sindexOf( 3, -6.0, x1, 2 );

#### sindexOf.ndarray( N, searchElement, x, strideX, offsetX )

Returns the index of a specified search element in a single-precision floating-point strided array using alternative indexing semantics.
Returns the first index of a specified search element in a single-precision floating-point strided array using alternative indexing semantics.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
Expand Down Expand Up @@ -190,17 +190,17 @@ console.log( idx );
### Usage

```c
#include "stdlib/blas/ext/base/sindexof.h"
#include "stdlib/blas/ext/base/sindex_of.h"
```

#### stdlib_strided_sindexOf( N, searchElement, \*X, strideX )
#### stdlib_strided_sindex_of( N, searchElement, \*X, strideX )

Returns the index of a specified search element in a single-precision floating-point strided array.
Returns the first index of a specified search element in a single-precision floating-point strided array.

```c
float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };

int idx = stdlib_strided_sindexOf( 4, 3.0f, x, 1 );
int idx = stdlib_strided_sindex_of( 4, 3.0f, x, 1 );
// returns 2
```

Expand All @@ -212,17 +212,17 @@ The function accepts the following arguments:
- **strideX**: `[in] CBLAS_INT` stride length.

```c
CBLAS_INT N stdlib_strided_sindexOf( const CBLAS_INT N, const float searchElement, float *X, const CBLAS_INT strideX );
CBLAS_INT N stdlib_strided_sindex_of( const CBLAS_INT N, const float searchElement, float *X, const CBLAS_INT strideX );
```

#### stdlib_strided_sindexOf_ndarray( N, searchElement, \*X, strideX, offsetX )
#### stdlib_strided_sindex_of_ndarray( N, searchElement, \*X, strideX, offsetX )

Returns the index of a specified search element in a single-precision floating-point strided array using alternative indexing semantics.
Returns the first index of a specified search element in a single-precision floating-point strided array using alternative indexing semantics.

```c
float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };

int idx = stdlib_strided_sindexOf( 4, 3.0f, x, 1, 0 );
int idx = stdlib_strided_sindex_of( 4, 3.0f, x, 1, 0 );
// returns 2
```

Expand All @@ -235,7 +235,7 @@ The function accepts the following arguments:
- **offsetX**: `[in] CBLAS_INT` starting index.

```c
CBLAS_INT stdlib_strided_sindexOf_ndarray( const CBLAS_INT N, const float searchElement, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
CBLAS_INT stdlib_strided_sindex_of_ndarray( const CBLAS_INT N, const float searchElement, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
```

</section>
Expand All @@ -257,7 +257,7 @@ CBLAS_INT stdlib_strided_sindexOf_ndarray( const CBLAS_INT N, const float search
### Examples

```c
#include "stdlib/blas/ext/base/sindexof.h"
#include "stdlib/blas/ext/base/sindex_of.h"
#include <stdio.h>

int main( void ) {
Expand All @@ -270,8 +270,8 @@ int main( void ) {
// Specify a stride:
const int strideX = 1;

// Fill the array:
int idx = stdlib_strided_sindexOf( N, 5.0f, x, strideX );
// Perform a search:
int idx = stdlib_strided_sindex_of( N, 5.0f, x, strideX );

// Print the result:
printf( "index value: %d\n", idx );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var pow = require( '@stdlib/math/base/special/pow' );
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var oneTo = require( '@stdlib/array/one-to' );
var pkg = require( './../package.json' ).name;
var sindexOf = require( './../lib' );
var sindexOf = require( './../lib/sindex_of.js' );


// FUNCTIONS //
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var pow = require( '@stdlib/math/base/special/pow' );
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var oneTo = require( '@stdlib/array/one-to' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var sindexOf = tryRequire( resolve( __dirname, './../lib/sindex_of.native.js' ) );
var opts = {
'skip': ( sindexOf instanceof Error )
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x = oneTo( len, 'float32' );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = sindexOf( x.length, len+1, x, 1 );
if ( out !== out ) {
b.fail( 'should return an integer' );
}
}
b.toc();
if ( !isInteger( out ) ) {
b.fail( 'should return an integer' );
}
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+'::native:len='+len, opts, f );
}
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function main() {
len = pow( 10, i );

f = createBenchmark( len );
bench( pkg+':len='+len, f );
bench( pkg+':ndarray:len='+len, f );
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var pow = require( '@stdlib/math/base/special/pow' );
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var oneTo = require( '@stdlib/array/one-to' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var sindexOf = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( sindexOf instanceof Error )
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x = oneTo( len, 'float32' );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = sindexOf( x.length, len+1, x, 1, 0 );
if ( out !== out ) {
b.fail( 'should return an integer' );
}
}
b.toc();
if ( !isInteger( out ) ) {
b.fail( 'should return an integer' );
}
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+'::native:ndarray:len='+len, opts, f );
}
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

#include "stdlib/blas/ext/base/sindexof.h"
#include "stdlib/blas/ext/base/sindex_of.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
Expand Down Expand Up @@ -108,7 +108,7 @@ static double benchmark1( int iterations, int len ) {
t = tic();
for ( i = 0; i < iterations; i++ ) {
// cppcheck-suppress uninitvar
idx = stdlib_strided_sindexOf( len, 20000.0f, x, 1 );
idx = stdlib_strided_sindex_of( len, 20000.0f, x, 1 );
if ( idx < -2 ) {
printf( "unexpected result\n" );
break;
Expand Down Expand Up @@ -142,7 +142,7 @@ static double benchmark2( int iterations, int len ) {
t = tic();
for ( i = 0; i < iterations; i++ ) {
// cppcheck-suppress uninitvar
idx = stdlib_strided_sindexOf_ndarray( len, 20000.0f, x, 1, 0 );
idx = stdlib_strided_sindex_of_ndarray( len, 20000.0f, x, 1, 0 );
if ( idx < -2 ) {
printf( "unexpected result\n" );
break;
Expand Down
Loading