Skip to content

Commit 73d5c18

Browse files
committed
Auto-generated commit
1 parent 4119df4 commit 73d5c18

File tree

15 files changed

+1302
-2
lines changed

15 files changed

+1302
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Features
1212

13+
- [`ca51243`](https://github.com/stdlib-js/stdlib/commit/ca5124377589a8051527e4bc3b87173723c88f51) - add `hasAlmostSameValues` to namespace
14+
- [`24426d2`](https://github.com/stdlib-js/stdlib/commit/24426d292e18009d0d4acd3615e8f520b92b0c1b) - add `array/base/assert/has-almost-same-values`
1315
- [`5cf5331`](https://github.com/stdlib-js/stdlib/commit/5cf533172ba0fb480dcdbbe03861cfc14aded211) - update `array/base` TypeScript declarations
1416
- [`029ac45`](https://github.com/stdlib-js/stdlib/commit/029ac457518cedb513351f5196fa078ad0a78ede) - update `array/base/symmetric` TypeScript declarations
1517
- [`b090daa`](https://github.com/stdlib-js/stdlib/commit/b090daacf3b51a2afa50c08a06973ac13724e9df) - update `array/base/symmetric-banded` TypeScript declarations
@@ -257,6 +259,10 @@ A total of 33 issues were closed in this release:
257259

258260
<details>
259261

262+
- [`ca51243`](https://github.com/stdlib-js/stdlib/commit/ca5124377589a8051527e4bc3b87173723c88f51) - **feat:** add `hasAlmostSameValues` to namespace _(by Athan Reines)_
263+
- [`24426d2`](https://github.com/stdlib-js/stdlib/commit/24426d292e18009d0d4acd3615e8f520b92b0c1b) - **feat:** add `array/base/assert/has-almost-same-values` _(by Athan Reines)_
264+
- [`40e817d`](https://github.com/stdlib-js/stdlib/commit/40e817dca3683fef6bfaf07526e8428ac3d089d8) - **bench:** refactor to use string interpolation in `array/base/filled4d` [(#9186)](https://github.com/stdlib-js/stdlib/pull/9186) _(by Rohit R Bhat)_
265+
- [`ce79dc0`](https://github.com/stdlib-js/stdlib/commit/ce79dc05e70a1a631c3d23c2f0d2127420537b38) - **bench:** refactor to use string interpolation in `array/base/filled4d-by` [(#9188)](https://github.com/stdlib-js/stdlib/pull/9188) _(by Rohit R Bhat)_
260266
- [`ae947b7`](https://github.com/stdlib-js/stdlib/commit/ae947b78961fba28af4cdc2f4ba54fa5df8b35b3) - **bench:** refactor to use string interpolation in `array/base/filled5d` [(#9189)](https://github.com/stdlib-js/stdlib/pull/9189) _(by Rohit R Bhat)_
261267
- [`028d3db`](https://github.com/stdlib-js/stdlib/commit/028d3db4147f5e4735d81babd193a65c983d87c9) - **bench:** refactor to use string interpolation in `array/base/take3d` [(#9053)](https://github.com/stdlib-js/stdlib/pull/9053) _(by DivitJain26, Athan Reines)_
262268
- [`66dec1e`](https://github.com/stdlib-js/stdlib/commit/66dec1ea2a3186a8b461abc11ad69f1e42b1c478) - **bench:** refactor to use string interpolation in `array/base/take2d` [(#9051)](https://github.com/stdlib-js/stdlib/pull/9051) _(by DivitJain26, Athan Reines)_

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ For more information on the project, filing bug reports and feature requests, an
309309

310310
---
311311

312+
## License
313+
314+
See [LICENSE][stdlib-license].
315+
316+
312317
## Copyright
313318

314319
Copyright &copy; 2016-2025. The Stdlib [Authors][stdlib-authors].
@@ -355,6 +360,8 @@ Copyright &copy; 2016-2025. The Stdlib [Authors][stdlib-authors].
355360
[esm-readme]: https://github.com/stdlib-js/array/blob/esm/README.md
356361
[branches-url]: https://github.com/stdlib-js/array/blob/main/branches.md
357362

363+
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array/main/LICENSE
364+
358365
<!-- <toc-links> -->
359366

360367
[@stdlib/array/base]: https://github.com/stdlib-js/array/tree/main/base
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
# hasAlmostSameValues
22+
23+
> Test if two arrays have respective elements which are approximately the same value within a specified number of ULPs (units in the last place).
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 hasAlmostSameValues = require( '@stdlib/array/base/assert/has-almost-same-values' );
41+
```
42+
43+
#### hasAlmostSameValues( x, y, maxULP )
44+
45+
Tests if two arrays have respective elements which are approximately the same value within a specified number of ULPs (units in the last place).
46+
47+
```javascript
48+
var x = [ 0, 0, 1, 0 ];
49+
var y = [ 0, 0, 1, 0 ];
50+
51+
var bool = hasAlmostSameValues( x, y, 1 );
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+
- In contrast to the strict equality operator `===`, the function distinguishes between `+0` and `-0` and treats `NaNs` as the same value.
66+
- If provided arrays of unequal length, the function returns `false`.
67+
- The function does **not** skip `undefined` elements and is thus not optimized for sparse arrays.
68+
69+
</section>
70+
71+
<!-- /.notes -->
72+
73+
<!-- Package usage examples. -->
74+
75+
<section class="examples">
76+
77+
## Examples
78+
79+
<!-- eslint no-undef: "error" -->
80+
81+
```javascript
82+
var uniform = require( '@stdlib/random/array/uniform' );
83+
var Complex128Array = require( '@stdlib/array/complex128' );
84+
var hasAlmostSameValues = require( '@stdlib/array/base/assert/has-almost-same-values' );
85+
86+
var buf = uniform( 10, 0, 10 );
87+
// returns <Float64Array>
88+
89+
var x = new Complex128Array( buf );
90+
// returns <Complex128Array>
91+
92+
var y = new Complex128Array( buf );
93+
// returns <Complex128Array>
94+
95+
var out = hasAlmostSameValues( x, y, 1 );
96+
// returns true
97+
```
98+
99+
</section>
100+
101+
<!-- /.examples -->
102+
103+
<!-- 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. -->
104+
105+
<section class="references">
106+
107+
</section>
108+
109+
<!-- /.references -->
110+
111+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
112+
113+
<section class="related">
114+
115+
</section>
116+
117+
<!-- /.related -->
118+
119+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
120+
121+
<section class="links">
122+
123+
</section>
124+
125+
<!-- /.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) 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
26+
var zeros = require( './../../../../base/zeros' );
27+
var format = require( '@stdlib/string/format' );
28+
var pkg = require( './../package.json' ).name;
29+
var hasAlmostSameValues = 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 = zeros( len );
43+
return benchmark;
44+
45+
/**
46+
* Benchmark function.
47+
*
48+
* @private
49+
* @param {Benchmark} b - benchmark instance
50+
*/
51+
function benchmark( b ) {
52+
var out;
53+
var i;
54+
55+
b.tic();
56+
for ( i = 0; i < b.iterations; i++ ) {
57+
out = hasAlmostSameValues( x, x, 1 );
58+
if ( typeof out !== 'boolean' ) {
59+
b.fail( 'should return a boolean' );
60+
}
61+
}
62+
b.toc();
63+
if ( !isBoolean( out ) ) {
64+
b.fail( 'should return a boolean' );
65+
}
66+
b.pass( 'benchmark finished' );
67+
b.end();
68+
}
69+
}
70+
71+
72+
// MAIN //
73+
74+
/**
75+
* Main execution sequence.
76+
*
77+
* @private
78+
*/
79+
function main() {
80+
var len;
81+
var min;
82+
var max;
83+
var f;
84+
var i;
85+
86+
min = 1; // 10^min
87+
max = 6; // 10^max
88+
89+
for ( i = min; i <= max; i++ ) {
90+
len = pow( 10, i );
91+
92+
f = createBenchmark( len );
93+
bench( format( '%s:dtype=generic,len=%s', pkg, len ), f );
94+
}
95+
}
96+
97+
main();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
{{alias}}( x, y, maxULP )
3+
Tests if two arrays have respective elements which are approximately the
4+
same value within a specified number of ULPs (units in the last place).
5+
6+
If provided arrays of unequal length, the function returns `false`.
7+
8+
Parameters
9+
----------
10+
x: Array|TypedArray|Object
11+
First input array.
12+
13+
y: Array|TypedArray|Object
14+
Second input array.
15+
16+
maxULP: integer
17+
Maximum allowed ULP difference.
18+
19+
Returns
20+
-------
21+
bool: boolean
22+
Boolean indicating whether two arrays are approximately the same.
23+
24+
Examples
25+
--------
26+
> var x = [ 0, 0, 1, 0 ];
27+
> var y = [ 0, 0, 1, 0 ];
28+
> var out = {{alias}}( x, y, 0 )
29+
true
30+
31+
See Also
32+
--------
33+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { Collection, AccessorArrayLike } from '@stdlib/types/array';
24+
25+
/**
26+
* Tests if two arrays have respective elements which are approximately the same value within a specified number of ULPs (units in the last place).
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+
* @param maxULP - maximum allowed ULP difference
35+
* @returns boolean indicating whether both arrays are approximately the same value
36+
*
37+
* @example
38+
* var x = [ 0, 0, 1, 0 ];
39+
* var y = [ 0, 0, 1, 0 ];
40+
*
41+
* var out = hasAlmostSameValues( x, y, 0 );
42+
* // returns true
43+
*/
44+
declare function hasAlmostSameValues<T = unknown, U = unknown>( x: Collection<T> | AccessorArrayLike<T>, y: Collection<U> | AccessorArrayLike<U>, maxULP: number ): boolean;
45+
46+
47+
// EXPORTS //
48+
49+
export = hasAlmostSameValues;

0 commit comments

Comments
 (0)