scipp.allclose#
- scipp.allclose(x, y, rtol=None, atol=None, equal_nan=False)#
Checks if all elements in the inputs are close to each other.
Verifies that ALL element-wise comparisons meet the condition:
abs(x - y) <= atol + rtol * abs(y)
If both x and y have variances, the variances are also compared between elements. In this case, both values and variances must be within the computed tolerance limits. That is:
abs(x.value - y.value) <= atol + rtol * abs(y.value) and abs( sqrt(x.variance) - sqrt(y.variance)) <= atol + rtol * abs(sqrt(y.variance))
Attention
Vectors and matrices are compared element-wise. This is not necessarily a good measure for the similarity of spatial dtypes like
scipp.DType.rotation3orscipp.Dtype.affine_transform3(seescipp.spatial).- Parameters:
x (
Variable) – Left input.y (
Variable) – Right input.rtol (
Variable, default:None) – Tolerance value relative (to y). Can be a scalar or non-scalar. Cannot have variances. Defaults to scalar 1e-5 if unset.atol (
Variable, default:None) – Tolerance value absolute. Can be a scalar or non-scalar. Cannot have variances. Defaults to scalar 1e-8 if unset and takes units from y arg.equal_nan (
bool, default:False) – If true, non-finite values at the same index in (x, y) are treated as equal. Signbit must match for infs.
- Returns:
bool– True if for all elementsvalue <= atol + rtol * abs(y), otherwise False.
See also
scipp.iscloseCompares element-wise with specified tolerances.
Examples
Arrays that are close within default tolerances:
>>> import scipp as sc >>> x = sc.array(dims=['x'], values=[1.0, 2.0, 3.0], unit='m') >>> y = sc.array(dims=['x'], values=[1.0001, 2.0, 3.0001], unit='m') >>> sc.allclose(x, y) np.False_
Arrays with larger differences:
>>> z = sc.array(dims=['x'], values=[1.1, 2.0, 3.0], unit='m') >>> sc.allclose(x, z) np.False_