allclose#
- ivy.allclose(a, b, /, *, rtol=1e-05, atol=1e-08, equal_nan=False, out=None)[source]#
Return a True if the two arrays are element-wise equal within given tolerance; otherwise False.
The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(x2)) and the absolute difference atol are added together to compare against the absolute difference between x1 and x2. The default atol is not appropriate for comparing numbers that are much smaller than one
- Parameters:
x1 – First input array.
x2 – Second input array.
rtol (
float
, default:1e-05
) – The relative tolerance parameter.atol (
float
, default:1e-08
) – The absolute tolerance parameter.equal_nan (
bool
, default:False
) – Whether to compare NaN’s as equal. If True, NaN’s in x1 will be considered equal to NaN’s in x2 in the output array.out (
Optional
[Array
], default:None
) – Alternate output array in which to place the result. The default is None.
- Return type:
bool
- Returns:
ret – Returns True if the two arrays are equal within the given tolerance; False otherwise.
Examples
>>> x1 = ivy.array([1e10, 1e-7]) >>> x2 = ivy.array([1.00001e10, 1e-8]) >>> y = ivy.allclose(x1, x2) >>> print(y) ivy.array(False)
>>> x1 = ivy.array([1.0, ivy.nan]) >>> x2 = ivy.array([1.0, ivy.nan]) >>> y = ivy.allclose(x1, x2, equal_nan=True) >>> print(y) ivy.array(True)
>>> x1 = ivy.array([1e-10, 1e-10]) >>> x2 = ivy.array([1.00001e-10, 1e-10]) >>> y = ivy.allclose(x1, x2, rtol=0.005, atol=0.0) >>> print(y) ivy.array(True)
- Array.allclose(self, x2, /, *, rtol=1e-05, atol=1e-08, equal_nan=False, out=None)[source]#
ivy.Array instance method variant of ivy.allclose. This method simply wraps the function, and so the docstring for ivy.allclose also applies to this method with minimal changes.
- Parameters:
self (
Array
) – First input array.x2 (
Array
) – Second input array.rtol (
float
, default:1e-05
) – The relative tolerance parameter.atol (
float
, default:1e-08
) – The absolute tolerance parameter.equal_nan (
bool
, default:False
) – Whether to compare NaN’s as equal. If True, NaN’s in a will be considered equal to NaN’s in b in the output array.out (
Optional
[Container
], default:None
) – Alternate output array in which to place the result. The default is None.
- Return type:
bool
- Returns:
ret – Returns True if the two arrays are equal within the given tolerance; False otherwise.
Examples
>>> x1 = ivy.array([1e10, 1e-7]) >>> x2 = ivy.array([1.00001e10, 1e-8]) >>> y = x1.allclose(x2) >>> print(y) ivy.array(False)
>>> x1 = ivy.array([1.0, ivy.nan]) >>> x2 = ivy.array([1.0, ivy.nan]) >>> y = x1.allclose(x2, equal_nan=True) >>> print(y) ivy.array(True)
>>> x1 = ivy.array([1e-10, 1e-10]) >>> x2 = ivy.array([1.00001e-10, 1e-10]) >>> y = x1.allclose(x2, rtol=0.005, atol=0.0) >>> print(y) ivy.array(True)
- Container.allclose(self, x2, /, *, rtol=1e-05, atol=1e-08, equal_nan=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.allclose. This method simply wraps the function, and so the docstring for ivy.allclose also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Input container containing first input array.x2 (
Container
) – Input container containing second input array.rtol (
Union
[float
,Container
], default:1e-05
) – The relative tolerance parameter.atol (
Union
[float
,Container
], default:1e-08
) – The absolute tolerance parameter.equal_nan (
Union
[bool
,Container
], default:False
) – Whether to compare NaN’s as equal. If True, NaN’s in x1 will be considered equal to NaN’s in x2 in the output array.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.out (
Optional
[Container
], default:None
) – Alternate output array in which to place the result. The default is None.
- Return type:
Container
- Returns:
ret – A new container holding the result is returned unless out is specified, in which it is returned.
Examples
>>> x1 = ivy.Container(a=ivy.array([1., 2., 3.]), b=ivy.array([1., 2., 3.])) >>> x2 = ivy.Container(a=ivy.array([1., 2., 3.]), b=ivy.array([1., 2., 3.])) >>> y = x1.allclose(x2) >>> print(y) { a: ivy.array(True), b: ivy.array(True) }
>>> x1 = ivy.Container(a=ivy.array([1., 2., 3.]), ... b=ivy.array([1., 2., 3.])) >>> x2 = ivy.Container(a=ivy.array([1., 2., 3.0003]), ... b=ivy.array([1.0006, 2., 3.])) >>> y = x1.allclose(x2, rtol=1e-3) >>> print(y) { a: ivy.array(True), b: ivy.array(True) }