Skip to content

Commit

Permalink
Merge pull request #247 from cpburnz/ceil-and-floor
Browse files Browse the repository at this point in the history
Support ceil() and floor() functions
  • Loading branch information
robbmcleod committed Apr 4, 2017
2 parents 640f7f3 + 06d24a3 commit d8bd211
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ Supported functions are listed below::
Complex from real and imaginary parts.
* contains(str, str): bool
Returns True for every string in `op1` that contains `op2`.
* ceil(float|double): float|double
Round up towards positive infinity to the closest integer.
* floor(float|double): float|double
Round down towards negative infinity to the closest integer.

.. Notes:
Expand Down
2 changes: 2 additions & 0 deletions numexpr/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ def multiply(x, y):
'expm1': func(numpy.expm1, 'float'),

'abs': func(numpy.absolute, 'float'),
'ceil': func(numpy.ceil, 'float', 'double'),
'floor': func(numpy.floor, 'float', 'double'),

'where': where_func,

Expand Down
4 changes: 4 additions & 0 deletions numexpr/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ FUNC_FF(FUNC_EXP_FF, "exp_ff", expf, expf2, vsExp)
FUNC_FF(FUNC_EXPM1_FF, "expm1_ff", expm1f, expm1f2, vsExpm1)
FUNC_FF(FUNC_ABS_FF, "absolute_ff", fabsf, fabsf2, vsAbs)
FUNC_FF(FUNC_CONJ_FF, "conjugate_ff",fconjf, fconjf2, vsConj)
FUNC_FF(FUNC_CEIL_FF, "ceil_ff", ceilf, ceilf2, NULL)
FUNC_FF(FUNC_FLOOR_FF, "floor_ff", floorf, floorf2, NULL)
FUNC_FF(FUNC_FF_LAST, NULL, NULL, NULL, NULL)
#ifdef ELIDE_FUNC_FF
#undef ELIDE_FUNC_FF
Expand Down Expand Up @@ -76,6 +78,8 @@ FUNC_DD(FUNC_EXP_DD, "exp_dd", exp, vdExp)
FUNC_DD(FUNC_EXPM1_DD, "expm1_dd", expm1, vdExpm1)
FUNC_DD(FUNC_ABS_DD, "absolute_dd", fabs, vdAbs)
FUNC_DD(FUNC_CONJ_DD, "conjugate_dd",fconj, vdConj)
FUNC_DD(FUNC_CEIL_DD, "ceil_dd", ceil, NULL)
FUNC_DD(FUNC_FLOOR_DD, "floor_dd", floor, NULL)
FUNC_DD(FUNC_DD_LAST, NULL, NULL, NULL)
#ifdef ELIDE_FUNC_DD
#undef ELIDE_FUNC_DD
Expand Down
9 changes: 9 additions & 0 deletions numexpr/msvc_function_stubs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define fabsf(x) ((float)fabs((double)(x)))
#define fmodf(x, y) ((float)fmod((double)(x), (double)(y)))
#define atan2f(x, y) ((float)atan2((double)(x), (double)(y)))
#define ceilf(x) ((float)ceil((double)(x)))

/* The next are directly called from interp_body.cpp */
#define powf(x, y) ((float)pow((double)(x), (double)(y)))
Expand Down Expand Up @@ -138,4 +139,12 @@ inline float fconjf2(float x) {
return x;
}

inline float ceilf2(float x) {
return ceilf(x);
}

inline float floorf2(float x) {
return floorf(x);
}

#endif // NUMEXPR_MSVC_FUNCTION_STUBS_HPP
3 changes: 2 additions & 1 deletion numexpr/tests/test_numexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ def test_changing_nthreads_01_dec(self):
for func in ['copy', 'ones_like', 'sqrt',
'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan',
'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh',
'log', 'log1p', 'log10', 'exp', 'expm1', 'abs', 'conj']:
'log', 'log1p', 'log10', 'exp', 'expm1', 'abs', 'conj',
'ceil', 'floor']:
func1tests.append("a + %s(b+c)" % func)
tests.append(('1_ARG_FUNCS', func1tests))

Expand Down

0 comments on commit d8bd211

Please sign in to comment.