Skip to content

Commit 558b4e3

Browse files
authored
Merge branch 'stdlib-js:develop' into develop
2 parents 3487d29 + 74d2527 commit 558b4e3

File tree

136 files changed

+4918
-2180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+4918
-2180
lines changed

lib/node_modules/@stdlib/_tools/eslint/rules/doctest/test/fixtures/invalid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ test = {
302302
].join( '\n' ),
303303
'errors': [
304304
{
305-
'message': 'Encountered an error while running code: `invalid argument. Minimum support `a` must be less than maximum support `b`. Value: `[13,9]`.`. Did you mean to include a `// throws <RangeError>` annotation instead of `// returns <RangeError>`?',
305+
'message': 'Encountered an error while running code: `invalid argument. Minimum support must be less than maximum support. Value: `[13.000000, 9.000000]`.`. Did you mean to include a `// throws <RangeError>` annotation instead of `// returns <RangeError>`?',
306306
'type': null
307307
},
308308
{
309-
'message': 'Encountered an error while running code: `invalid argument. Minimum support `a` must be less than maximum support `b`. Value: `[3,1]`.`. Did you mean to include a `// throws <RangeError>` annotation instead of `// returns <RangeError>`?',
309+
'message': 'Encountered an error while running code: `invalid argument. Minimum support must be less than maximum support. Value: `[3.000000, 1.000000]`.`. Did you mean to include a `// throws <RangeError>` annotation instead of `// returns <RangeError>`?',
310310
'type': null
311311
}
312312
],

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-doctest/test/fixtures/invalid.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,49 @@ test = {
289289
'message': 'Displayed return value is `null`, but expected `NaN` instead',
290290
'type': null
291291
}
292-
]
292+
],
293+
'output': [
294+
'\'use strict\';',
295+
'',
296+
'// MODULES //',
297+
'',
298+
'var asin = require( \'@stdlib/math/base/special/asin\' );',
299+
'var sqrt = require( \'@stdlib/math/base/special/sqrt\' );',
300+
'',
301+
'',
302+
'// MAIN //',
303+
'',
304+
'/**',
305+
'* Computes the inverse half-value versed sine.',
306+
'*',
307+
'* @param {number} x - input value',
308+
'* @returns {number} inverse half-value versed sine',
309+
'*',
310+
'* @example',
311+
'* var v = ahaversin( 0.0 );',
312+
'* // returns 0.0',
313+
'*',
314+
'* @example',
315+
'* var v = ahaversin( 1.0 );',
316+
'* // returns ~3.142',
317+
'*',
318+
'* @example',
319+
'* var v = ahaversin( 0.5 );',
320+
'* // returns ~1.5708',
321+
'*',
322+
'* @example',
323+
'* var v = ahaversin( NaN );',
324+
'* // returns null',
325+
'*/',
326+
'function ahaversin( x ) {',
327+
' return 2.0 * asin( sqrt( x ) );',
328+
'}',
329+
'',
330+
'',
331+
'// EXPORTS //',
332+
'',
333+
'module.exports = ahaversin;'
334+
].join( '\n' )
293335
};
294336
invalid.push( test );
295337

