Skip to content

Commit 933e03c

Browse files
committed
fix: apply suggestions from code review
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent ee87e2b commit 933e03c

File tree

13 files changed

+595
-208
lines changed

13 files changed

+595
-208
lines changed

lib/node_modules/@stdlib/blas/ext/base/sindex-of/README.md

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ limitations under the License.
4040
var sindexOf = require( '@stdlib/blas/ext/base/sindex-of' );
4141
```
4242

43-
#### sindexOf( N, searchElement, x, strideX\[, offsetX ] )
43+
#### sindexOf( N, searchElement, x, strideX )
4444

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

@@ -59,39 +59,71 @@ The function has the following parameters:
5959
- **searchElement**: element to search the index of.
6060
- **x**: input [`Float32Array`][@stdlib/array/float32].
6161
- **strideX**: index increment.
62-
- **offsetX**: starting index (_optional_).
6362

64-
To begin searching from specific index, provide an `offset` parameter:
63+
If the function is unable to find an element which equals a provided search element, the function returns `-1`.
6564

6665
```javascript
6766
var Float32Array = require( '@stdlib/array/float32' );
6867

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

71-
var idx = sindexOf( x.length, 3.0, x, 1, 5 );
72-
// returns 7
70+
var idx = sindexOf( x.length, 8.0, x, 1 );
71+
// returns -1
72+
```
73+
74+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to search every other element:
75+
76+
```javascript
77+
var Float32Array = require( '@stdlib/array/float32' );
78+
79+
var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, 3.0 ] );
80+
81+
var idx = sindexOf( 4, -1.0, x, 2 );
82+
// returns 6
83+
```
84+
85+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
86+
87+
```javascript
88+
var Float32Array = require( '@stdlib/array/float32' );
89+
90+
// Initial array...
91+
var x0 = new Float32Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
92+
93+
// Create an offset view...
94+
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
95+
96+
// Find index...
97+
var idx = sindexOf( 3, -6.0, x1, 2 );
98+
// returns 4
7399
```
74100

75-
If both `offset` and `stride` are less than zero, the search begins from the last array element and proceeds towards the first element.
101+
#### sindexOf.ndarray( N, searchElement, x, strideX, offsetX )
102+
103+
Returns the index of a specified search element in a single-precision floating-point strided array using alternative indexing semantics.
76104

77105
```javascript
78106
var Float32Array = require( '@stdlib/array/float32' );
79107

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

82-
var idx = sindexOf( x.length, 3.0, x, -1, -2 );
110+
var idx = sindexOf.ndarray( x.length, 3.0, x, 1, 0 );
83111
// returns 2
84112
```
85113

86-
If the function is unable to find an element which equals a provided search element, the function returns `-1`.
114+
The function has the following additional parameters:
115+
116+
- **offsetX**: starting index.
117+
118+
While [`typed array`][mdn-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
87119

88120
```javascript
89121
var Float32Array = require( '@stdlib/array/float32' );
90122

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

93-
var idx = sindexOf( x.length, 8.0, x, 1 );
94-
// returns -1
125+
var idx = sindexOf.ndarray( 3, 3.0, x, 1, x.length-3 );
126+
// returns 7
95127
```
96128

97129
</section>
@@ -125,17 +157,9 @@ var sindexOf = require( '@stdlib/blas/ext/base/sindex-of' );
125157
var x = discreteUniform( 10, -100, 100, {
126158
'dtype': 'float32'
127159
});
160+
console.log( x );
128161

129-
var idx = sindexOf( x.length, 2.0, x, 1 );
130-
console.log( idx );
131-
132-
idx = sindexOf( x.length, 12.0, x, 2, 5 );
133-
console.log( idx );
134-
135-
idx = sindexOf( x.length, -57.0, x, 1, -2 );
136-
console.log( idx );
137-
138-
idx = sindexOf( x.length, 92.0, x, -1, -2 );
162+
var idx = sindexOf( x.length, 80.0, x, 1 );
139163
console.log( idx );
140164
```
141165

@@ -165,6 +189,8 @@ console.log( idx );
165189

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

192+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
193+
168194
</section>
169195

170196
<!-- /.links -->

