Skip to content

Commit 0729f51

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents b789714 + 114f651 commit 0729f51

File tree

82 files changed

+4076
-31
lines changed

Some content is hidden

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

82 files changed

+4076
-31
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
# hasEqualValuesIndexed
22+
23+
> Test if two indexed arrays have equal values.
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 hasEqualValuesIndexed = require( '@stdlib/array/base/assert/has-equal-values-indexed' );
41+
```
42+
43+
#### hasEqualValuesIndexed( x, y )
44+
45+
Tests if two indexed arrays have equal values.
46+
47+
```javascript
48+
var x = [ 0, 0, 1, 0 ];
49+
var y = [ 0, 0, 1, 0 ];
50+
51+
var bool = hasEqualValuesIndexed( x, y );
52+
// returns true
53+
```
54+
55+
</section>
56+
57+
<!-- /.usage -->
58+
59+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
60+
61+
<section class="notes">
62+
63+
## Notes
64+
65+
- If provided arrays of unequal length, the function returns `false`.
66+
- The function performs **strict** equality comparison.
67+
- The function does **not** skip `undefined` elements and is thus not optimized for sparse arrays.
68+
- An _indexed_ array-like object is a data structure in which one retrieves elements via integer indices using bracket `[]` notation (e.g., `Float64Array`, `Int32Array`, `Array`, etc). This is in contrast to an _accessor_ array-like object in which one retrieves elements using `get` and `set` methods (e.g., [`Complex64Array`][@stdlib/array/complex64] and [`Complex128Array`][@stdlib/array/complex128]).
69+
70+
</section>
71+
72+
<!-- /.notes -->
73+
74+
<!-- Package usage examples. -->
75+
76+
<section class="examples">
77+
78+
## Examples
79+
80+
<!-- eslint no-undef: "error" -->
81+
82+
```javascript
83+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
84+
var Float64Array = require( '@stdlib/array/float64' );
85+
var hasEqualValuesIndexed = require( '@stdlib/array/base/assert/has-equal-values-indexed' );
86+
87+
var buf = discreteUniform( 10, 0, 10 );
88+
// returns <Float64Array>
89+
90+
var x = new Float64Array( buf );
91+
// returns <Float64Array>
92+
93+
var y = new Float64Array( buf );
94+
// returns <Float64Array>
95+
96+
var out = hasEqualValuesIndexed( x, y );
97+
// returns true
98+
```
99+
100+
</section>
101+
102+
<!-- /.examples -->
103+
104+
<!-- 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. -->
105+
106+
<section class="references">
107+
108+
</section>
109+
110+
<!-- /.references -->
111+
112+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
113+
114+
<section class="related">
115+
116+
</section>
117+
118+
<!-- /.related -->
119+
120+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
121+
122+
<section class="links">
123+
124+
[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64
125+
126+
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128
127+
128+
</section>
129+
130+
<!-- /.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) 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 bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
26+
var zeros = require( '@stdlib/array/base/zeros' );
27+
var pkg = require( './../package.json' ).name;
28+
var hasEqualValuesIndexed = 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 = zeros( 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 = hasEqualValuesIndexed( x, x );
57+
if ( typeof out !== 'boolean' ) {
58+
b.fail( 'should return a boolean' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isBoolean( out ) ) {
63+
b.fail( 'should return a boolean' );
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
{{alias}}( x, y )
3+
Tests if two indexed arrays have equal values.
4+
5+
If provided arrays of unequal length, the function returns `false`.
6+
7+
Parameters
8+
----------
9+
x: Array|TypedArray|Object
10+
First input array.
11+
12+
y: Array|TypedArray|Object
13+
Second input array.
14+
15+
Returns
16+
-------
17+
bool: boolean
18+
The function returns `true` if both arrays have equal values; otherwise,
19+
the function returns `false`.
20+
21+
Examples
22+
--------
23+
> var x = [ 0, 0, 1, 0 ];
24+
> var y = [ 0, 0, 1, 0 ];
25+
> var out = {{alias}}( x, y )
26+
true
27+
28+
See Also
29+
--------
30+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
/// <reference types="@stdlib/types"/>
22+
23+
import { Collection } from '@stdlib/types/array';
24+
25+
/**
26+
* Tests if two indexed arrays have equal values.
27+
*
28+
* ## Notes
29+
*
30+
* - If provided arrays of unequal length, the function returns `false`.
31+
*
32+
* @param x - first input array
33+
* @param y - second input array
34+
* @returns boolean indicating whether both arrays have equal values
35+
*
36+
* @example
37+
* var x = [ 0, 0, 1, 0 ];
38+
* var y = [ 0, 0, 1, 0 ];
39+
*
40+
* var out = hasEqualValuesIndexed( x, y );
41+
* // returns true
42+
*/
43+
declare function hasEqualValuesIndexed<T = unknown, U = unknown>( x: Collection<T>, y: Collection<U> ): boolean;
44+
45+
46+
// EXPORTS //
47+
48+
export = hasEqualValuesIndexed;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 hasEqualValuesIndexed = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
const x = [ 1, 2, 3 ];
27+
28+
hasEqualValuesIndexed( x, x ); // $ExpectType boolean
29+
hasEqualValuesIndexed( new Float64Array( x ), new Float64Array( x ) ); // $ExpectType boolean
30+
hasEqualValuesIndexed( new Float32Array( x ), new Float32Array( x ) ); // $ExpectType boolean
31+
hasEqualValuesIndexed( new Int32Array( x ), new Int32Array( x ) ); // $ExpectType boolean
32+
hasEqualValuesIndexed( new Int16Array( x ), new Int16Array( x ) ); // $ExpectType boolean
33+
hasEqualValuesIndexed( new Int8Array( x ), new Int8Array( x ) ); // $ExpectType boolean
34+
hasEqualValuesIndexed( new Uint32Array( x ), new Uint32Array( x ) ); // $ExpectType boolean
35+
hasEqualValuesIndexed( new Uint16Array( x ), new Uint16Array( x ) ); // $ExpectType boolean
36+
hasEqualValuesIndexed( new Uint8Array( x ), new Uint8Array( x ) ); // $ExpectType boolean
37+
hasEqualValuesIndexed( new Uint8ClampedArray( x ), new Uint8ClampedArray( x ) ); // $ExpectType boolean
38+
}
39+
40+
// The compiler throws an error if the function is provided a first argument which is not a collection...
41+
{
42+
const x = [ 1, 2, 3 ];
43+
44+
hasEqualValuesIndexed( 2, x ); // $ExpectError
45+
hasEqualValuesIndexed( false, x ); // $ExpectError
46+
hasEqualValuesIndexed( true, x ); // $ExpectError
47+
hasEqualValuesIndexed( {}, x ); // $ExpectError
48+
}
49+
50+
// The compiler throws an error if the function is provided a second argument which is not a collection...
51+
{
52+
const x = [ 1, 2, 3 ];
53+
54+
hasEqualValuesIndexed( x, 2 ); // $ExpectError
55+
hasEqualValuesIndexed( x, false ); // $ExpectError
56+
hasEqualValuesIndexed( x, true ); // $ExpectError
57+
hasEqualValuesIndexed( x, {} ); // $ExpectError
58+
}
59+
60+
// The compiler throws an error if the function is provided an unsupported number of arguments...
61+
{
62+
const x = [ 1, 2, 3 ];
63+
64+
hasEqualValuesIndexed(); // $ExpectError
65+
hasEqualValuesIndexed( x ); // $ExpectError
66+
hasEqualValuesIndexed( x, x, x ); // $ExpectError
67+
}

0 commit comments

Comments
 (0)