lib/node_modules/@stdlib/_tools/eslint/rules/jsdoc-doctest/test/fixtures/valid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ test = {
11161116
'// MODULES //',
11171117
'',
11181118
'var copysign = require( \'@stdlib/math/base/special/copysign\' );',
1119-
'var sincos = require( \'@stdlib/math/base/special/sincos\' );',
1119+
'var sincos = require( \'@stdlib/math/base/special/sincos\' ).assign;',
11201120
'var isnan = require( \'@stdlib/math/base/assert/is-nan\' );',
11211121
'var isInfinite = require( \'@stdlib/math/base/assert/is-infinite\' );',
11221122
'var exp = require( \'@stdlib/math/base/special/exp\' );',
@@ -1167,7 +1167,7 @@ test = {
11671167
' out[ 0 ] = e;',
11681168
' out[ 1 ] = im;',
11691169
' } else {',
1170-
' sincos( out, im );',
1170+
' sincos( im, out, 1, 0 );',
11711171
' tmp = out[ 0 ];',
11721172
' out[ 0 ] = out[ 1 ] * e;',
11731173
' out[ 1 ] = tmp * e;',
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# indexOfSameValue
22+
23+
> Return the index of the first element which equals a provided search element according to the [SameValue Algorithm][@stdlib/assert/is-same-value].
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var indexOfSameValue = require( '@stdlib/array/base/index-of-same-value' );
41+
```
42+
43+
#### indexOfSameValue( x, searchElement, fromIndex )
44+
45+
Returns the index of the first element which equals a provided search element according to the [SameValue Algorithm][@stdlib/assert/is-same-value].
46+
47+
```javascript
48+
var x = [ 1, 2, 3, 4, 5, 6 ];
49+
50+
var idx = indexOfSameValue( x, 3, 0 );
51+
// returns 2
52+
```
53+
54+
If the function is unable to find an element which equals a provided search element, the function returns `-1`.
55+
56+
```javascript
57+
var x = [ 1, 2, 3, 4, 5, 6 ];
58+
59+
var idx = indexOfSameValue( x, 7, 0 );
60+
// returns -1
61+
```
62+
63+
To begin searching from specific index, provide a non-zero `fromIndex` argument.
64+
65+
```javascript
66+
var x = [ 1, 1, 2, 1, 2, 3, 3 ];
67+
68+
var idx = indexOfSameValue( x, 2, 3 );
69+
// returns 4
70+
```
71+
72+
If `fromIndex` is less than zero, the starting index is resolved relative to the last array element, with the last array element corresponding to `fromIndex = -1`.
73+
74+
```javascript
75+
var x = [ 1, 1, 2, 1, 2, 3, 3 ];
76+
77+
var idx = indexOfSameValue( x, 2, -4 );
78+
// returns 4
79+
```
80+
81+
</section>
82+
83+
<!-- /.usage -->
84+
85+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
86+
87+
<section class="notes">
88+
89+
## Notes
90+
91+
- The function performs a linear scan and returns immediately upon finding a match.
92+
- When searching for a search element, the function checks for equality using the [SameValue Algorithm][@stdlib/assert/is-same-value] as specified in ECMAScript 5. As a consequence, `NaN` values are considered equal, and `-0` and `+0` are considered distinct.
93+
94+
</section>
95+
96+
<!-- /.notes -->
97+
98+
<!-- Package usage examples. -->
99+
100+
<section class="examples">
101+
102+
## Examples
103+
104+
<!-- eslint no-undef: "error" -->
105+
106+
```javascript
107+
var indexOfSameValue = require( '@stdlib/array/base/index-of-same-value' );
108+
109+
var x = [ 'foo', 'bar', 'beep', 'boop', 'foo', 'bar' ];
110+
111+
var idx = indexOfSameValue( x, 'beep', 0 );
112+
// returns 2
113+
114+
idx = indexOfSameValue( x, 'bop', 0 );
115+
// returns -1
116+
117+
idx = indexOfSameValue( x, 'foo', 1 );
118+
// returns 4
119+
120+
idx = indexOfSameValue( x, 'foo', -4 );
121+
// returns 4
122+
123+
idx = indexOfSameValue( x, 'foo', 5 );
124+
// returns -1
125+
```
126+
127+
</section>
128+
129+
<!-- /.examples -->
130+
131+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
132+
133+
<section class="references">
134+
135+
</section>
136+
137+
<!-- /.references -->
138+
139+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
140+
141+
<section class="related">
142+
143+
</section>
144+
145+
<!-- /.related -->
146+
147+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
148+
149+
<section class="links">
150+
151+
[@stdlib/assert/is-same-value]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-same-value
152+
153+
</section>
154+
155+
<!-- /.links -->
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 zeroTo = require( '@stdlib/array/base/zero-to' );
27+
var pkg = require( './../package.json' ).name;
28+
var indexOfSameValue = require( './../lib' );
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 = zeroTo( len );
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 = indexOfSameValue( x, -2, 0 );
57+
if ( out !== out ) {
58+
b.fail( 'should return an integer' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isInteger( out ) || out >= 0 ) {
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=generic,len='+len, f );
93+
}
94+
}
95+
96+
main();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
{{alias}}( x, searchElement, fromIndex )
3+
Returns the index of the first element which equals a provided search
4+
element according to the same value algorithm.
5+
6+
The function performs a linear scan and returns immediately upon finding a
7+
match.
8+
9+
If unable to find an element which equals a provided search element, the
10+
function returns -1.
11+
12+
The function treats `-0` and `+0` as distinct and `NaNs` as the same.
13+
14+
Parameters
15+
----------
16+
x: ArrayLikeObject
17+
Input array.
18+
19+
searchElement: any
20+
Search element.
21+
22+
fromIndex: integer
23+
Starting index (inclusive). If less than zero, the starting index is
24+
resolved relative to the last array element, with the last array element
25+
corresponding to `fromIndex = -1`.
26+
27+
Returns
28+
-------
29+
out: integer
30+
Index or -1.
31+
32+
Examples
33+
--------
34+
> var out = {{alias}}( [ 1, 2, 3, 4 ], 3, 0 )
35+
2
36+
37+
See Also
38+
--------
39+

0 commit comments

Comments
 (0)