lib/node_modules/@stdlib/blas/ext/base/sindex-of/benchmark/benchmark.length.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function createBenchmark( len ) {
5353

5454
b.tic();
5555
for ( i = 0; i < b.iterations; i++ ) {
56-
out = sindexOf( x.length, 2.0, x, 1, 0 );
56+
out = sindexOf( x.length, 2.0, x, 1 );
5757
if ( out !== out ) {
5858
b.fail( 'should return an integer' );
5959
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
26+
var oneTo = require( '@stdlib/array/one-to' );
27+
var pkg = require( './../package.json' ).name;
28+
var sindexOf = require( './../lib/ndarray.js' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
var x = oneTo( len, 'float32' );
42+
return benchmark;
43+
44+
/**
45+
* Benchmark function.
46+
*
47+
* @private
48+
* @param {Benchmark} b - benchmark instance
49+
*/
50+
function benchmark( b ) {
51+
var out;
52+
var i;
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
out = sindexOf( x.length, 2.0, x, 1, 0 );
57+
if ( out !== out ) {
58+
b.fail( 'should return an integer' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isInteger( out ) ) {
63+
b.fail( 'should return an integer' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
}
68+
}
69+
70+
71+
// MAIN //
72+
73+
/**
74+
* Main execution sequence.
75+
*
76+
* @private
77+
*/
78+
function main() {
79+
var len;
80+
var min;
81+
var max;
82+
var f;
83+
var i;
84+
85+
min = 1; // 10^min
86+
max = 6; // 10^max
87+
88+
for ( i = min; i <= max; i++ ) {
89+
len = pow( 10, i );
90+
91+
f = createBenchmark( len );
92+
bench( pkg+':dtype=float32,len='+len, f );
93+
}
94+
}
95+
96+
main();

lib/node_modules/@stdlib/blas/ext/base/sindex-of/docs/repl.txt

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11

2-
{{alias}}( N, searchElement, x, strideX[, offsetX ] )
2+
{{alias}}( N, searchElement, x, strideX )
33
Returns the index of a specified search element in a single-precision
44
floating-point strided array.
55

6-
If unable to find an element which equals a provided search element, the
7-
function returns -1.
6+
The `N` and stride parameters determine which elements in the strided array
7+
are accessed at runtime.
8+
9+
Indexing is relative to the first index. To introduce an offset, use a typed
10+
array view.
11+
12+
if `N <= 0`, the function returns `-1`.
813

914
Parameters
1015
----------
@@ -20,11 +25,6 @@
2025
strideX: integer
2126
Index increment.
2227

23-
offsetX: integer (optional)
24-
Starting index (inclusive). If less than zero, the starting index is
25-
resolved relative to the last array element, with the last array element
26-
corresponding to `offsetX = -1`.
27-
2828
Returns
2929
-------
3030
out: integer
@@ -36,5 +36,42 @@
3636
> var out = {{alias}}( x.length, 1.0, x, 1 )
3737
1
3838

39+
40+
{{alias}}( N, searchElement, x, strideX, offsetX )
41+
Returns the index of a specified search element in a single-precision
42+
floating-point strided array using alternative indexing semantics.
43+
44+
While typed array views mandate a view offset based on the underlying
45+
buffer, the offset parameter supports indexing semantics based on a
46+
starting index.
47+
48+
Parameters
49+
----------
50+
N: integer
51+
Number of indexed elements.
52+
53+
searchElement: number
54+
Search element.
55+
56+
x: Float32Array
57+
Input array.
58+
59+
strideX: integer
60+
Index increment.
61+
62+
offsetX: integer
63+
Starting index.
64+
65+
Returns
66+
-------
67+
out: integer
68+
Index or -1.
69+
70+
Examples
71+
--------
72+
> var x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] );
73+
> var out = {{alias}}.ndarray( x.length, 1.0, x, 1, 0 )
74+
1
75+
3976
See Also
4077
--------

lib/node_modules/@stdlib/blas/ext/base/sindex-of/docs/types/index.d.ts

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,55 @@
1919
// TypeScript Version: 4.1
2020

2121
/**
22-
* Returns the index of a specified search element in a single-precision floating-point strided array.
23-
*
24-
* ## Notes
22+
* Interface describing `sindexOf`
2523
*
26-
* - If unable to find an element which equals a provided search element, the function returns `-1`.
27-
* - If `offsetX` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `offsetX = -1`.
24+
*/
25+
interface Routine {
26+
/**
27+
* Returns the index of a specified search element in a single-precision floating-point strided array.
28+
*
29+
* @param N - number of indexed elements
30+
* @param searchElement - search element
31+
* @param x - input array
32+
* @param strideX - stride length
33+
* @returns index
34+
*
35+
* @example
36+
* var Float32Array = require( '@stdlib/array/float32' );
37+
* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
38+
*
39+
* var idx = sindexOf( x.length, 2.0, x, 1 );
40+
* // returns 1
41+
*/
42+
( N: number, searchElement: number, x: Float32Array, strideX: number ): number;
43+
44+
/**
45+
* Returns the index of a specified search element in a single-precision floating-point strided array using alternative indexing semantics.
46+
*
47+
* @param N - number of indexed elements
48+
* @param searchElement - search element
49+
* @param x - input array
50+
* @param strideX - stride length
51+
* @param offsetX - starting index
52+
* @returns index
53+
*
54+
* @example
55+
* var Float32Array = require( '@stdlib/array/float32' );
56+
* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
57+
*
58+
* var idx = sindexOf.ndarray( x.length, 2.0, x, 1, 0 );
59+
* // returns 1
60+
*/
61+
ndarray( N: number, searchElement: number, x: Float32Array, strideX: number, offsetX: number ): number;
62+
}
63+
64+
/**
65+
* Returns the index of a specified search element in a single-precision floating-point strided array.
2866
*
2967
* @param N - number of indexed elements
3068
* @param searchElement - search element
3169
* @param x - input array
3270
* @param strideX - stride length
33-
* @param offsetX - starting index
3471
* @returns index
3572
*
3673
* @example
@@ -39,8 +76,15 @@
3976
*
4077
* var idx = sindexOf( x.length, 2.0, x, 1 );
4178
* // returns 1
79+
*
80+
* @example
81+
* var Float32Array = require( '@stdlib/array/float32' );
82+
* var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
83+
*
84+
* var idx = sindexOf.ndarray( x.length, 2.0, x, 1, 0 );
85+
* // returns 1
4286
*/
43-
declare function sindexOf( N: number, searchElement: number, x: Float32Array, strideX: number, offsetX?: number ): number;
87+
declare var sindexOf: Routine;
4488

4589

4690
// EXPORTS //

0 commit comments

Comments
 (0)