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. Formats are parameterized by the primary IEEE-754 parameters of:
Width in bits (k)
Precision (p)
Maximum exponent (emax)
with additional fields defining the encoding of infinities, Not-a-number (NaN) values,
and negative zero, among others (see gfloat.FormatInfo
.)
This allows an implementation of generic floating point encode/decode logic, handling various current and proposed floating point types:
IEEE 754: Binary16, Binary32
OCP Float8: E5M2, E4M3, and MX formats
IEEE WG P3109: P{p} for p in 1..7
The library favours readability and extensibility over speed - for fast implementations of these datatypes see, for example, ml_dtypes, bitstring, MX PyTorch Emulation Library.
To get started with the library, we recommend perusing the notebooks, otherwise you may wish to jump straight into the API.
- Notebooks
- API
- Functions
- Classes
FormatInfo
FormatInfo.name
FormatInfo.k
FormatInfo.precision
FormatInfo.emax
FormatInfo.has_nz
FormatInfo.has_infs
FormatInfo.num_high_nans
FormatInfo.has_subnormals
FormatInfo.is_signed
FormatInfo.is_twos_complement
FormatInfo.tSignificandBits
FormatInfo.expBits
FormatInfo.signBits
FormatInfo.expBias
FormatInfo.bits
FormatInfo.eps
FormatInfo.epsneg
FormatInfo.iexp
FormatInfo.machep
FormatInfo.max
FormatInfo.maxexp
FormatInfo.min
FormatInfo.num_nans
FormatInfo.code_of_nan
FormatInfo.code_of_posinf
FormatInfo.code_of_neginf
FormatInfo.code_of_zero
FormatInfo.has_zero
FormatInfo.code_of_negzero
FormatInfo.code_of_max
FormatInfo.code_of_min
FormatInfo.smallest_normal
FormatInfo.smallest_subnormal
FormatInfo.smallest
FormatInfo.is_all_subnormal
FloatClass
RoundMode
FloatValue
BlockFormatInfo
- Pretty printers
- Defined Formats