diff options
author | David Cournapeau <cournape@gmail.com> | 2009-11-10 09:34:28 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2009-11-10 09:34:28 +0000 |
commit | cbe4c80dda4c93bd69ce7a7c4f65f21cd8e38890 (patch) | |
tree | 5418f56501e89d1e4f5c5547ffb4b9168de03a8e | |
parent | dc6e5983b2d1dc9858ed9356eaf119a29d72ba37 (diff) | |
download | numpy-cbe4c80dda4c93bd69ce7a7c4f65f21cd8e38890.tar.gz |
ENH: make spacing available as a ufunc.
-rw-r--r-- | numpy/core/code_generators/generate_umath.py | 5 | ||||
-rw-r--r-- | numpy/core/code_generators/ufunc_docstrings.py | 28 | ||||
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 9 | ||||
-rw-r--r-- | numpy/core/src/umath/loops.h | 21 | ||||
-rw-r--r-- | numpy/core/src/umath/loops.h.src | 4 |
5 files changed, 56 insertions, 11 deletions
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py index 49f2f23d6..c2f1450f7 100644 --- a/numpy/core/code_generators/generate_umath.py +++ b/numpy/core/code_generators/generate_umath.py @@ -665,6 +665,11 @@ defdict = { docstrings.get('numpy.core.umath.nextafter'), TD(flts), ), +'spacing' : + Ufunc(1, 1, None, + docstrings.get('numpy.core.umath.spacing'), + TD(flts), + ), 'modf' : Ufunc(1, 2, None, docstrings.get('numpy.core.umath.modf'), diff --git a/numpy/core/code_generators/ufunc_docstrings.py b/numpy/core/code_generators/ufunc_docstrings.py index 7ccf3f5e8..9b4501469 100644 --- a/numpy/core/code_generators/ufunc_docstrings.py +++ b/numpy/core/code_generators/ufunc_docstrings.py @@ -2811,6 +2811,34 @@ add_newdoc('numpy.core.umath', 'nextafter', True """) +add_newdoc('numpy.core.umath', 'spacing', + """ + Return the distance between x and the nearest adjacent number. + + Parameters + ---------- + x1: array_like + Values to find the spacing of. + + Returns + ------- + out : array_like + The spacing of values of `x1`. + + Examples + -------- + >>> np.spacing(1, 2) == np.finfo(np.float64).eps + True + + Note + ---- + It can be considered as a generalization of EPS: spacing(np.float64(1)) == + np.finfo(np.float64).eps, and there should not be any representable number + between x + spacing(x) and x for any finite x. + + spacing of +- inf and nan is nan. + """) + add_newdoc('numpy.core.umath', 'sin', """ Trigonometric sine, element-wise. diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index 74404aa99..6efd30c0c 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -1096,6 +1096,15 @@ NPY_NO_EXPORT void /**end repeat1**/ NPY_NO_EXPORT void +@TYPE@_spacing(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)) +{ + UNARY_LOOP { + const @type@ in1 = *(@type@ *)ip1; + *((@type@ *)op1) = npy_spacing@c@(in1); + } +} + +NPY_NO_EXPORT void @TYPE@_copysign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)) { BINARY_LOOP { diff --git a/numpy/core/src/umath/loops.h b/numpy/core/src/umath/loops.h index 0cf88303d..48aa7ff5b 100644 --- a/numpy/core/src/umath/loops.h +++ b/numpy/core/src/umath/loops.h @@ -1611,6 +1611,10 @@ FLOAT_copysign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func NPY_NO_EXPORT void FLOAT_nextafter(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); +#line 210 +NPY_NO_EXPORT void +FLOAT_spacing(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); + #line 218 NPY_NO_EXPORT void @@ -1760,6 +1764,10 @@ DOUBLE_copysign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(fun NPY_NO_EXPORT void DOUBLE_nextafter(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); +#line 210 +NPY_NO_EXPORT void +DOUBLE_spacing(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); + #line 218 NPY_NO_EXPORT void @@ -1909,6 +1917,10 @@ LONGDOUBLE_copysign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED NPY_NO_EXPORT void LONGDOUBLE_nextafter(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); +#line 210 +NPY_NO_EXPORT void +LONGDOUBLE_spacing(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); + #line 218 NPY_NO_EXPORT void @@ -2080,9 +2092,6 @@ NPY_NO_EXPORT void CFLOAT_absolute(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); NPY_NO_EXPORT void -CFLOAT__arg(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); - -NPY_NO_EXPORT void CFLOAT_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); #line 372 @@ -2196,9 +2205,6 @@ NPY_NO_EXPORT void CDOUBLE_absolute(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); NPY_NO_EXPORT void -CDOUBLE__arg(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); - -NPY_NO_EXPORT void CDOUBLE_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); #line 372 @@ -2312,9 +2318,6 @@ NPY_NO_EXPORT void CLONGDOUBLE_absolute(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); NPY_NO_EXPORT void -CLONGDOUBLE__arg(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); - -NPY_NO_EXPORT void CLONGDOUBLE_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); #line 372 diff --git a/numpy/core/src/umath/loops.h.src b/numpy/core/src/umath/loops.h.src index f99c99cfd..3fc8ecbf6 100644 --- a/numpy/core/src/umath/loops.h.src +++ b/numpy/core/src/umath/loops.h.src @@ -204,8 +204,8 @@ NPY_NO_EXPORT void @TYPE@_logical_not(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); /**begin repeat1 - * #kind = isnan, isinf, isfinite, signbit, copysign, nextafter# - * #func = npy_isnan, npy_isinf, npy_isfinite, npy_signbit, npy_copysign, nextafter# + * #kind = isnan, isinf, isfinite, signbit, copysign, nextafter, spacing# + * #func = npy_isnan, npy_isinf, npy_isfinite, npy_signbit, npy_copysign, nextafter, spacing# **/ NPY_NO_EXPORT void @TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func)); |