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
- Scalar Functions
- Block format functions
- Classes
FormatInfoFormatInfo.nameFormatInfo.kFormatInfo.precisionFormatInfo.emaxFormatInfo.has_nzFormatInfo.has_infsFormatInfo.num_high_nansFormatInfo.has_subnormalsFormatInfo.is_signedFormatInfo.is_twos_complementFormatInfo.tSignificandBitsFormatInfo.expBitsFormatInfo.signBitsFormatInfo.expBiasFormatInfo.bitsFormatInfo.epsFormatInfo.epsnegFormatInfo.iexpFormatInfo.machepFormatInfo.maxFormatInfo.maxexpFormatInfo.minFormatInfo.num_nansFormatInfo.code_of_nanFormatInfo.code_of_posinfFormatInfo.code_of_neginfFormatInfo.code_of_zeroFormatInfo.has_zeroFormatInfo.code_of_negzeroFormatInfo.code_of_maxFormatInfo.code_of_minFormatInfo.smallest_normalFormatInfo.smallest_subnormalFormatInfo.smallestFormatInfo.is_all_subnormal
FloatClassRoundModeFloatValueBlockFormatInfo
- Pretty printers
- Defined Formats