diff options
author | David Cournapeau <cournape@gmail.com> | 2008-12-21 07:08:03 +0000 |
---|---|---|
committer | David Cournapeau <cournape@gmail.com> | 2008-12-21 07:08:03 +0000 |
commit | 44c808f02c55d6a18eaf2cc9ed2e3956e2ac5611 (patch) | |
tree | 3406b228a4627dfe2def16a7f626c90bb0122ace /numpy | |
parent | f531cfb60fd0e4dec69354bfd61109defa99ea5e (diff) | |
parent | a80dfe7c7abd95ba351b909b1de9212bd22438ca (diff) | |
download | numpy-44c808f02c55d6a18eaf2cc9ed2e3956e2ac5611.tar.gz |
Merged revisions 6174-6175,6179-6182 via svnmerge from
http://svn.scipy.org/svn/numpy/trunk
........
r6174 | ptvirtan | 2008-12-20 02:58:57 +0900 (Sat, 20 Dec 2008) | 1 line
docs: put CHM files in a zip
........
r6175 | ptvirtan | 2008-12-20 22:40:30 +0900 (Sat, 20 Dec 2008) | 1 line
test_umath: don't check against cmath on branch cuts, since the behavior of our functions varies across platforms on them
........
r6179 | cdavid | 2008-12-21 15:02:29 +0900 (Sun, 21 Dec 2008) | 1 line
Do not declare missing functions to avoid mismatch with potentially conflicting, undetected ones
........
r6180 | cdavid | 2008-12-21 15:02:44 +0900 (Sun, 21 Dec 2008) | 1 line
Update comments in umath.
........
r6181 | cdavid | 2008-12-21 15:03:05 +0900 (Sun, 21 Dec 2008) | 1 line
Do not set function to macro in umath anymore.
........
r6182 | cdavid | 2008-12-21 15:03:19 +0900 (Sun, 21 Dec 2008) | 1 line
Do not define math func as static: better to have a link error when we have a config problem than having two functions with the same name.
........
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/umath_funcs_c99.inc.src | 130 | ||||
-rw-r--r-- | numpy/core/tests/test_umath.py | 2 |
2 files changed, 27 insertions, 105 deletions
diff --git a/numpy/core/src/umath_funcs_c99.inc.src b/numpy/core/src/umath_funcs_c99.inc.src index dab9076e0..e0bcdebee 100644 --- a/numpy/core/src/umath_funcs_c99.inc.src +++ b/numpy/core/src/umath_funcs_c99.inc.src @@ -17,9 +17,7 @@ * 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. If it is linkable it - * may still be the case that no prototype is available. So to cover all the - * cases requires the following construction. + * as a macro, or is an intrinsic (hardware) function. * * i) Undefine any possible macros: * @@ -27,44 +25,20 @@ * #undef foo * #endif * - * ii) Check if the function was in the library, If not, define the - * function with npy_ prepended to its name to avoid conflict with any - * intrinsic versions, then use a define so that the preprocessor will - * replace foo with npy_foo before the compilation pass. Make the - * function static to avoid poluting the module library. + * 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: * - * #ifdef foo - * #undef foo - * #endif - * #ifndef HAVE_FOO - * static double - * npy_foo(double x) - * { - * return x; - * } - * #define foo npy_foo - * - * iii) Finally, even if foo is in the library, add a prototype. Just being - * in the library doesn't guarantee a prototype in math.h, and in any case - * you want to make sure the prototype is what you think it is. Count on it, - * whatever can go wrong will go wrong. Think defensively! The result: - * - * #ifdef foo - * #undef foo - * #endif - * #ifndef HAVE_FOO - * static double - * npy_foo(double x) - * { - * return x; - * } - * #define foo npy_foo - * #else - * double foo(double x); - * #end - * - * And there you have it. + * Not ok: + * double exp(double a); * + * Ok: + * #ifdef SYMBOL_DEFINED_WEIRD_PLATFORM + * double exp(double); + * #endif */ /* @@ -82,8 +56,7 @@ /* Original code by Konrad Hinsen. */ #ifndef HAVE_EXPM1 -static double -npy_expm1(double x) +double expm1(double x) { double u = exp(x); if (u == 1.0) { @@ -94,14 +67,10 @@ npy_expm1(double x) return (u-1.0) * x/log(u); } } -#define expm1 npy_expm1 -#else -double expm1(double x); #endif #ifndef HAVE_LOG1P -static double -npy_log1p(double x) +double log1p(double x) { double u = 1. + x; if (u == 1.0) { @@ -110,14 +79,10 @@ npy_log1p(double x) return log(u) * x / (u - 1); } } -#define log1p npy_log1p -#else -double log1p(double x); #endif #ifndef HAVE_HYPOT -static double -npy_hypot(double x, double y) +double hypot(double x, double y) { double yx; @@ -135,25 +100,17 @@ npy_hypot(double x, double y) return x*sqrt(1.+yx*yx); } } -#define hypot npy_hypot -#else -double hypot(double x, double y); #endif #ifndef HAVE_ACOSH -static double -npy_acosh(double x) +double acosh(double x) { return 2*log(sqrt((x+1.0)/2)+sqrt((x-1.0)/2)); } -#define acosh npy_acosh -#else -double acosh(double x); #endif #ifndef HAVE_ASINH -static double -npy_asinh(double xx) +double asinh(double xx) { double x, d; int sign; @@ -172,14 +129,10 @@ npy_asinh(double xx) } return sign*log1p(x*(1.0 + x/(d+1))); } -#define asinh npy_asinh -#else -double asinh(double xx); #endif #ifndef HAVE_ATANH -static double -npy_atanh(double x) +double atanh(double x) { if (x > 0) { return -0.5*log1p(-2.0*x/(1.0 + x)); @@ -188,14 +141,10 @@ npy_atanh(double x) return 0.5*log1p(2.0*x/(1.0 - x)); } } -#define atanh npy_atanh -#else -double atanh(double x); #endif #ifndef HAVE_RINT -static double -npy_rint(double x) +double rint(double x) { double y, r; @@ -214,46 +163,31 @@ npy_rint(double x) } return y; } -#define rint npy_rint -#else -double rint(double x); #endif #ifndef HAVE_TRUNC -static double -npy_trunc(double x) +double trunc(double x) { return x < 0 ? ceil(x) : floor(x); } -#define trunc npy_trunc -#else -double trunc(double x); #endif #ifndef HAVE_EXP2 #define LOG2 0.69314718055994530943 -static double -npy_exp2(double x) +double exp2(double x) { return exp(LOG2*x); } -#define exp2 npy_exp2 #undef LOG2 -#else -double exp2(double x); #endif #ifndef HAVE_LOG2 #define INVLOG2 1.4426950408889634074 -static double -npy_log2(double x) +double log2(double x) { return INVLOG2*log(x); } -#define log2 npy_log2 #undef INVLOG2 -#else -double log2(double x); #endif /* @@ -331,14 +265,10 @@ static int signbit_ld (long double x) #undef @kind@@c@ #endif #ifndef HAVE_@KIND@@C@ -static @type@ -npy_@kind@@c@(@type@ x) +@type@ @kind@@c@(@type@ x) { return (@type@) @kind@((double)x); } -#define @kind@@c@ npy_@kind@@c@ -#else -@type@ @kind@@c@(@type@ x); #endif /**end repeat1**/ @@ -351,14 +281,10 @@ npy_@kind@@c@(@type@ x) #undef @kind@@c@ #endif #ifndef HAVE_@KIND@@C@ -static @type@ -npy_@kind@@c@(@type@ x, @type@ y) +@type@ @kind@@c@(@type@ x, @type@ y) { return (@type@) @kind@((double)x, (double) y); } -#define @kind@@c@ npy_@kind@@c@ -#else -@type@ @kind@@c@(@type@ x, @type@ y); #endif /**end repeat1**/ @@ -366,17 +292,13 @@ npy_@kind@@c@(@type@ x, @type@ y) #undef modf@c@ #endif #ifndef HAVE_MODF@C@ -static @type@ -npy_modf@c@(@type@ x, @type@ *iptr) +@type@ modf@c@(@type@ x, @type@ *iptr) { double niptr; double y = modf((double)x, &niptr); *iptr = (@type@) niptr; return (@type@) y; } -#define modf@c@ npy_modf@c@ -#else -@type@ modf@c@(@type@ x, @type@ *iptr); #endif /**end repeat**/ diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index 0dab9ac3a..1b4ba97ca 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -404,7 +404,7 @@ class TestComplexFunctions(object): if sys.version_info < (2,5,3): broken_cmath_asinh = True - points = [-2, 2j, 2, -2j, -1-1j, -1+1j, +1-1j, +1+1j] + points = [-1-1j, -1+1j, +1-1j, +1+1j] name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan', 'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'} atol = 4*np.finfo(np.complex).eps |