-
-
Notifications
You must be signed in to change notification settings - Fork 907
feat: add @stdlib/assert/is-same-accessor-array
#2890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a013fe4
feat: add main function
aayush0325 7fa08c5
feat: added tests
aayush0325 f331e07
feat: added examples
aayush0325 1840b5a
feat: added benchmark
aayush0325 774e28b
feat: added docs
aayush0325 76bd76f
feat: added README.md
aayush0325 f82d632
fix: package.json desc error fixed
aayush0325 c056bcb
fix: updated package.json keywords
aayush0325 b7043e4
chore: apply suggestions from code review
Planeshifter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
lib/node_modules/@stdlib/assert/is-same-accessor-array/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<!-- | ||
|
||
@license Apache-2.0 | ||
|
||
Copyright (c) 2024 The Stdlib Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
--> | ||
|
||
# isSameAccessorArray | ||
|
||
> Test if two arguments are both [accessor arrays][@stdlib/assert/is-accessor-array] and have the [same values][@stdlib/assert/is-same-value]. | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var isSameAccessorArray = require( '@stdlib/assert/is-same-accessor-array' ); | ||
``` | ||
|
||
#### isSameAccessorArray( v1, v2 ) | ||
|
||
Tests if two arguments are both [accessor arrays][@stdlib/assert/is-accessor-array] and have the [same values][@stdlib/assert/is-same-value]. | ||
|
||
```javascript | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
|
||
var x = new Complex128Array( [ 1.0, 2.0 ] ); | ||
var y = new Complex128Array( [ 1.0, 2.0 ] ); | ||
var bool = isSameAccessorArray( x, y ); | ||
// returns true | ||
|
||
bool = isSameAccessorArray( x, [ -1.0, 2.0 ] ); | ||
// returns false | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="notes"> | ||
|
||
## Notes | ||
|
||
- 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]. | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var isSameAccessorArray = require( '@stdlib/assert/is-same-accessor-array' ); | ||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
|
||
var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
var y = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
var out = isSameAccessorArray( x, y ); | ||
// returns true | ||
|
||
x = new Complex128Array( [ 1.0, 2.0, 0.0, 4.0 ] ); | ||
y = new Complex128Array( [ 1.0, 2.0, 3.0, -1.0 ] ); | ||
out = isSameAccessorArray( x, y ); | ||
// returns false | ||
|
||
x = new Complex128Array( [ NaN, NaN ] ); | ||
y = new Complex128Array( [ NaN, NaN ] ); | ||
out = isSameAccessorArray( x, y ); | ||
// returns true | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
</section> | ||
|
||
<!-- /.related --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
|
||
[@stdlib/assert/is-same-value]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-same-value | ||
|
||
[@stdlib/assert/is-accessor-array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-accessor-array | ||
|
||
<!-- <related-links> --> | ||
|
||
<!-- </related-links> --> | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
97 changes: 97 additions & 0 deletions
97
lib/node_modules/@stdlib/assert/is-same-accessor-array/benchmark/benchmark.length.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var complex128Array = require( '@stdlib/array/complex128' ); | ||
var bench = require( '@stdlib/bench' ); | ||
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var zeroTo = require( '@stdlib/array/base/zero-to' ); | ||
var pkg = require( './../package.json' ).name; | ||
var isSameAccessorArray = require( './../lib' ); | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} len - array length | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( len ) { | ||
var x = complex128Array( zeroTo( len ) ); | ||
var y = complex128Array( zeroTo( len ) ); | ||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var bool; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
bool = isSameAccessorArray( x, y ); | ||
if ( typeof bool !== 'boolean' ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( !isBoolean( bool ) ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
} | ||
} | ||
|
||
|
||
// MAIN // | ||
|
||
/** | ||
* Main execution sequence. | ||
* | ||
* @private | ||
*/ | ||
function main() { | ||
var len; | ||
var min; | ||
var max; | ||
var f; | ||
var i; | ||
|
||
min = 1; // 10^min | ||
max = 6; // 10^max | ||
|
||
for ( i = min; i <= max; i++ ) { | ||
len = pow( 10, i ); | ||
f = createBenchmark( len ); | ||
bench( pkg+':len='+len, f ); | ||
} | ||
} | ||
|
||
main(); |
36 changes: 36 additions & 0 deletions
36
lib/node_modules/@stdlib/assert/is-same-accessor-array/docs/repl.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
{{alias}}( v1, v2 ) | ||
Tests if two arguments are both accessor arrays and have the same values. | ||
|
||
The function differs from the `===` operator in that the function treats | ||
`-0` and `+0` as distinct and `NaNs` as the same. | ||
|
||
Parameters | ||
---------- | ||
v1: any | ||
First input value. | ||
|
||
v2: any | ||
Second input value. | ||
|
||
Returns | ||
------- | ||
bool: boolean | ||
Boolean indicating whether two arguments are both accessor arrays | ||
having the same values. | ||
|
||
Examples | ||
-------- | ||
> var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
> var y = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] ); | ||
> var bool = {{alias}}( x, y ) | ||
true | ||
|
||
> x = new {{alias:@stdlib/array/complex128}}( [] ); | ||
> y = new {{alias:@stdlib/array/complex128}}( [] ); | ||
> bool = {{alias}}( x, y ) | ||
true | ||
|
||
See Also | ||
-------- | ||
|
61 changes: 61 additions & 0 deletions
61
lib/node_modules/@stdlib/assert/is-same-accessor-array/docs/types/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// TypeScript Version: 4.1 | ||
|
||
/** | ||
* Tests if two arguments are both accessor arrays and have the same values. | ||
* | ||
* ## Notes | ||
* | ||
* - The function differs from the `===` operator in that the function treats `-0` and `+0` as distinct and `NaNs` as the same. | ||
* | ||
* @param v1 - first input value | ||
* @param v2 - second input value | ||
* @returns boolean indicating whether two arguments are accessor arrays with the same content | ||
* | ||
* @example | ||
* var Complex128Array = require( '@stdlib/array/complex128' ); | ||
* | ||
* var x = new Complex128Array( [ 1, 2, 1, 2 ] ); | ||
* var y = new Complex128Array( [ 1, 2, 1, 2 ] ); | ||
* var out = isSameAccessorArray( x, y ); | ||
* // returns true | ||
* | ||
* @example | ||
* var Complex128Array = require( '@stdlib/array/complex128' ); | ||
* | ||
* var x = new Complex128Array( [ 1, 2, 1, 2 ] ); | ||
* var y = new Complex128Array( [ 2, 1, 2, 1 ] ); | ||
* var out = isSameAccessorArray( x, y ); | ||
* // returns false | ||
* | ||
* @example | ||
* var Complex128Array = require( '@stdlib/array/complex128' ); | ||
* | ||
* var x = new Complex128Array( [ 1, 2, 1, 2 ] ); | ||
* var y = [ 1, 2, 3 ]; | ||
* var out = isSameAccessorArray( x, y ); | ||
* // returns false | ||
*/ | ||
declare function isSameAccessorArray( v1: any, v2: any ): boolean; | ||
Check warning on line 56 in lib/node_modules/@stdlib/assert/is-same-accessor-array/docs/types/index.d.ts
|
||
|
||
|
||
// EXPORTS // | ||
|
||
export = isSameAccessorArray; |
36 changes: 36 additions & 0 deletions
36
lib/node_modules/@stdlib/assert/is-same-accessor-array/docs/types/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import isSameAccessorArray = require( './index' ); | ||
|
||
|
||
// TESTS // | ||
|
||
// The function returns a boolean... | ||
{ | ||
isSameAccessorArray( 3.14, 3.14 ); // $ExpectType boolean | ||
isSameAccessorArray( null, null ); // $ExpectType boolean | ||
isSameAccessorArray( 'beep', 'boop' ); // $ExpectType boolean | ||
} | ||
|
||
// The compiler throws an error if the function is provided an unsupported number of arguments... | ||
{ | ||
isSameAccessorArray(); // $ExpectError | ||
isSameAccessorArray( 3.14 ); // $ExpectError | ||
isSameAccessorArray( 'beep', 'beep', 3.14 ); // $ExpectError | ||
} |
41 changes: 41 additions & 0 deletions
41
lib/node_modules/@stdlib/assert/is-same-accessor-array/examples/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var Complex128Array = require( '@stdlib/array/complex128' ); | ||
var Complex64Array = require( '@stdlib/array/complex64' ); | ||
var isSameAccessorArray = require( './../lib' ); | ||
|
||
var x = new Complex128Array( [ 1, 2, 3, 4 ] ); | ||
var y = new Complex128Array( [ 1, 2, 3, 4 ] ); | ||
var out = isSameAccessorArray( x, y ); | ||
console.log( out ); | ||
// => true | ||
|
||
x = new Complex64Array( [ 1, 2 ]); | ||
y = [ 0.0, -0.0, 0.0 ]; | ||
out = isSameAccessorArray( x, y ); | ||
console.log( out ); | ||
// => false | ||
|
||
x = new Complex128Array( [] ); | ||
y = new Complex64Array( [] ); | ||
out = isSameAccessorArray( x, y ); | ||
console.log( out ); | ||
// => true |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.