Skip to content

Commit bbe6033

Browse files
committed
Auto-generated commit
1 parent 79a537e commit bbe6033

File tree

13 files changed

+1289
-2
lines changed

13 files changed

+1289
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-07-13)
7+
## Unreleased (2025-07-15)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`0b89b56`](https://github.com/stdlib-js/stdlib/commit/0b89b56db0aa040a643ef859ac71795462e947d5) - add `hasAlmostEqualValues` to namespace
14+
- [`fee6898`](https://github.com/stdlib-js/stdlib/commit/fee68983980c006c27c7f1f5d1f3f11b20602974) - add `array/base/assert/has-almost-equal-values`
1315
- [`7f0421e`](https://github.com/stdlib-js/stdlib/commit/7f0421e54502fdd9e92758d9c9123216372287fd) - add inital implementation of `array/struct-factory`
1416
- [`79efa56`](https://github.com/stdlib-js/stdlib/commit/79efa566515a8c7453fb59b9e18050be37969830) - add `anyHasOwnProp`, `anyHasProp`, `anyIsEntry`, and `anyIsEntryIn` to namespace
1517
- [`9d04faf`](https://github.com/stdlib-js/stdlib/commit/9d04fafb8ff8cbba366950b2659de2c652953597) - add `array/base/any-is-entry-in`
@@ -217,6 +219,8 @@ A total of 32 issues were closed in this release:
217219

218220
<details>
219221

222+
- [`0b89b56`](https://github.com/stdlib-js/stdlib/commit/0b89b56db0aa040a643ef859ac71795462e947d5) - **feat:** add `hasAlmostEqualValues` to namespace _(by Athan Reines)_
223+
- [`fee6898`](https://github.com/stdlib-js/stdlib/commit/fee68983980c006c27c7f1f5d1f3f11b20602974) - **feat:** add `array/base/assert/has-almost-equal-values` _(by Athan Reines)_
220224
- [`2a0ea7f`](https://github.com/stdlib-js/stdlib/commit/2a0ea7feb22806685fef9eac8a32d7012dab7adc) - **fix:** use correct package names in package.json _(by Philipp Burckhardt)_
221225
- [`7c9afed`](https://github.com/stdlib-js/stdlib/commit/7c9afed6a288c9e7d3048dfa0ac8f085759d73f4) - **chore:** minor clean-up _(by Philipp Burckhardt)_
222226
- [`bc3632a`](https://github.com/stdlib-js/stdlib/commit/bc3632a5a7b48a8973b1418e861ddc45b3e8d0fa) - **chore:** minor clean-up _(by Philipp Burckhardt)_
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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+
# hasAlmostEqualValues
22+
23+
> Test if two arrays have respective elements which are approximately equal 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 hasAlmostEqualValues = require( '@stdlib/array/base/assert/has-almost-equal-values' );
41+
```
42+
43+
#### hasAlmostEqualValues( x, y, maxULP )
44+
45+
Tests if two arrays have respective elements which are approximately equal 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 = hasAlmostEqualValues( 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+
- If provided arrays of unequal length, the function returns `false`.
66+
- The function does **not** skip `undefined` elements and is thus not optimized for sparse arrays.
67+
68+
</section>
69+
70+
<!-- /.notes -->
71+
72+
<!-- Package usage examples. -->
73+
74+
<section class="examples">
75+
76+
## Examples
77+
78+
<!-- eslint no-undef: "error" -->
79+
80+
```javascript
81+
var uniform = require( '@stdlib/random/array/uniform' );
82+
var Complex128Array = require( '@stdlib/array/complex128' );
83+
var hasAlmostEqualValues = require( '@stdlib/array/base/assert/has-almost-equal-values' );
84+
85+
var buf = uniform( 10, 0, 10 );
86+
// returns <Float64Array>
87+
88+
var x = new Complex128Array( buf );
89+
// returns <Complex128Array>
90+
91+
var y = new Complex128Array( buf );
92+
// returns <Complex128Array>
93+
94+
var out = hasAlmostEqualValues( x, y, 1 );
95+
// returns true
96+
```
97+
98+
</section>
99+
100+
<!-- /.examples -->
101+
102+
<!-- 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. -->
103+
104+
<section class="references">
105+
106+
</section>
107+
108+
<!-- /.references -->
109+
110+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
111+
112+
<section class="related">
113+
114+
</section>
115+
116+
<!-- /.related -->
117+
118+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
119+
120+
<section class="links">
121+
122+
</section>
123+
124+
<!-- /.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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
26+
var zeros = require( './../../../../base/zeros' );
27+
var pkg = require( './../package.json' ).name;
28+
var hasAlmostEqualValues = 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 = hasAlmostEqualValues( x, x, 1 );
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: 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 equal
4+
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 equal.
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 equal 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 equal
36+
*
37+
* @example
38+
* var x = [ 0, 0, 1, 0 ];
39+
* var y = [ 0, 0, 1, 0 ];
40+
*
41+
* var out = hasAlmostEqualValues( x, y, 0 );
42+
* // returns true
43+
*/
44+
declare function hasAlmostEqualValues<T = unknown, U = unknown>( x: Collection<T> | AccessorArrayLike<T>, y: Collection<U> | AccessorArrayLike<U>, maxULP: number ): boolean;
45+
46+
47+
// EXPORTS //
48+
49+
export = hasAlmostEqualValues;

0 commit comments

Comments
 (0)