Skip to content

Commit 190c7b4

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents db91373 + 15e6c71 commit 190c7b4

File tree

21 files changed

+1432
-9
lines changed

21 files changed

+1432
-9
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 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+
# isSameAccessorArray
22+
23+
> Test if two arguments are both [accessor arrays][@stdlib/assert/is-accessor-array] and have the [same values][@stdlib/assert/is-same-value].
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var isSameAccessorArray = require( '@stdlib/assert/is-same-accessor-array' );
31+
```
32+
33+
#### isSameAccessorArray( v1, v2 )
34+
35+
Tests if two arguments are both [accessor arrays][@stdlib/assert/is-accessor-array] and have the [same values][@stdlib/assert/is-same-value].
36+
37+
```javascript
38+
var Complex128Array = require( '@stdlib/array/complex128' );
39+
40+
var x = new Complex128Array( [ 1.0, 2.0 ] );
41+
var y = new Complex128Array( [ 1.0, 2.0 ] );
42+
var bool = isSameAccessorArray( x, y );
43+
// returns true
44+
45+
bool = isSameAccessorArray( x, [ -1.0, 2.0 ] );
46+
// returns false
47+
```
48+
49+
</section>
50+
51+
<!-- /.usage -->
52+
53+
<section class="notes">
54+
55+
## Notes
56+
57+
- In contrast to the strict equality operator `===`, the function distinguishes between `+0` and `-0` and treats `NaNs` as the [same value][@stdlib/assert/is-same-value].
58+
59+
</section>
60+
61+
<!-- /.notes -->
62+
63+
<section class="examples">
64+
65+
## Examples
66+
67+
<!-- eslint no-undef: "error" -->
68+
69+
```javascript
70+
var isSameAccessorArray = require( '@stdlib/assert/is-same-accessor-array' );
71+
var Complex128Array = require( '@stdlib/array/complex128' );
72+
73+
var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] );
74+
var y = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] );
75+
var out = isSameAccessorArray( x, y );
76+
// returns true
77+
78+
x = new Complex128Array( [ 1.0, 2.0, 0.0, 4.0 ] );
79+
y = new Complex128Array( [ 1.0, 2.0, 3.0, -1.0 ] );
80+
out = isSameAccessorArray( x, y );
81+
// returns false
82+
83+
x = new Complex128Array( [ NaN, NaN ] );
84+
y = new Complex128Array( [ NaN, NaN ] );
85+
out = isSameAccessorArray( x, y );
86+
// returns true
87+
```
88+
89+
</section>
90+
91+
<!-- /.examples -->
92+
93+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
94+
95+
<section class="related">
96+
97+
</section>
98+
99+
<!-- /.related -->
100+
101+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
102+
103+
<section class="links">
104+
105+
[@stdlib/assert/is-same-value]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-same-value
106+
107+
[@stdlib/assert/is-accessor-array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-accessor-array
108+
109+
<!-- <related-links> -->
110+
111+
<!-- </related-links> -->
112+
113+
</section>
114+
115+
<!-- /.links -->
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 complex128Array = require( '@stdlib/array/complex128' );
24+
var bench = require( '@stdlib/bench' );
25+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var zeroTo = require( '@stdlib/array/base/zero-to' );
28+
var pkg = require( './../package.json' ).name;
29+
var isSameAccessorArray = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - array length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var x = complex128Array( zeroTo( len ) );
43+
var y = complex128Array( zeroTo( len ) );
44+
return benchmark;
45+
46+
/**
47+
* Benchmark function.
48+
*
49+
* @private
50+
* @param {Benchmark} b - benchmark instance
51+
*/
52+
function benchmark( b ) {
53+
var bool;
54+
var i;
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
bool = isSameAccessorArray( x, y );
59+
if ( typeof bool !== 'boolean' ) {
60+
b.fail( 'should return a boolean' );
61+
}
62+
}
63+
b.toc();
64+
if ( !isBoolean( bool ) ) {
65+
b.fail( 'should return a boolean' );
66+
}
67+
b.pass( 'benchmark finished' );
68+
b.end();
69+
}
70+
}
71+
72+
73+
// MAIN //
74+
75+
/**
76+
* Main execution sequence.
77+
*
78+
* @private
79+
*/
80+
function main() {
81+
var len;
82+
var min;
83+
var max;
84+
var f;
85+
var i;
86+
87+
min = 1; // 10^min
88+
max = 6; // 10^max
89+
90+
for ( i = min; i <= max; i++ ) {
91+
len = pow( 10, i );
92+
f = createBenchmark( len );
93+
bench( pkg+':len='+len, f );
94+
}
95+
}
96+
97+
main();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
{{alias}}( v1, v2 )
3+
Tests if two arguments are both accessor arrays and have the same values.
4+
5+
The function differs from the `===` operator in that the function treats
6+
`-0` and `+0` as distinct and `NaNs` as the same.
7+
8+
Parameters
9+
----------
10+
v1: any
11+
First input value.
12+
13+
v2: any
14+
Second input value.
15+
16+
Returns
17+
-------
18+
bool: boolean
19+
Boolean indicating whether two arguments are both accessor arrays
20+
having the same values.
21+
22+
Examples
23+
--------
24+
> var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] );
25+
> var y = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] );
26+
> var bool = {{alias}}( x, y )
27+
true
28+
29+
> x = new {{alias:@stdlib/array/complex128}}( [] );
30+
> y = new {{alias:@stdlib/array/complex128}}( [] );
31+
> bool = {{alias}}( x, y )
32+
true
33+
34+
See Also
35+
--------
36+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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+
/**
22+
* Tests if two arguments are both accessor arrays and have the same values.
23+
*
24+
* ## Notes
25+
*
26+
* - The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same.
27+
*
28+
* @param v1 - first input value
29+
* @param v2 - second input value
30+
* @returns boolean indicating whether two arguments are accessor arrays with the same content
31+
*
32+
* @example
33+
* var Complex128Array = require( '@stdlib/array/complex128' );
34+
*
35+
* var x = new Complex128Array( [ 1, 2, 1, 2 ] );
36+
* var y = new Complex128Array( [ 1, 2, 1, 2 ] );
37+
* var out = isSameAccessorArray( x, y );
38+
* // returns true
39+
*
40+
* @example
41+
* var Complex128Array = require( '@stdlib/array/complex128' );
42+
*
43+
* var x = new Complex128Array( [ 1, 2, 1, 2 ] );
44+
* var y = new Complex128Array( [ 2, 1, 2, 1 ] );
45+
* var out = isSameAccessorArray( x, y );
46+
* // returns false
47+
*
48+
* @example
49+
* var Complex128Array = require( '@stdlib/array/complex128' );
50+
*
51+
* var x = new Complex128Array( [ 1, 2, 1, 2 ] );
52+
* var y = [ 1, 2, 3 ];
53+
* var out = isSameAccessorArray( x, y );
54+
* // returns false
55+
*/
56+
declare function isSameAccessorArray( v1: any, v2: any ): boolean;
57+
58+
59+
// EXPORTS //
60+
61+
export = isSameAccessorArray;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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+
import isSameAccessorArray = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isSameAccessorArray( 3.14, 3.14 ); // $ExpectType boolean
27+
isSameAccessorArray( null, null ); // $ExpectType boolean
28+
isSameAccessorArray( 'beep', 'boop' ); // $ExpectType boolean
29+
}
30+
31+
// The compiler throws an error if the function is provided an unsupported number of arguments...
32+
{
33+
isSameAccessorArray(); // $ExpectError
34+
isSameAccessorArray( 3.14 ); // $ExpectError
35+
isSameAccessorArray( 'beep', 'beep', 3.14 ); // $ExpectError
36+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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+
var Complex128Array = require( '@stdlib/array/complex128' );
22+
var Complex64Array = require( '@stdlib/array/complex64' );
23+
var isSameAccessorArray = require( './../lib' );
24+
25+
var x = new Complex128Array( [ 1, 2, 3, 4 ] );
26+
var y = new Complex128Array( [ 1, 2, 3, 4 ] );
27+
var out = isSameAccessorArray( x, y );
28+
console.log( out );
29+
// => true
30+
31+
x = new Complex64Array( [ 1, 2 ]);
32+
y = [ 0.0, -0.0, 0.0 ];
33+
out = isSameAccessorArray( x, y );
34+
console.log( out );
35+
// => false
36+
37+
x = new Complex128Array( [] );
38+
y = new Complex64Array( [] );
39+
out = isSameAccessorArray( x, y );
40+
console.log( out );
41+
// => true

0 commit comments

Comments
 (0)