diff options
author | Mark Wiebe <mwwiebe@gmail.com> | 2010-11-10 17:08:45 -0800 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2010-12-01 20:02:15 -0700 |
commit | 9b72aa96cec9d182062f378fca869aaa303f1ca9 (patch) | |
tree | 15a2a98c221552c2306bbc4edf2aacdd9533c6f1 | |
parent | 632ba9b0cfc07ef7ca49fedc698ebfd3a9031be2 (diff) | |
download | numpy-9b72aa96cec9d182062f378fca869aaa303f1ca9.tar.gz |
DOC: core: Update docs for half/float16 type
-rw-r--r-- | doc/source/reference/arrays.dtypes.rst | 2 | ||||
-rw-r--r-- | doc/source/reference/arrays.scalars.rst | 4 | ||||
-rw-r--r-- | doc/source/reference/c-api.coremath.rst | 201 | ||||
-rw-r--r-- | doc/source/reference/c-api.dtype.rst | 14 | ||||
-rw-r--r-- | doc/source/reference/c-api.ufunc.rst | 34 | ||||
-rw-r--r-- | doc/source/reference/figures/dtype-hierarchy.dia | bin | 4332 -> 4728 bytes | |||
-rw-r--r-- | doc/source/reference/figures/dtype-hierarchy.png | bin | 131045 -> 18746 bytes | |||
-rw-r--r-- | doc/source/reference/ufuncs.rst | 56 | ||||
-rw-r--r-- | doc/source/user/c-info.beyond-basics.rst | 2 | ||||
-rw-r--r-- | numpy/core/include/numpy/halffloat.h | 2 | ||||
-rw-r--r-- | numpy/doc/basics.py | 2 | ||||
-rw-r--r-- | numpy/doc/structured_arrays.py | 4 |
12 files changed, 273 insertions, 48 deletions
diff --git a/doc/source/reference/arrays.dtypes.rst b/doc/source/reference/arrays.dtypes.rst index c1b09f609..c89a282f4 100644 --- a/doc/source/reference/arrays.dtypes.rst +++ b/doc/source/reference/arrays.dtypes.rst @@ -137,7 +137,7 @@ What can be converted to a data-type object is described below: Array-scalar types - The 21 built-in :ref:`array scalar type objects + The 24 built-in :ref:`array scalar type objects <arrays.scalars.built-in>` all convert to an associated data-type object. This is true for their sub-classes as well. diff --git a/doc/source/reference/arrays.scalars.rst b/doc/source/reference/arrays.scalars.rst index 62e22146a..001227af4 100644 --- a/doc/source/reference/arrays.scalars.rst +++ b/doc/source/reference/arrays.scalars.rst @@ -12,7 +12,7 @@ convenient in applications that don't need to be concerned with all the ways data can be represented in a computer. For scientific computing, however, more control is often needed. -In NumPy, there are 21 new fundamental Python types to describe +In NumPy, there are 24 new fundamental Python types to describe different types of scalars. These type descriptors are mostly based on the types available in the C language that CPython is written in, with several additional types compatible with Python's types. @@ -138,10 +138,12 @@ Unsigned integers: Floating-point numbers: =================== ============================= =============== +:class:`half` ``'j'`` :class:`single` compatible: C float ``'f'`` :class:`double` compatible: C double :class:`float_` compatible: Python float ``'d'`` :class:`longfloat` compatible: C long float ``'g'`` +:class:`float16` 16 bits :class:`float32` 32 bits :class:`float64` 64 bits :class:`float96` 96 bits, platform? diff --git a/doc/source/reference/c-api.coremath.rst b/doc/source/reference/c-api.coremath.rst index 5c50f36e4..6584f216d 100644 --- a/doc/source/reference/c-api.coremath.rst +++ b/doc/source/reference/c-api.coremath.rst @@ -18,7 +18,7 @@ library contains most math-related C99 functionality, which can be used on platforms where C99 is not well supported. The core math functions have the same API as the C99 ones, except for the npy_* prefix. -The available functions are defined in npy_math.h - please refer to this header +The available functions are defined in <numpy/npy_math.h> - please refer to this header when in doubt. Floating point classification @@ -55,7 +55,7 @@ Floating point classification This is a macro, and is equivalent to C99 isfinite: works for single, double and extended precision, and return a non 0 value is x is neither a - NaN or a infinity. + NaN nor an infinity. .. cfunction:: int npy_isinf(x) @@ -181,3 +181,200 @@ compile and link options to your extension in your setup.py: In other words, the usage of info is exactly the same as when using blas_info and co. + +Half-precision functions +~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 2.0.0 + +The header file <numpy/halffloat.h> provides functions to work with +IEEE 754-2008 16-bit floating point values. While this format is +not typically used for numerical computations, it is useful for +storing values which require floating point but do not need much precision. +It can also be used as an educational tool to understand the nature +of floating point round-off error. + +Like for other types, NumPy includes a typedef npy_half for the 16 bit +float. Unlike for most of the other types, you cannot use this as a +normal type in C, since is is a typedef for npy_uint16. For example, +1.0 looks like 0x3c00 to C, and if you do an equality comparison +between the different signed zeros, you will get -0.0 != 0.0 +(0x8000 != 0x0000), which is incorrect. + +For these reasons, NumPy provides an API to work with npy_half values +accessible by including <numpy/halffloat.h> and linking to 'npymath'. +For functions that are not provided directly, such as the arithmetic +operations, the preferred method is to convert to float +or double and back again, as in the following example. + +.. code-block:: c + + npy_half sum(int n, npy_half *array) { + float ret = 0; + while(n--) { + ret += npy_half_to_float(*array++); + } + return npy_float_to_half(ret); + } + +External Links: + +* `754-2008 IEEE Standard for Floating-Point Arithmetic`__ +* `Half-precision Float Wikipedia Article`__. +* `OpenGL Half Float Pixel Support`__ +* `The OpenEXR image format`__. + +__ http://ieeexplore.ieee.org/servlet/opac?punumber=4610933 +__ http://en.wikipedia.org/wiki/Half_precision_floating-point_format +__ http://www.opengl.org/registry/specs/ARB/half_float_pixel.txt +__ http://www.openexr.com/about.html + +.. cvar:: NPY_HALF_ZERO + + This macro is defined to positive zero. + +.. cvar:: NPY_HALF_PZERO + + This macro is defined to positive zero. + +.. cvar:: NPY_HALF_NZERO + + This macro is defined to negative zero. + +.. cvar:: NPY_HALF_ONE + + This macro is defined to 1.0. + +.. cvar:: NPY_HALF_NEGONE + + This macro is defined to -1.0. + +.. cvar:: NPY_HALF_PINF + + This macro is defined to +inf. + +.. cvar:: NPY_HALF_NINF + + This macro is defined to -inf. + +.. cvar:: NPY_HALF_NAN + + This macro is defined to a NaN value, guaranteed to have its sign bit unset. + +.. cfunction:: float npy_half_to_float(npy_half h) + + Converts a half-precision float to a single-precision float. + +.. cfunction:: double npy_half_to_double(npy_half h) + + Converts a half-precision float to a double-precision float. + +.. cfunction:: npy_half npy_float_to_half(float f) + + Converts a single-precision float to a half-precision float. The + value is rounded to the nearest representable half, with ties going + to the nearest even. If the value is too small or too big, the + system's floating point underflow or overflow bit will be set. + +.. cfunction:: npy_half npy_double_to_half(double d) + + Converts a double-precision float to a half-precision float. The + value is rounded to the nearest representable half, with ties going + to the nearest even. If the value is too small or too big, the + system's floating point underflow or overflow bit will be set. + +.. cfunction:: int npy_half_eq(npy_half h1, npy_half h2) + + Compares two half-precision floats (h1 == h2). + +.. cfunction:: int npy_half_ne(npy_half h1, npy_half h2) + + Compares two half-precision floats (h1 != h2). + +.. cfunction:: int npy_half_le(npy_half h1, npy_half h2) + + Compares two half-precision floats (h1 <= h2). + +.. cfunction:: int npy_half_lt(npy_half h1, npy_half h2) + + Compares two half-precision floats (h1 < h2). + +.. cfunction:: int npy_half_ge(npy_half h1, npy_half h2) + + Compares two half-precision floats (h1 >= h2). + +.. cfunction:: int npy_half_gt(npy_half h1, npy_half h2) + + Compares two half-precision floats (h1 > h2). + +.. cfunction:: int npy_half_eq_nonan(npy_half h1, npy_half h2) + + Compares two half-precision floats that are known to not be NaN (h1 == h2). If + a value is NaN, the result is undefined. + +.. cfunction:: int npy_half_lt_nonan(npy_half h1, npy_half h2) + + Compares two half-precision floats that are known to not be NaN (h1 < h2). If + a value is NaN, the result is undefined. + +.. cfunction:: int npy_half_le_nonan(npy_half h1, npy_half h2) + + Compares two half-precision floats that are known to not be NaN (h1 <= h2). If + a value is NaN, the result is undefined. + +.. cfunction:: int npy_half_iszero(npy_half h) + + Tests whether the half-precision float has a value equal to zero. This may be slightly + faster than calling npy_half_eq(h, NPY_ZERO). + +.. cfunction:: int npy_half_isnan(npy_half h) + + Tests whether the half-precision float is a NaN. + +.. cfunction:: int npy_half_isinf(npy_half h) + + Tests whether the half-precision float is plus or minus Inf. + +.. cfunction:: int npy_half_isfinite(npy_half h) + + Tests whether the half-precision float is finite (not NaN or Inf). + +.. cfunction:: int npy_half_signbit(npy_half h) + + Returns 1 is h is negative, 0 otherwise. + +.. cfunction:: npy_half npy_half_copysign(npy_half x, npy_half y) + + Returns the value of x with the sign bit copied from y. Works for any value, + including Inf and NaN. + +.. cfunction:: npy_half npy_half_spacing(npy_half h) + + This is the same for half-precision float as npy_spacing and npy_spacingf + described in the low-level floating point section. + +.. cfunction:: npy_half npy_half_nextafter(npy_half x, npy_half y) + + This is the same for half-precision float as npy_nextafter and npy_nextafterf + described in the low-level floating point section. + +.. cfunction:: npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f) + + Low-level function which converts a 32-bit single-precision float, stored + as a uint32, into a 16-bit half-precision float. + +.. cfunction:: npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d) + + Low-level function which converts a 64-bit double-precision float, stored + as a uint64, into a 16-bit half-precision float. + +.. cfunction:: npy_uint32 npy_halfbits_to_floatbits(npy_uint16 h) + + Low-level function which converts a 16-bit half-precision float + into a 32-bit single-precision float, stored as a uint32. + +.. cfunction:: npy_uint64 npy_halfbits_to_doublebits(npy_uint16 h) + + Low-level function which converts a 16-bit half-precision float + into a 64-bit double-precision float, stored as a uint64. + diff --git a/doc/source/reference/c-api.dtype.rst b/doc/source/reference/c-api.dtype.rst index 569a4ccb3..01f5260de 100644 --- a/doc/source/reference/c-api.dtype.rst +++ b/doc/source/reference/c-api.dtype.rst @@ -3,7 +3,7 @@ Data Type API .. sectionauthor:: Travis E. Oliphant -The standard array can have 21 different data types (and has some +The standard array can have 24 different data types (and has some support for adding your own types). These data types all have an enumerated type, an enumerated type-character, and a corresponding array scalar Python type object (placed in a hierarchy). There are @@ -25,15 +25,16 @@ select the precision desired. Enumerated Types ---------------- -There is a list of enumerated types defined providing the basic 21 +There is a list of enumerated types defined providing the basic 24 data types plus some useful generic names. Whenever the code requires a type number, one of these enumerated types is requested. The types are all called :cdata:`NPY_{NAME}` where ``{NAME}`` can be **BOOL**, **BYTE**, **UBYTE**, **SHORT**, **USHORT**, **INT**, **UINT**, **LONG**, **ULONG**, **LONGLONG**, **ULONGLONG**, - **FLOAT**, **DOUBLE**, **LONGDOUBLE**, **CFLOAT**, **CDOUBLE**, - **CLONGDOUBLE**, **OBJECT**, **STRING**, **UNICODE**, **VOID** + **HALF**, **FLOAT**, **DOUBLE**, **LONGDOUBLE**, **CFLOAT**, + **CDOUBLE**, **CLONGDOUBLE**, **DATETIME**, **TIMEDELTA**, + **OBJECT**, **STRING**, **UNICODE**, **VOID** **NTYPES**, **NOTYPE**, **USERDEF**, **DEFAULT_TYPE** @@ -44,8 +45,9 @@ is :cdata:`NPY_{NAME}LTR` where ``{NAME}`` can be **BOOL**, **BYTE**, **UBYTE**, **SHORT**, **USHORT**, **INT**, **UINT**, **LONG**, **ULONG**, **LONGLONG**, **ULONGLONG**, - **FLOAT**, **DOUBLE**, **LONGDOUBLE**, **CFLOAT**, **CDOUBLE**, - **CLONGDOUBLE**, **OBJECT**, **STRING**, **VOID** + **HALF**, **FLOAT**, **DOUBLE**, **LONGDOUBLE**, **CFLOAT**, + **CDOUBLE**, **CLONGDOUBLE**, **DATETIME**, **TIMEDELTA**, + **OBJECT**, **STRING**, **VOID** **INTP**, **UINTP** diff --git a/doc/source/reference/c-api.ufunc.rst b/doc/source/reference/c-api.ufunc.rst index 384a69cf7..27977de99 100644 --- a/doc/source/reference/c-api.ufunc.rst +++ b/doc/source/reference/c-api.ufunc.rst @@ -234,18 +234,27 @@ structure. .. cfunction:: void PyUFunc_G_G(char** args, npy_intp* dimensions, npy_intp* steps, void* func) +.. cfunction:: void PyUFunc_j_j(char** args, npy_intp* dimensions, + npy_intp* steps, void* func) + +.. cfunction:: void PyUFunc_j_j_As_f_f(char** args, npy_intp* dimensions, + npy_intp* steps, void* func) + +.. cfunction:: void PyUFunc_j_j_As_d_d(char** args, npy_intp* dimensions, + npy_intp* steps, void* func) + Type specific, core 1-d functions for ufuncs where each calculation is obtained by calling a function taking one input argument and returning one output. This function is passed in ``func``. The letters correspond to dtypechar's of the supported - data types ( ``f`` - float, ``d`` - double, ``g`` - long double, - ``F`` - cfloat, ``D`` - cdouble, ``G`` - clongdouble). The - argument *func* must support the same signature. The _As_X_X - variants assume ndarray's of one data type but cast the values to - use an underlying function that takes a different data type. Thus, - :cfunc:`PyUFunc_f_f_As_d_d` uses ndarrays of data type :cdata:`NPY_FLOAT` - but calls out to a C-function that takes double and returns - double. + data types ( ``j`` - half, ``f`` - float, ``d`` - double, + ``g`` - long double, ``F`` - cfloat, ``D`` - cdouble, + ``G`` - clongdouble). The argument *func* must support the same + signature. The _As_X_X variants assume ndarray's of one data type + but cast the values to use an underlying function that takes a + different data type. Thus, :cfunc:`PyUFunc_f_f_As_d_d` uses + ndarrays of data type :cdata:`NPY_FLOAT` but calls out to a + C-function that takes double and returns double. .. cfunction:: void PyUFunc_ff_f_As_dd_d(char** args, npy_intp* dimensions, npy_intp* steps, void* func) @@ -271,6 +280,15 @@ structure. .. cfunction:: void PyUFunc_GG_G(char** args, npy_intp* dimensions, npy_intp* steps, void* func) +.. cfunction:: void PyUFunc_jj_j(char** args, npy_intp* dimensions, + npy_intp* steps, void* func) + +.. cfunction:: void PyUFunc_jj_j_As_ff_f(char** args, npy_intp* dimensions, + npy_intp* steps, void* func) + +.. cfunction:: void PyUFunc_jj_j_As_dd_d(char** args, npy_intp* dimensions, + npy_intp* steps, void* func) + Type specific, core 1-d functions for ufuncs where each calculation is obtained by calling a function taking two input arguments and returning one output. The underlying function to diff --git a/doc/source/reference/figures/dtype-hierarchy.dia b/doc/source/reference/figures/dtype-hierarchy.dia Binary files differindex 65379b880..62e925cfd 100644 --- a/doc/source/reference/figures/dtype-hierarchy.dia +++ b/doc/source/reference/figures/dtype-hierarchy.dia diff --git a/doc/source/reference/figures/dtype-hierarchy.png b/doc/source/reference/figures/dtype-hierarchy.png Binary files differindex 5722ac527..6c45758b1 100644 --- a/doc/source/reference/figures/dtype-hierarchy.png +++ b/doc/source/reference/figures/dtype-hierarchy.png diff --git a/doc/source/reference/ufuncs.rst b/doc/source/reference/ufuncs.rst index 77269be58..680232a36 100644 --- a/doc/source/reference/ufuncs.rst +++ b/doc/source/reference/ufuncs.rst @@ -207,7 +207,7 @@ implemented by the question of when a data type can be cast "safely" to another data type. The answer to this question can be determined in Python with a function call: :func:`can_cast(fromtype, totype) <can_cast>`. The Figure below shows the results of this call for -the 21 internally supported types on the author's 32-bit system. You +the 24 internally supported types on the author's 64-bit system. You can generate this table for your system with the code given in the Figure. .. admonition:: Figure @@ -224,34 +224,38 @@ can generate this table for your system with the code given in the Figure. ... print int(np.can_cast(row, col)), ... print >>> print_table(np.typecodes['All']) - X ? b h i l q p B H I L Q P f d g F D G S U V O - ? 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - b 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 - h 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 - i 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 - l 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 - q 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 - p 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 - B 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - H 0 0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - I 0 0 0 0 0 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 1 1 - L 0 0 0 0 0 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 1 1 - Q 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 1 1 1 1 - P 0 0 0 0 0 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 1 1 - f 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 - d 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 - g 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 - F 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 - D 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 - G 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 - S 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 - U 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 - V 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 - O 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 + X ? b h i l q p B H I L Q P j f d g F D G S U V O M m + ? 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + b 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 + h 0 0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 + i 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0 + l 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0 + q 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0 + p 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0 + B 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 + H 0 0 0 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 0 + I 0 0 0 0 1 1 1 0 0 1 1 1 1 0 0 1 1 0 1 1 1 1 1 1 0 0 + L 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 1 1 1 1 1 1 0 0 + Q 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 1 1 1 1 1 1 0 0 + P 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 1 1 0 1 1 1 1 1 1 0 0 + j 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 + f 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 + d 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 0 + g 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 0 0 + F 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 + D 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 + G 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 + S 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 + U 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 + V 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 + O 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 + M 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 + m 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 + You should note that, while included in the table for completeness, the 'S', 'U', and 'V' types cannot be operated on by ufuncs. Also, -note that on a 64-bit system the integer types may have different +note that on a 32-bit system the integer types may have different sizes, resulting in a slightly altered table. Mixed scalar-array operations use a different set of casting rules diff --git a/doc/source/user/c-info.beyond-basics.rst b/doc/source/user/c-info.beyond-basics.rst index 563467e72..5ff92a122 100644 --- a/doc/source/user/c-info.beyond-basics.rst +++ b/doc/source/user/c-info.beyond-basics.rst @@ -389,7 +389,7 @@ register ufuncs for user-defined data-types. User-defined data-types ======================= -NumPy comes with 21 builtin data-types. While this covers a large +NumPy comes with 24 builtin data-types. While this covers a large majority of possible use cases, it is conceivable that a user may have a need for an additional data-type. There is some support for adding an additional data-type into the NumPy system. This additional data- diff --git a/numpy/core/include/numpy/halffloat.h b/numpy/core/include/numpy/halffloat.h index a4d2b335d..c6bb726bc 100644 --- a/numpy/core/include/numpy/halffloat.h +++ b/numpy/core/include/numpy/halffloat.h @@ -35,8 +35,8 @@ int npy_half_isnan(npy_half h); int npy_half_isinf(npy_half h); int npy_half_isfinite(npy_half h); int npy_half_signbit(npy_half h); -npy_half npy_half_spacing(npy_half h); npy_half npy_half_copysign(npy_half x, npy_half y); +npy_half npy_half_spacing(npy_half h); npy_half npy_half_nextafter(npy_half x, npy_half y); /* diff --git a/numpy/doc/basics.py b/numpy/doc/basics.py index ea651bbc7..97e982204 100644 --- a/numpy/doc/basics.py +++ b/numpy/doc/basics.py @@ -23,6 +23,8 @@ uint16 Unsigned integer (0 to 65535) uint32 Unsigned integer (0 to 4294967295) uint64 Unsigned integer (0 to 18446744073709551615) float Shorthand for ``float64``. +float16 Half precision float: sign bit, 5 bits exponent, + 10 bits mantissa float32 Single precision float: sign bit, 8 bits exponent, 23 bits mantissa float64 Double precision float: sign bit, 11 bits exponent, diff --git a/numpy/doc/structured_arrays.py b/numpy/doc/structured_arrays.py index 21fdf87ea..6eafd71cd 100644 --- a/numpy/doc/structured_arrays.py +++ b/numpy/doc/structured_arrays.py @@ -70,10 +70,10 @@ In this case, the constructor expects a comma-separated list of type specifiers, optionally with extra shape information. The type specifiers can take 4 different forms: :: - a) b1, i1, i2, i4, i8, u1, u2, u4, u8, f4, f8, c8, c16, a<n> + a) b1, i1, i2, i4, i8, u1, u2, u4, u8, f2, f4, f8, c8, c16, a<n> (representing bytes, ints, unsigned ints, floats, complex and fixed length strings of specified byte lengths) - b) int8,...,uint8,...,float32, float64, complex64, complex128 + b) int8,...,uint8,...,float16, float32, float64, complex64, complex128 (this time with bit sizes) c) older Numeric/numarray type specifications (e.g. Float32). Don't use these in new code! |