This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / testing / _private / utils / assert_array_almost_equal_nulp

function

numpy.testing._private.utils:assert_array_almost_equal_nulp

source: build-install/usr/lib/python3.14/site-packages/numpy/testing/_private/utils.py :1773

Signature

def   assert_array_almost_equal_nulp ( x y nulp = 1 )

Summary

Compare two arrays relatively to their spacing.

Extended Summary

This is a relatively robust method to compare two arrays whose amplitude is variable.

Parameters

x, y : array_like

Input arrays.

nulp : int, optional

The maximum number of unit in the last place for tolerance (see Notes). Default is 1.

Returns

: None

Raises

: AssertionError

If the spacing between x and y for one or more elements is larger than nulp.

Notes

An assertion is raised if the following condition is not met

abs(x - y) <= nulp * spacing(maximum(abs(x), abs(y)))

Examples

x = np.array([1., 1e-10, 1e-20])
eps = np.finfo(x.dtype).eps
np.testing.assert_array_almost_equal_nulp(x, x*eps/2 + x)
np.testing.assert_array_almost_equal_nulp(x, x*eps + x)

See also

assert_array_max_ulp

Check that all items of arrays differ in at most N Units in the Last Place.

spacing

Return the distance between x and the nearest adjacent number.

Aliases

  • numpy.testing.assert_array_almost_equal_nulp