Fused multiply-add for Python
Fused multiply-add for Python.
Fused multiply-add computes
(x*y) + z with a single rounding. Useful for dot
products, matrix multiplications, polynomial evaluations (e.g., with Horner's rule),
Newton's method for evaluating functions, convolutions, artificial neural networks etc.
import pyfma out = pyfma.fma(3.0, 2.0, 1.0) # 3.0*2.0 + 1.0 = 7.0
Also works with NumPy inputs:
import numpy import pyfma x = numpy.random.rand(3, 4, 5) y = numpy.random.rand(3, 4, 5) z = numpy.random.rand(3, 4, 5) out = pyfma.fma(x, y, z)
Built with pybind11.
Caution The C/C++ implementation of FMA in MS Windows is reportedly broken. Use with care.
pyfma can be installed from the Python Package Index, so with
pip install pyfma
you can install/upgrade.
For manual installation (if you're a developer or just really keen on getting the bleeding edge version of pyfma), there are two possibilities:
- Get the sources, do
pip install .. This does the trick most the time.
- As a fallback, there's a CMake-based installation. Simply go
To run the pyfma unit tests, check out this repository and type
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.