This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / _external / array_api_extra / testing / assert_close_nulp

function

scipy._external.array_api_extra.testing:assert_close_nulp

source: build-install/usr/lib/python3.14/site-packages/scipy/_external/array_api_extra/testing.py:957

Signature

def assert_close_nulp(actual: Array, desired: Array, *, nulp: int = 1, check_dtype: bool = True, check_shape: bool = True, check_scalar: bool = False, check_device: bool = True, xp: ArrayNamespace | None = None) → None

Summary

Compare two arrays relatively to their spacing.

Extended Summary

This is an interface to numpy.testing.assert_array_almost_equal_nulp which accepts any standard-compatible array and performs additional array namespace, shape, and dtype checks.

Parameters

actual : Array

The array produced by the tested function.

desired : Array

The expected array (typically hardcoded).

nulp : int, optional

The maximum number of units in the last place for the tolerance check. Default: 1.

check_dtype : bool, default: True

Whether to check agreement between actual and desired dtypes.

check_shape : bool, default: True

Whether to check agreement between actual and desired shapes.

check_scalar : bool, default: False

NumPy only: whether to check agreement between actual and desired types — 0-D numpy.ndarray vs scalar (e.g. numpy.double).

check_device : bool, default: True

Whether to check agreement between actual and desired devices.

xp : array_namespace, optional

A standard-compatible namespace which actual and desired must match.

Raises

: AssertionError

If the spacing between actual and desired for one or more elements is larger than nulp.

: ImportError

If numpy is not importable in the Python environment.

Notes

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

An assertion is raised if the following condition is not met

abs(actual - desired) <= nulp * spacing(maximum(abs(actual), abs(desired)))

where spacing(x) is the distance between x and the nearest adjacent number representable by in the data type of x.

See also

assert_close

Similar function for inexact equality checks.

numpy.spacing

Spacing calculation for NumPy arrays.

numpy.testing.assert_array_almost_equal_nulp

Similar function for NumPy arrays.

Aliases

  • scipy.differentiate.xpx.testing.assert_close_nulp