Skip to content

Commit 74473d6

Browse files
committed
feat: add blas/ext/base/ndarray/zindex-of
--- 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: passed - 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 f0ed784 commit 74473d6

10 files changed

Lines changed: 929 additions & 0 deletions

File tree

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# zindexOf
22+
23+
> Return the first index of a search element in a one-dimensional double-precision complex floating-point ndarray.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var zindexOf = require( '@stdlib/blas/ext/base/ndarray/zindex-of' );
37+
```
38+
39+
#### zindexOf( arrays )
40+
41+
Returns the first index of a specified search element in a one-dimensional double-precision complex floating-point ndarray.
42+
43+
```javascript
44+
var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );
45+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
46+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
47+
48+
var x = new Complex128Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
49+
50+
var searchElement = scalar2ndarray( new Complex128( 3.0, 4.0 ), {
51+
'dtype': 'complex128'
52+
});
53+
54+
var fromIndex = scalar2ndarray( 0, {
55+
'dtype': 'generic'
56+
});
57+
58+
var idx = zindexOf( [ x, searchElement, fromIndex ] );
59+
// returns 1
60+
```
61+
62+
The function has the following parameters:
63+
64+
- **arrays**: array-like object containing the following ndarrays:
65+
66+
- a one-dimensional input ndarray.
67+
- a zero-dimensional ndarray containing the search element.
68+
- a zero-dimensional ndarray containing the index from which to begin searching.
69+
70+
If the function is unable to find a search element, the function returns `-1`.
71+
72+
```javascript
73+
var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );
74+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
75+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
76+
77+
var x = new Complex128Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
78+
79+
var searchElement = scalar2ndarray( new Complex128( 10.0, 0.0 ), {
80+
'dtype': 'complex128'
81+
});
82+
83+
var fromIndex = scalar2ndarray( 0, {
84+
'dtype': 'generic'
85+
});
86+
87+
var idx = zindexOf( [ x, searchElement, fromIndex ] );
88+
// returns -1
89+
```
90+
91+
</section>
92+
93+
<!-- /.usage -->
94+
95+
<section class="notes">
96+
97+
## Notes
98+
99+
- If a specified starting search index is negative, the function resolves the starting search index by counting backward from the last element (where `-1` refers to the last element).
100+
101+
</section>
102+
103+
<!-- /.notes -->
104+
105+
<section class="examples">
106+
107+
## Examples
108+
109+
<!-- eslint no-undef: "error" -->
110+
111+
```javascript
112+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
113+
var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );
114+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
115+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
116+
var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' );
117+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
118+
var zindexOf = require( '@stdlib/blas/ext/base/ndarray/zindex-of' );
119+
120+
var opts = {
121+
'dtype': 'float64'
122+
};
123+
124+
var x = new Complex128Vector( discreteUniform( 20, -50, 50, opts ) );
125+
console.log( ndarray2array( x ) );
126+
127+
var searchElement = scalar2ndarray( new Complex128( 2.0, 3.0 ), {
128+
'dtype': 'complex128'
129+
});
130+
console.log( 'Search Element:', ndarraylike2scalar( searchElement ) );
131+
132+
var fromIndex = scalar2ndarray( 0, {
133+
'dtype': 'generic'
134+
});
135+
console.log( 'From Index:', ndarraylike2scalar( fromIndex ) );
136+
137+
var idx = zindexOf( [ x, searchElement, fromIndex ] );
138+
console.log( idx );
139+
```
140+
141+
</section>
142+
143+
<!-- /.examples -->
144+
145+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
146+
147+
<section class="related">
148+
149+
</section>
150+
151+
<!-- /.related -->
152+
153+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
154+
155+
<section class="links">
156+
157+
</section>
158+
159+
<!-- /.links -->
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );
28+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
29+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
30+
var format = require( '@stdlib/string/format' );
31+
var pkg = require( './../package.json' ).name;
32+
var zindexOf = require( './../lib' );
33+
34+
35+
// FUNCTIONS //
36+
37+
/**
38+
* Creates a benchmark function.
39+
*
40+
* @private
41+
* @param {PositiveInteger} len - array length
42+
* @returns {Function} benchmark function
43+
*/
44+
function createBenchmark( len ) {
45+
var searchElement;
46+
var fromIndex;
47+
var xbuf;
48+
var x;
49+
50+
xbuf = uniform( len*2, 0.0, 100.0, {
51+
'dtype': 'float64'
52+
});
53+
x = new Complex128Vector( xbuf.buffer );
54+
searchElement = scalar2ndarray( new Complex128( -10.0, -10.0 ), {
55+
'dtype': 'complex128'
56+
});
57+
fromIndex = scalar2ndarray( 0, {
58+
'dtype': 'generic'
59+
});
60+
return benchmark;
61+
62+
/**
63+
* Benchmark function.
64+
*
65+
* @private
66+
* @param {Benchmark} b - benchmark instance
67+
*/
68+
function benchmark( b ) {
69+
var out;
70+
var i;
71+
72+
b.tic();
73+
for ( i = 0; i < b.iterations; i++ ) {
74+
out = zindexOf( [ x, searchElement, fromIndex ] );
75+
if ( out !== out ) {
76+
b.fail( 'should return an integer' );
77+
}
78+
}
79+
b.toc();
80+
if ( !isInteger( out ) ) {
81+
b.fail( 'should return an integer' );
82+
}
83+
b.pass( 'benchmark finished' );
84+
b.end();
85+
}
86+
}
87+
88+
89+
// MAIN //
90+
91+
/**
92+
* Main execution sequence.
93+
*
94+
* @private
95+
*/
96+
function main() {
97+
var len;
98+
var min;
99+
var max;
100+
var f;
101+
var i;
102+
103+
min = 1; // 10^min
104+
max = 6; // 10^max
105+
106+
for ( i = min; i <= max; i++ ) {
107+
len = pow( 10, i );
108+
f = createBenchmark( len );
109+
bench( format( '%s:len=%d', pkg, len ), f );
110+
}
111+
}
112+
113+
main();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
{{alias}}( arrays )
3+
Returns the first index of a search element in a one-dimensional double-
4+
precision complex floating-point ndarray.
5+
6+
If a specified starting search index is negative, the function resolves the
7+
starting search index by counting backward from the last element (where `-1`
8+
refers to the last element).
9+
10+
Parameters
11+
----------
12+
arrays: ArrayLikeObject<ndarray>
13+
Array-like object containing the following ndarrays:
14+
15+
- a one-dimensional input ndarray.
16+
- a zero-dimensional ndarray containing the search element.
17+
- a zero-dimensional ndarray containing the index from which to begin
18+
searching.
19+
20+
Returns
21+
-------
22+
out: integer
23+
Index.
24+
25+
Examples
26+
--------
27+
> var x = new {{alias:@stdlib/ndarray/vector/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] );
28+
> var c = new {{alias:@stdlib/complex/float64/ctor}}( 3.0, 4.0 );
29+
> var v = {{alias:@stdlib/ndarray/from-scalar}}( c, { 'dtype': 'complex128' } );
30+
> var i = {{alias:@stdlib/ndarray/from-scalar}}( 0, { 'dtype': 'generic' } );
31+
> {{alias}}( [ x, v, i ] )
32+
1
33+
34+
See Also
35+
--------
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { complex128ndarray, typedndarray } from '@stdlib/types/ndarray';
24+
import { Complex128 } from '@stdlib/types/complex';
25+
26+
/**
27+
* Returns the first index of a search element in a one-dimensional double-precision complex floating-point ndarray.
28+
*
29+
* ## Notes
30+
*
31+
* - The function expects the following ndarrays:
32+
*
33+
* - a one-dimensional input ndarray.
34+
* - a zero-dimensional ndarray containing the search element.
35+
* - a zero-dimensional ndarray containing the index from which to begin searching.
36+
*
37+
* @param arrays - array-like object containing ndarrays
38+
* @returns index
39+
*
40+
* @example
41+
* var Complex128Vector = require( '@stdlib/ndarray/vector/complex128' );
42+
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
43+
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
44+
*
45+
* var x = new Complex128Vector( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
46+
*
47+
* var searchElement = scalar2ndarray( new Complex128( 3.0, 4.0 ), {
48+
* 'dtype': 'complex128'
49+
* });
50+
*
51+
* var fromIndex = scalar2ndarray( 0, {
52+
* 'dtype': 'generic'
53+
* });
54+
*
55+
* var v = zindexOf( [ x, searchElement, fromIndex ] );
56+
* // returns 1
57+
*/
58+
declare function zindexOf( arrays: [ complex128ndarray, typedndarray<Complex128>, typedndarray<number> ] ): number;
59+
60+
61+
// EXPORTS //
62+
63+
export = zindexOf;

0 commit comments

Comments
 (0)