diff options
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 5 | ||||
-rw-r--r-- | numpy/core/src/numpyos.c | 8 | ||||
-rw-r--r-- | numpy/core/src/umath_funcs_c99.inc.src | 304 | ||||
-rw-r--r-- | numpy/core/src/umathmodule.c.src | 7 |
4 files changed, 6 insertions, 318 deletions
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index d680671c3..c4c612ff9 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -81,11 +81,6 @@ _arraydescr_fromobj(PyObject *obj) return NULL; } -/* XXX: We include c99 compat math module here because it is needed for - * numpyos.c (included by arrayobject). This is bad - we should separate - * declaration/implementation and share this in a lib. */ -#include "umath_funcs_c99.inc" - /* Including this file is the only way I know how to declare functions static in each file, and store the pointers from functions in both arrayobject.c and multiarraymodule.c for the C-API diff --git a/numpy/core/src/numpyos.c b/numpy/core/src/numpyos.c index 5408851f9..ca7cdafe9 100644 --- a/numpy/core/src/numpyos.c +++ b/numpy/core/src/numpyos.c @@ -1,6 +1,8 @@ #include <locale.h> #include <stdio.h> +#include "numpy/npy_math.h" + /* From the C99 standard, section 7.19.6: The exponent always contains at least two digits, and only as many more digits as necessary to represent the exponent. @@ -249,21 +251,21 @@ _fix_ascii_format(char* buf, size_t buflen, int decimal) const char *format, \ type val, int decimal) \ { \ - if (isfinite(val)) { \ + if (npy_isfinite(val)) { \ if(_check_ascii_format(format)) { \ return NULL; \ } \ PyOS_snprintf(buffer, buf_size, format, (print_type)val); \ return _fix_ascii_format(buffer, buf_size, decimal); \ } \ - else if (isnan(val)){ \ + else if (npy_isnan(val)){ \ if (buf_size < 4) { \ return NULL; \ } \ strcpy(buffer, "nan"); \ } \ else { \ - if (signbit(val)) { \ + if (npy_signbit(val)) { \ if (buf_size < 5) { \ return NULL; \ } \ diff --git a/numpy/core/src/umath_funcs_c99.inc.src b/numpy/core/src/umath_funcs_c99.inc.src deleted file mode 100644 index e0bcdebee..000000000 --- a/numpy/core/src/umath_funcs_c99.inc.src +++ /dev/null @@ -1,304 +0,0 @@ -/* - * vim:syntax=c - * A small module to implement missing C99 math capabilities required by numpy - * - * Please keep this independant of python ! - * - * How to add a function to this section - * ------------------------------------- - * - * Say you want to add `foo`, these are the steps and the reasons for them. - * - * 1) Add foo to the appropriate list in the configuration system. The - * lists can be found in numpy/core/setup.py lines 63-105. Read the - * comments that come with them, they are very helpful. - * - * 2) The configuration system will define a macro HAVE_FOO if your function - * can be linked from the math library. The result can depend on the - * optimization flags as well as the compiler, so can't be known ahead of - * time. If the function can't be linked, then either it is absent, defined - * as a macro, or is an intrinsic (hardware) function. - * - * i) Undefine any possible macros: - * - * #ifdef foo - * #undef foo - * #endif - * - * ii) Avoid as much as possible to declare any function here. Declaring - * functions is not portable: some platforms define some function inline - * with a non standard identifier, for example, or may put another - * idendifier which changes the calling convention of the function. If you - * really have to, ALWAYS declare it for the one platform you are dealing - * with: - * - * Not ok: - * double exp(double a); - * - * Ok: - * #ifdef SYMBOL_DEFINED_WEIRD_PLATFORM - * double exp(double); - * #endif - */ - -/* - ***************************************************************************** - ** DISTRO VOODOO ** - ***************************************************************************** - */ - - -/* - ***************************************************************************** - ** BASIC MATH FUNCTIONS ** - ***************************************************************************** - */ - -/* Original code by Konrad Hinsen. */ -#ifndef HAVE_EXPM1 -double expm1(double x) -{ - double u = exp(x); - if (u == 1.0) { - return x; - } else if (u-1.0 == -1.0) { - return -1; - } else { - return (u-1.0) * x/log(u); - } -} -#endif - -#ifndef HAVE_LOG1P -double log1p(double x) -{ - double u = 1. + x; - if (u == 1.0) { - return x; - } else { - return log(u) * x / (u - 1); - } -} -#endif - -#ifndef HAVE_HYPOT -double hypot(double x, double y) -{ - double yx; - - x = fabs(x); - y = fabs(y); - if (x < y) { - double temp = x; - x = y; - y = temp; - } - if (x == 0.) - return 0.; - else { - yx = y/x; - return x*sqrt(1.+yx*yx); - } -} -#endif - -#ifndef HAVE_ACOSH -double acosh(double x) -{ - return 2*log(sqrt((x+1.0)/2)+sqrt((x-1.0)/2)); -} -#endif - -#ifndef HAVE_ASINH -double asinh(double xx) -{ - double x, d; - int sign; - if (xx < 0.0) { - sign = -1; - x = -xx; - } - else { - sign = 1; - x = xx; - } - if (x > 1e8) { - d = x; - } else { - d = sqrt(x*x + 1); - } - return sign*log1p(x*(1.0 + x/(d+1))); -} -#endif - -#ifndef HAVE_ATANH -double atanh(double x) -{ - if (x > 0) { - return -0.5*log1p(-2.0*x/(1.0 + x)); - } - else { - return 0.5*log1p(2.0*x/(1.0 - x)); - } -} -#endif - -#ifndef HAVE_RINT -double rint(double x) -{ - double y, r; - - y = floor(x); - r = x - y; - - if (r > 0.5) goto rndup; - - /* Round to nearest even */ - if (r==0.5) { - r = y - 2.0*floor(0.5*y); - if (r==1.0) { - rndup: - y+=1.0; - } - } - return y; -} -#endif - -#ifndef HAVE_TRUNC -double trunc(double x) -{ - return x < 0 ? ceil(x) : floor(x); -} -#endif - -#ifndef HAVE_EXP2 -#define LOG2 0.69314718055994530943 -double exp2(double x) -{ - return exp(LOG2*x); -} -#undef LOG2 -#endif - -#ifndef HAVE_LOG2 -#define INVLOG2 1.4426950408889634074 -double log2(double x) -{ - return INVLOG2*log(x); -} -#undef INVLOG2 -#endif - -/* - ***************************************************************************** - ** IEEE 754 FPU HANDLING ** - ***************************************************************************** - */ -#if !defined(HAVE_DECL_ISNAN) - # define isnan(x) ((x) != (x)) -#endif - -/* VS 2003 with /Ox optimizes (x)-(x) to 0, which is not IEEE compliant. So we - * force (x) + (-x), which seems to work. */ -#if !defined(HAVE_DECL_ISFINITE) - # define isfinite(x) !isnan((x) + (-x)) -#endif - -#if !defined(HAVE_DECL_ISINF) -#define isinf(x) (!isfinite(x) && !isnan(x)) -#endif - -#if !defined(HAVE_DECL_SIGNBIT) - #include "_signbit.c" - # define signbit(x) \ - (sizeof (x) == sizeof (long double) ? signbit_ld (x) \ - : sizeof (x) == sizeof (double) ? signbit_d (x) \ - : signbit_f (x)) - -static int signbit_f (float x) -{ - return signbit_d((double)x); -} - -static int signbit_ld (long double x) -{ - return signbit_d((double)x); -} -#endif - -/* - * if C99 extensions not available then define dummy functions that use the - * double versions for - * - * sin, cos, tan - * sinh, cosh, tanh, - * fabs, floor, ceil, rint, trunc - * sqrt, log10, log, exp, expm1 - * asin, acos, atan, - * asinh, acosh, atanh - * - * hypot, atan2, pow, fmod, modf - * - * We assume the above are always available in their double versions. - * - * NOTE: some facilities may be available as macro only instead of functions. - * For simplicity, we define our own functions and undef the macros. We could - * instead test for the macro, but I am lazy to do that for now. - */ - -/**begin repeat - * #type = longdouble, float# - * #TYPE = LONGDOUBLE, FLOAT# - * #c = l,f# - * #C = L,F# - */ - -/**begin repeat1 - * #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10, - * log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2# - * #KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10, - * LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2# - */ - -#ifdef @kind@@c@ -#undef @kind@@c@ -#endif -#ifndef HAVE_@KIND@@C@ -@type@ @kind@@c@(@type@ x) -{ - return (@type@) @kind@((double)x); -} -#endif - -/**end repeat1**/ - -/**begin repeat1 - * #kind = atan2,hypot,pow,fmod# - * #KIND = ATAN2,HYPOT,POW,FMOD# - */ -#ifdef @kind@@c@ -#undef @kind@@c@ -#endif -#ifndef HAVE_@KIND@@C@ -@type@ @kind@@c@(@type@ x, @type@ y) -{ - return (@type@) @kind@((double)x, (double) y); -} -#endif -/**end repeat1**/ - -#ifdef modf@c@ -#undef modf@c@ -#endif -#ifndef HAVE_MODF@C@ -@type@ modf@c@(@type@ x, @type@ *iptr) -{ - double niptr; - double y = modf((double)x, &niptr); - *iptr = (@type@) niptr; - return (@type@) y; -} -#endif - -/**end repeat**/ diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src index a5557042f..f0eb20f4a 100644 --- a/numpy/core/src/umathmodule.c.src +++ b/numpy/core/src/umathmodule.c.src @@ -23,18 +23,13 @@ #include "abstract.h" #include "config.h" -/* - * Looks like some versions of Python.h do naughty things, so math.h needs - * to come after. - */ -#include <math.h> +#include "numpy/npy_math.h" /* ***************************************************************************** ** INCLUDE GENERATED CODE ** ***************************************************************************** */ -#include "umath_funcs_c99.inc" #include "umath_funcs.inc" #include "umath_loops.inc" #include "umath_ufunc_object.inc" |