diff options
author | David Cournapeau <cournape@gmail.com> | 2008-08-25 22:05:29 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2008-08-25 22:05:29 +0000 |
commit | 4406a13523c045e6af5f066b2d07981316acef70 (patch) | |
tree | bdb2331f6e430de913094489cd8e37c8b9e4b5a7 /numpy/core | |
parent | 5b38878bd94d755d72441cf1849a433b6971dd6c (diff) | |
download | numpy-4406a13523c045e6af5f066b2d07981316acef70.tar.gz |
Add a trunc function in umath module.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/code_generators/docstrings.py | 25 | ||||
-rw-r--r-- | numpy/core/code_generators/generate_umath.py | 6 | ||||
-rw-r--r-- | numpy/core/src/arrayobject.c | 3 | ||||
-rw-r--r-- | numpy/core/src/umathmodule.c.src | 2 |
4 files changed, 35 insertions, 1 deletions
diff --git a/numpy/core/code_generators/docstrings.py b/numpy/core/code_generators/docstrings.py index ae5643e20..7c5aeae26 100644 --- a/numpy/core/code_generators/docstrings.py +++ b/numpy/core/code_generators/docstrings.py @@ -689,6 +689,31 @@ add_newdoc('numpy.core.umath', 'ceil', """) +add_newdoc('numpy.core.umath', 'trunc', + """ + Return the truncated value of the input, element-wise. + + The truncated value of the scalar `x` is the nearest integer `i`, such + that i is not larger than x amplitude + + Parameters + ---------- + x : array_like + Input data. + + Returns + ------- + y : {ndarray, scalar} + The truncated value of each element in `x`. + + Examples + -------- + >>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0]) + >>> np.ceil(a) + array([-1., -1., -0., 0., 1., 1., 2.]) + + """) + add_newdoc('numpy.core.umath', 'conjugate', """ Return the complex conjugate, element-wise. diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py index ba57d53e0..6a36d6add 100644 --- a/numpy/core/code_generators/generate_umath.py +++ b/numpy/core/code_generators/generate_umath.py @@ -476,6 +476,12 @@ defdict = { TD(flts, f='ceil'), TD(M, f='ceil'), ), +'trunc' : + Ufunc(1, 1, None, + docstrings.get('numpy.core.umath.trunc'), + TD(flts, f='trunc'), + TD(M, f='trunc'), + ), 'fabs' : Ufunc(1, 1, None, docstrings.get('numpy.core.umath.fabs'), diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index ad3cbc4f2..586e7081a 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -3351,6 +3351,7 @@ typedef struct { *logical_and, *floor, *ceil, + *trunc, *maximum, *minimum, *rint, @@ -3408,6 +3409,7 @@ PyArray_SetNumericOps(PyObject *dict) SET(logical_and); SET(floor); SET(ceil); + SET(trunc); SET(maximum); SET(minimum); SET(rint); @@ -3458,6 +3460,7 @@ PyArray_GetNumericOps(void) GET(logical_and); GET(floor); GET(ceil); + GET(trunc); GET(maximum); GET(minimum); GET(rint); diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src index 6bc26f2d0..1517449a6 100644 --- a/numpy/core/src/umathmodule.c.src +++ b/numpy/core/src/umathmodule.c.src @@ -333,7 +333,7 @@ trunc (double x) double y, r; if (x < 0) { - return - floor(-x); + return - floor(-x); } else { return x; } |