[Numpy-svn] r5907 - in branches/ufunc_cleanup: numpy/core/include/numpy numpy/core/src numpy/core/tests numpy/distutils/command tools/win32build

numpy-svn@scip... numpy-svn@scip...
Fri Oct 3 20:04:01 CDT 2008


Author: charris
Date: 2008-10-03 20:02:11 -0500 (Fri, 03 Oct 2008)
New Revision: 5907

Added:
   branches/ufunc_cleanup/numpy/core/include/numpy/WTF_MathExtras.h
Modified:
   branches/ufunc_cleanup/numpy/core/src/ufuncobject.c
   branches/ufunc_cleanup/numpy/core/src/umathmodule.c.src
   branches/ufunc_cleanup/numpy/core/tests/test_umath.py
   branches/ufunc_cleanup/numpy/distutils/command/scons.py
   branches/ufunc_cleanup/tools/win32build/doall.py
Log:
Update to trunk.
Add WTF_MathExtras.h from Apple to see if it fixes some windows problems.


Added: branches/ufunc_cleanup/numpy/core/include/numpy/WTF_MathExtras.h
===================================================================
--- branches/ufunc_cleanup/numpy/core/include/numpy/WTF_MathExtras.h	2008-10-03 15:55:52 UTC (rev 5906)
+++ branches/ufunc_cleanup/numpy/core/include/numpy/WTF_MathExtras.h	2008-10-04 01:02:11 UTC (rev 5907)
@@ -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 */

Modified: branches/ufunc_cleanup/numpy/core/src/ufuncobject.c
===================================================================
--- branches/ufunc_cleanup/numpy/core/src/ufuncobject.c	2008-10-03 15:55:52 UTC (rev 5906)
+++ branches/ufunc_cleanup/numpy/core/src/ufuncobject.c	2008-10-04 01:02:11 UTC (rev 5907)
@@ -1427,12 +1427,15 @@
      * 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;

Modified: branches/ufunc_cleanup/numpy/core/src/umathmodule.c.src
===================================================================
--- branches/ufunc_cleanup/numpy/core/src/umathmodule.c.src	2008-10-03 15:55:52 UTC (rev 5906)
+++ branches/ufunc_cleanup/numpy/core/src/umathmodule.c.src	2008-10-04 01:02:11 UTC (rev 5907)
@@ -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 @@
     return x * (M_PI/180.0L);
 }
 
-/* 
+/*
  * A whole slew of basic math functions are provided originally
  * by Konrad Hinsen.
  */

Modified: branches/ufunc_cleanup/numpy/core/tests/test_umath.py
===================================================================
--- branches/ufunc_cleanup/numpy/core/tests/test_umath.py	2008-10-03 15:55:52 UTC (rev 5906)
+++ branches/ufunc_cleanup/numpy/core/tests/test_umath.py	2008-10-04 01:02:11 UTC (rev 5907)
@@ -281,6 +281,16 @@
         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):
     """

Modified: branches/ufunc_cleanup/numpy/distutils/command/scons.py
===================================================================
--- branches/ufunc_cleanup/numpy/distutils/command/scons.py	2008-10-03 15:55:52 UTC (rev 5906)
+++ branches/ufunc_cleanup/numpy/distutils/command/scons.py	2008-10-04 01:02:11 UTC (rev 5907)
@@ -360,7 +360,7 @@
                                    "this package " % str(e))
 
             try:
-                minver = "0.9.1"
+                minver = "0.9.3"
                 from numscons import get_version
                 if get_version() < minver:
                     raise ValueError()

Modified: branches/ufunc_cleanup/tools/win32build/doall.py
===================================================================
--- branches/ufunc_cleanup/tools/win32build/doall.py	2008-10-03 15:55:52 UTC (rev 5906)
+++ branches/ufunc_cleanup/tools/win32build/doall.py	2008-10-04 01:02:11 UTC (rev 5907)
@@ -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)



More information about the Numpy-svn mailing list