MCPcopy Create free account
hub / github.com/numpy/numpy / assert_array_max_ulp

Function assert_array_max_ulp

numpy/testing/_private/utils.py:1571–1620  ·  view source on GitHub ↗

Check that all items of arrays differ in at most N Units in the Last Place. Parameters ---------- a, b : array_like Input arrays to be compared. maxulp : int, optional The maximum number of units in the last place that elements of `a` and `b` can differ.

(a, b, maxulp=1, dtype=None)

Source from the content-addressed store, hash-verified

1569
1570
1571def assert_array_max_ulp(a, b, maxulp=1, dtype=None):
1572 """
1573 Check that all items of arrays differ in at most N Units in the Last Place.
1574
1575 Parameters
1576 ----------
1577 a, b : array_like
1578 Input arrays to be compared.
1579 maxulp : int, optional
1580 The maximum number of units in the last place that elements of `a` and
1581 `b` can differ. Default is 1.
1582 dtype : dtype, optional
1583 Data-type to convert `a` and `b` to if given. Default is None.
1584
1585 Returns
1586 -------
1587 ret : ndarray
1588 Array containing number of representable floating point numbers between
1589 items in `a` and `b`.
1590
1591 Raises
1592 ------
1593 AssertionError
1594 If one or more elements differ by more than `maxulp`.
1595
1596 Notes
1597 -----
1598 For computing the ULP difference, this API does not differentiate between
1599 various representations of NAN (ULP difference between 0x7fc00000 and 0xffc00000
1600 is zero).
1601
1602 See Also
1603 --------
1604 assert_array_almost_equal_nulp : Compare two arrays relatively to their
1605 spacing.
1606
1607 Examples
1608 --------
1609 >>> a = np.linspace(0., 1., 100)
1610 >>> res = np.testing.assert_array_max_ulp(a, np.arcsin(np.sin(a)))
1611
1612 """
1613 __tracebackhide__ = True # Hide traceback for py.test
1614 import numpy as np
1615 ret = nulp_diff(a, b, dtype)
1616 if not np.all(ret <= maxulp):
1617 raise AssertionError("Arrays are not almost equal up to %g "
1618 "ULP (max difference is %g ULP)" %
1619 (maxulp, np.max(ret)))
1620 return ret
1621
1622
1623def nulp_diff(x, y, dtype=None):

Callers 15

test_arrayMethod · 0.90
test_avx_based_ufuncMethod · 0.90
test_exp_float32Method · 0.90
test_log_float32Method · 0.90
test_sincos_float32Method · 0.90
test_emptyMethod · 0.90
test_emptyMethod · 0.90

Calls 3

nulp_diffFunction · 0.85
allMethod · 0.45
maxMethod · 0.45

Tested by 15

test_arrayMethod · 0.72
test_avx_based_ufuncMethod · 0.72
test_exp_float32Method · 0.72
test_log_float32Method · 0.72
test_sincos_float32Method · 0.72
test_emptyMethod · 0.72
test_emptyMethod · 0.72