diff --git a/.gitignore b/.gitignore index 197e8b4..f2c1f91 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,8 @@ _doc/examples/data/*.optimized.onnx _doc/examples/*.html _doc/_static/require.js _doc/_static/viz.js +_doc/LICENSE.txt +_doc/CHANGELOGS.rst _unittests/ut__main/*.png _unittests/ut__main/_cache/* _unittests/ut__main/*.html diff --git a/_doc/api/f8.rst b/_doc/api/f8.rst new file mode 100644 index 0000000..ad39fca --- /dev/null +++ b/_doc/api/f8.rst @@ -0,0 +1,5 @@ +Float 8 +======= + +.. automodule:: onnx_array_api.validation.f8 + :members: diff --git a/_doc/api/index.rst b/_doc/api/index.rst index c39b7c0..d52b616 100644 --- a/_doc/api/index.rst +++ b/_doc/api/index.rst @@ -20,3 +20,4 @@ API reference tools profiling + f8 diff --git a/_doc/conf.py b/_doc/conf.py index 7d55588..cd11655 100644 --- a/_doc/conf.py +++ b/_doc/conf.py @@ -122,9 +122,7 @@ "onnxruntime": "https://onnxruntime.ai/", "numpy": "https://numpy.org/", "numba": "https://numba.pydata.org/", - "onnx-array-api": ( - "http://www.xavierdupre.fr/app/onnx-array-api/helpsphinx/index.html" - ), + "onnx-array-api": ("https://sdpython.github.io/doc/onnx-array-api/dev/"), "pyinstrument": "https://github.com/joerick/pyinstrument", "python": "https://www.python.org/", "scikit-learn": "https://scikit-learn.org/stable/", diff --git a/_unittests/ut_validation/test_f8.py b/_unittests/ut_validation/test_f8.py index c50cfed..a05caef 100644 --- a/_unittests/ut_validation/test_f8.py +++ b/_unittests/ut_validation/test_f8.py @@ -1151,7 +1151,16 @@ def test_float8_e5m2fnuz_negative_nan(self): back = fe4m3_to_float32(to, fn=True, uz=True) self.assertTrue(numpy.isnan(back)) + def test_fe4m3fn_to_float32_bug(self): + cases = [(1.8131605, 1.875)] + for val, expected in cases: + with self.subTest(value=val, expected=expected): + res = fe4m3_to_float32(search_float32_into_fe4m3(val)) + self.assertEqual(expected, res) + res = fe4m3_to_float32(float32_to_fe4m3(val)) + self.assertEqual(expected, res) + if __name__ == "__main__": - TestF8().test_search_float32_into_fe4m3fn_simple() + TestF8().test_fe4m3fn_to_float32_bug() unittest.main(verbosity=2) diff --git a/onnx_array_api/validation/f8.py b/onnx_array_api/validation/f8.py index d95b3b3..649eab5 100644 --- a/onnx_array_api/validation/f8.py +++ b/onnx_array_api/validation/f8.py @@ -12,18 +12,17 @@ class UndefinedCastError(FloatingPointError): pass -def display_float32(value, sign=1, exponent=8, mantissa=23): +def display_int(ival, sign=1, exponent=8, mantissa=23): """ - Displays a float32 into b. + Displays an integer as bits. - :param value: value to display (float32) + :param ival: value to display (float32) :param sign: number of bits for the sign :param exponent: number of bits for the exponent :param mantissa: number of bits for the mantissa :return: string """ t = sign + exponent + mantissa - ival = int.from_bytes(struct.pack("> 20 - if m & 0x80000: + if (m & 0x80000) and ( + (m & 0x100000) or (m & 0x7FFFF) + ): # round to nearest even if (ret & 0x7F) < 0x7F: # rounding ret += 1 @@ -584,7 +591,7 @@ def float32_to_fe4m3(x, fn: bool = True, uz: bool = False, saturate: bool = True if (ret & 0x7F) == 0x7F: ret &= 0xFE if (m & 0x80000) and ( - (m & 0x100000) or (m & 0x7C000) + (m & 0x100000) or (m & 0x7FFFF) ): # round to nearest even if (ret & 0x7F) < 0x7E: # rounding @@ -642,7 +649,9 @@ def float32_to_fe5m2(x, fn: bool = False, uz: bool = False, saturate: bool = Tru ex = e - 111 # 127 - 16 ret |= ex << 2 ret |= m >> 21 - if m & 0x100000: + if m & 0x100000 and ( + (m & 0xFFFFF) or (m & 0x200000) + ): # round to nearest even if (ret & 0x7F) < 0x7F: # rounding ret += 1 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy