-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
38 lines (31 loc) · 1.32 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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']