.. Copyright (c) 2024 Graphcore Ltd. All rights reserved. .. note:: Check the version number of this documentation against the `gfloat` version you are using. "Latest" refers to the head on https://github.com/graphcore-research/gfloat, while pypi versions installed using `pip install` will have corresponding `vX.Y.Z` tags. GFloat: Generic floating point formats in Python ================================================ GFloat is designed to allow experimentation with a variety of floating-point formats in Python. Headline features: * A wide variety of floating point formats defined in :py:class:`gfloat.formats` - IEEE 754, BFloat, OCP FP8 and MX, IEEE P3109 * Conversion between floats under numerous rounding modes - Scalar code is optimized for readability - Array code is faster, and can operate on Numpy, JAX, or PyTorch arrays. * Notebooks useful for teaching and exploring float formats Provided Formats ---------------- Formats are parameterized by the primary IEEE-754 parameters of: * Width in bits (k) * Precision (p) * Maximum exponent (emax) with additional fields defining the presence/encoding of: * Infinities * Not-a-number (NaN) values * Negative zero * Subnormal numbers * Signed/unsigned * Two's complement encoding (of the significand) This allows an implementation of generic floating point encode/decode logic, handling various current and proposed floating point types: - `IEEE 754 `_: Binary16, Binary32 - `Brain floating point `_: BFloat16 - |ocp_link|: E5M2, E4M3 - |p3109_link|: P{p} for p in 1..7 - Types from the |ocp_mx_link| spec: E8M0, INT8, and FP4, FP6 types As well as block formats from |ocp_mx_link|. .. |ocp_mx_link| raw:: html OCP MX .. |ocp_link| raw:: html OCP Float8 .. |p3109_link| raw:: html IEEE P3109 Rounding modes -------------- Various rounding modes: * Directed modes: Toward Zero, Toward Positive, Toward Negative * Round-to-nearest, with Ties to Even or Ties to Away * Stochastic rounding, with specified numbers of random bits See Also -------- GFloat, being a pure Python library, favours readability and extensibility over speed (although the `*_ndarray` functions are reasonably fast for large arrays). For fast implementations of these datatypes see, for example, `ml_dtypes `_, `bitstring `_, `MX PyTorch Emulation Library `_, `APyTypes `_. To get started with the library, we recommend perusing the notebooks, otherwise you may wish to jump straight into the API. Contents ======== .. toctree:: :hidden: self .. toctree:: notebooks api formats Index and Search ================ * :ref:`genindex` * :ref:`search`