mwiebe/numpy_half
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This Python module adds half-precision floating point support to NumPy. In Python, all you have to do is 'import half', and a float16 type will be available in NumPy ('numpy.float16'). To build: $ python setup.py build To install (as root): # python setup.py install To install in your home directory (replace ... with the appropriate value and add the PYTHON path to ~/.bashrc or where is right for your setup): $ export PYTHONPATH=$PYTHONPATH:~/pymods/.../site-packages $ python setup.py install --prefix=~/pymods Here's some simple example usage: >>> import numpy as np, half >>> np.arange(10, dtype='float16') array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.], dtype=float16) >>> print np.finfo(np.float16) Machine parameters for float16 --------------------------------------------------------------------- precision= 3 resolution= 1.0004e-03 machep= -10 eps= 9.7656e-04 negep = -11 epsneg= 4.8828e-04 minexp= -14 tiny= 6.1035e-05 maxexp= 16 max= 6.5504e+04 nexp = 5 min= -max --------------------------------------------------------------------- >>> a = np.array([-np.inf, 0, 1, 3.14159], dtype='f2') >>> a array([ -Inf, 0. , 1. , 3.140625], dtype=float16) >>> ['%04x' % h for h in a.view(dtype='u2')] ['fc00', '0000', '3c00', '4248']
About
Half-precision floating point for NumPy
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published