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)
| 1846 | |
| 1847 | |
| 1848 | def assert_array_max_ulp(a, b, maxulp=1, dtype=None): |
| 1849 | """ |
| 1850 | Check that all items of arrays differ in at most N Units in the Last Place. |
| 1851 | |
| 1852 | Parameters |
| 1853 | ---------- |
| 1854 | a, b : array_like |
| 1855 | Input arrays to be compared. |
| 1856 | maxulp : int, optional |
| 1857 | The maximum number of units in the last place that elements of `a` and |
| 1858 | `b` can differ. Default is 1. |
| 1859 | dtype : dtype, optional |
| 1860 | Data-type to convert `a` and `b` to if given. Default is None. |
| 1861 | |
| 1862 | Returns |
| 1863 | ------- |
| 1864 | ret : ndarray |
| 1865 | Array containing number of representable floating point numbers between |
| 1866 | items in `a` and `b`. |
| 1867 | |
| 1868 | Raises |
| 1869 | ------ |
| 1870 | AssertionError |
| 1871 | If one or more elements differ by more than `maxulp`. |
| 1872 | |
| 1873 | Notes |
| 1874 | ----- |
| 1875 | For computing the ULP difference, this API does not differentiate between |
| 1876 | various representations of NAN (ULP difference between 0x7fc00000 and 0xffc00000 |
| 1877 | is zero). |
| 1878 | |
| 1879 | See Also |
| 1880 | -------- |
| 1881 | assert_array_almost_equal_nulp : Compare two arrays relatively to their |
| 1882 | spacing. |
| 1883 | |
| 1884 | Examples |
| 1885 | -------- |
| 1886 | >>> a = np.linspace(0., 1., 100) |
| 1887 | >>> res = np.testing.assert_array_max_ulp(a, np.arcsin(np.sin(a))) |
| 1888 | |
| 1889 | """ |
| 1890 | __tracebackhide__ = True # Hide traceback for py.test |
| 1891 | import numpy as np |
| 1892 | ret = nulp_diff(a, b, dtype) |
| 1893 | if not np.all(ret <= maxulp): |
| 1894 | raise AssertionError(f"Arrays are not almost equal up to {maxulp:g} " |
| 1895 | f"ULP (max difference is {np.max(ret):g} ULP)") |
| 1896 | return ret |
| 1897 | |
| 1898 | |
| 1899 | def nulp_diff(x, y, dtype=None): |
searching dependent graphs…