diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2008-10-04 01:02:11 +0000 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2008-10-04 01:02:11 +0000 |
commit | 98f4cd292ae1478174270ef2f3dc70b2b3108d75 (patch) | |
tree | 654f76b2c6e8666d75aca1ae4dd39c8093041f56 | |
parent | 5055ae60c20668cec21d2a0152b10d91044751f0 (diff) | |
download | numpy-98f4cd292ae1478174270ef2f3dc70b2b3108d75.tar.gz |
Update to trunk.
Add WTF_MathExtras.h from Apple to see if it fixes some windows problems.
-rw-r--r-- | numpy/core/include/numpy/WTF_MathExtras.h | 170 | ||||
-rw-r--r-- | numpy/core/src/ufuncobject.c | 7 | ||||
-rw-r--r-- | numpy/core/src/umathmodule.c.src | 3 | ||||
-rw-r--r-- | numpy/core/tests/test_umath.py | 10 | ||||
-rw-r--r-- | numpy/distutils/command/scons.py | 2 | ||||
-rw-r--r-- | tools/win32build/doall.py | 26 |
6 files changed, 207 insertions, 11 deletions
diff --git a/numpy/core/include/numpy/WTF_MathExtras.h b/numpy/core/include/numpy/WTF_MathExtras.h new file mode 100644 index 000000000..46bd36934 --- /dev/null +++ b/numpy/core/include/numpy/WTF_MathExtras.h @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef WTF_MathExtras_h +#define WTF_MathExtras_h + +#include <math.h> +#include <stdlib.h> +#include <time.h> + +#if defined (__SVR4) && defined (__sun) && defined (__GNUC__) + +#include <ieeefp.h> + +#endif + +#if defined(_MSC_VER) + +#include <xmath.h> +#include <limits> + +#if HAVE(FLOAT_H) +#include <float.h> +#endif + +#endif + +#ifndef M_PI +const double piDouble = 3.14159265358979323846; +const float piFloat = 3.14159265358979323846f; +#else +const double piDouble = M_PI; +const float piFloat = (float)M_PI; +#endif + +#ifndef M_PI_4 +const double piOverFourDouble = 0.785398163397448309616; +const float piOverFourFloat = 0.785398163397448309616f; +#else +const double piOverFourDouble = M_PI_4; +const float piOverFourFloat = (float)M_PI_4; +#endif + +#if defined (__SVR4) && defined (__sun) && defined (__GNUC__) + +#ifndef isfinite +#define isfinite(x) (finite(x) && !isnand(x)) +#endif +#ifndef isinf +#define isinf(x) (!finite(x) && !isnand(x)) +#endif +#ifndef signbit +#define signbit(x) (x < 0.0) /* FIXME: Wrong for negative 0. */ +#endif + +#endif + +#if defined(_MSC_VER) + +#define isinf(num) ( !_finite(num) && !_isnan(num) ) +#define isnan(num) ( !!_isnan(num) ) +/* +#define lround(num) ( (long)(num > 0 ? num + 0.5 : ceil(num - 0.5)) ) +#define lroundf(num) ( (long)(num > 0 ? num + 0.5f : ceilf(num - 0.5f)) ) +#define round(num) ( num > 0 ? floor(num + 0.5) : ceil(num - 0.5) ) +#define roundf(num) ( num > 0 ? floorf(num + 0.5f) : ceilf(num - 0.5f) ) +*/ +#define signbit(num) ( _copysign(1.0, num) < 0 ) +#define trunc(num) ( num > 0 ? floor(num) : ceil(num) ) +#define nextafter(x, y) ( _nextafter(x, y) ) +#define nextafterf(x, y) ( x > y ? x - FLT_EPSILON : x + FLT_EPSILON ) +#define copysign(x, y) ( _copysign(x, y) ) +#define isfinite(x) ( _finite(x) ) + +/* + * Work around a bug in Win, where atan2(+-infinity, +-infinity) + * yields NaN instead of specific values. + */ +/* +double +wtf_atan2(double x, double y) +{ + static double posInf = std::numeric_limits<double>::infinity(); + static double negInf = -std::numeric_limits<double>::infinity(); + static double nan = std::numeric_limits<double>::quiet_NaN(); + + + double result = nan; + + if (x == posInf && y == posInf) + result = piOverFourDouble; + else if (x == posInf && y == negInf) + result = 3 * piOverFourDouble; + else if (x == negInf && y == posInf) + + result = -piOverFourDouble; + else if (x == negInf && y == negInf) + result = -3 * piOverFourDouble; + else + result = ::atan2(x, y); + + return result; +} +*/ + +/* + * Work around a bug in the Microsoft CRT, where fmod(x, +-infinity) + * yields NaN instead of x. + */ +#define wtf_fmod(x, y) ( (!isinf(x) && isinf(y)) ? x : fmod(x, y) ) + +/* + * Work around a bug in the Microsoft CRT, where pow(NaN, 0) + * yields NaN instead of 1. + */ +#define wtf_pow(x, y) ( y == 0 ? 1 : pow(x, y) ) + +/* +#define atan2(x, y) wtf_atan2(x, y) +*/ +#define fmod(x, y) wtf_fmod(x, y) +#define pow(x, y) wtf_pow(x, y) + +#endif /* COMPILER(MSVC) */ + + +#define deg2rad(d) ( d * piDouble / 180.0 ) +#define rad2deg(r) ( r * 180.0 / piDouble ) +#define deg2grad(d) ( d * 400.0 / 360.0 ) +#define grad2deg(g) ( g * 360.0 / 400.0 ) +#define rad2grad(r) ( r * 200.0 / piDouble ) +#define grad2rad(g) ( g * piDouble / 200.0 ) + +#define deg2radf(d) ( d * piFloat / 180.0f ) +#define rad2degf(r) ( r * 180.0f / piFloat ) +#define deg2gradf(d) ( d * 400.0f / 360.0f ) +#define grad2degf(g) ( g * 360.0f / 400.0f ) +#define rad2gradf(r) ( r * 200.0f / piFloat ) +#define grad2radf(g) ( g * piFloat / 200.0f ) + + +#endif /* #ifndef WTF_MathExtras_h */ diff --git a/numpy/core/src/ufuncobject.c b/numpy/core/src/ufuncobject.c index fd14936a8..ab4ecef75 100644 --- a/numpy/core/src/ufuncobject.c +++ b/numpy/core/src/ufuncobject.c @@ -1427,12 +1427,15 @@ construct_arrays(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps, * FAIL with NotImplemented if the other object has * the __r<op>__ method and has __array_priority__ as * an attribute (signalling it can handle ndarray's) - * and is not already an ndarray + * and is not already an ndarray or a subtype of the same type. */ if ((arg_types[1] == PyArray_OBJECT) && \ (loop->ufunc->nin==2) && (loop->ufunc->nout == 1)) { PyObject *_obj = PyTuple_GET_ITEM(args, 1); - if (!PyArray_CheckExact(_obj) && \ + if (!PyArray_CheckExact(_obj) && + /* If both are same subtype of object arrays, then proceed */ + !(_obj->ob_type == (PyTuple_GET_ITEM(args, 0))->ob_type) && \ + PyObject_HasAttrString(_obj, "__array_priority__") && \ _has_reflected_op(_obj, loop->ufunc->name)) { loop->notimplemented = 1; diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src index 3e1e9928e..a30a98abd 100644 --- a/numpy/core/src/umathmodule.c.src +++ b/numpy/core/src/umathmodule.c.src @@ -16,6 +16,7 @@ #include "abstract.h" #include "config.h" #include <math.h> +#include "numpy/WTF_MathExtras.h" #ifndef M_PI #define M_PI 3.14159265358979323846264338328 @@ -47,7 +48,7 @@ longdouble radiansl(longdouble x) { return x * (M_PI/180.0L); } -/* +/* * A whole slew of basic math functions are provided originally * by Konrad Hinsen. */ diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index b9c2675fd..ee2893f18 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -281,6 +281,16 @@ class TestAttributes(TestCase): assert_equal(add.nout, 1) assert_equal(add.identity, 0) +class TestSubclass(TestCase): + def test_subclass_op(self): + class simple(np.ndarray): + def __new__(subtype, shape): + self = np.ndarray.__new__(subtype, shape, dtype=object) + self.fill(0) + return self + a = simple((3,4)) + assert_equal(a+a, a) + def _check_branch_cut(f, x0, dx, re_sign=1, im_sign=-1, sig_zero_ok=False, dtype=np.complex): """ diff --git a/numpy/distutils/command/scons.py b/numpy/distutils/command/scons.py index 80795a010..d5303bb29 100644 --- a/numpy/distutils/command/scons.py +++ b/numpy/distutils/command/scons.py @@ -360,7 +360,7 @@ class scons(old_build_ext): "this package " % str(e)) try: - minver = "0.9.1" + minver = "0.9.3" from numscons import get_version if get_version() < minver: raise ValueError() diff --git a/tools/win32build/doall.py b/tools/win32build/doall.py index 19009d42b..eb07394ea 100644 --- a/tools/win32build/doall.py +++ b/tools/win32build/doall.py @@ -1,13 +1,25 @@ import subprocess import os -PYVER = "2.5" +if __name__ == '__main__': + from optparse import OptionParser + parser = OptionParser() + parser.add_option("-p", "--pyver", dest="pyver", + help = "Python version (2.4, 2.5, etc...)") -# Bootstrap -subprocess.check_call(['python', 'prepare_bootstrap.py', '-p', PYVER]) + opts, args = parser.parse_args() + pyver = opts.pyver -# Build binaries -subprocess.check_call(['python', 'build.py', '-p', PYVER], cwd = 'bootstrap-%s' % PYVER) + if not pyver: + pyver = "2.5" -# Build installer using nsis -subprocess.check_call(['makensis', 'numpy-superinstaller.nsi'], cwd = 'bootstrap-%s' % PYVER) + # Bootstrap + subprocess.check_call(['python', 'prepare_bootstrap.py', '-p', pyver]) + + # Build binaries + subprocess.check_call(['python', 'build.py', '-p', pyver], + cwd = 'bootstrap-%s' % pyver) + + # Build installer using nsis + subprocess.check_call(['makensis', 'numpy-superinstaller.nsi'], + cwd = 'bootstrap-%s' % pyver) |