MCPcopy Create free account
hub / github.com/google-deepmind/chex / _bfloat16_nulp_diff

Function _bfloat16_nulp_diff

chex/_src/asserts.py:1725–1736  ·  view source on GitHub ↗

Number of representable bf16 points between each item in x and y.

(x: np.ndarray, y: np.ndarray)

Source from the content-addressed store, hash-verified

1723
1724
1725def _bfloat16_nulp_diff(x: np.ndarray, y: np.ndarray) -> np.ndarray:
1726 """Number of representable bf16 points between each item in x and y."""
1727 rx = x.view(np.int16)
1728 ry = y.view(np.int16)
1729 # The constant for two's complement adjustment, same as for float16.
1730 comp = np.int16(-(2**15))
1731 # Transform the integer representations of negative numbers, to make the
1732 # integer representation monotonic across the full range of floats.
1733 rx = np.where(rx < 0, comp - rx, rx)
1734 ry = np.where(ry < 0, comp - ry, ry)
1735 diff = np.abs(rx.astype(np.int32) - ry.astype(np.int32))
1736 return diff.astype(np.float64)
1737
1738
1739def _assert_trees_all_close_ulp_static(

Callers 1

assert_fnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…