[Numpy-svn] r3625 - in trunk: . numpy/core/src numpy/core/tests

numpy-svn at scipy.org numpy-svn at scipy.org
Sat Mar 31 03:40:52 EDT 2007


Author: oliphant
Date: 2007-03-31 02:40:31 -0500 (Sat, 31 Mar 2007)
New Revision: 3625

Modified:
   trunk/THANKS.txt
   trunk/numpy/core/src/multiarraymodule.c
   trunk/numpy/core/tests/test_numeric.py
Log:
Finish adding and checking remaining tests for clip (and choose).   All tests now pass for new clip method.

Modified: trunk/THANKS.txt
===================================================================
--- trunk/THANKS.txt	2007-03-31 00:15:41 UTC (rev 3624)
+++ trunk/THANKS.txt	2007-03-31 07:40:31 UTC (rev 3625)
@@ -34,4 +34,4 @@
     Valgrind expertise.
 Stefan van der Walt for documentation, bug-fixes and regression-tests.
 Andrew Straw for help with http://www.scipy.org, documentation, and testing. 
-David Cournapeau for documentation, bug-fixes, and code contributions.
+David Cournapeau for documentation, bug-fixes, and code contributions including fast_clipping.

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2007-03-31 00:15:41 UTC (rev 3624)
+++ trunk/numpy/core/src/multiarraymodule.c	2007-03-31 07:40:31 UTC (rev 3625)
@@ -1291,6 +1291,7 @@
                 else 
                         oflags = NPY_CARRAY;
                 oflags |= NPY_UPDATEIFCOPY | NPY_FORCECAST;
+                Py_INCREF(indescr);
                 newout = (NPY_AO*)PyArray_FromArray(out, indescr, oflags);
                 if (newout == NULL) goto fail;
         }

Modified: trunk/numpy/core/tests/test_numeric.py
===================================================================
--- trunk/numpy/core/tests/test_numeric.py	2007-03-31 00:15:41 UTC (rev 3624)
+++ trunk/numpy/core/tests/test_numeric.py	2007-03-31 07:40:31 UTC (rev 3625)
@@ -568,105 +568,102 @@
         ac  = self.fastclip(a, m , M, out = b)
         assert_array_strict_equal(ac, act)
 
-##        # This looks like a data-type descriptor is not reference
-##        #  counted right.
-##        print "=== OUT arg: testing non native with native scalar, min/max, " + \
-##              "out non native==="
-##        a   = self._generate_non_native_data(self.nr, self.nc)
-##        b   = a.copy()
-##        b   = b.astype(b.dtype.newbyteorder('>'))
-##        bt  = b.copy()
-##        m   = -0.5
-##        M   = 1.
-##        self.fastclip(a, m , M, out = b)
-##        self.clip(a, m, M, out = bt)
-##        assert_array_strict_equal(b, bt)
+    def test_type_cast_10(self):
+        "Test non native with native scalar, min/max, out non native"
+        a   = self._generate_non_native_data(self.nr, self.nc)
+        b   = a.copy()
+        b   = b.astype(b.dtype.newbyteorder('>'))
+        bt  = b.copy()
+        m   = -0.5
+        M   = 1.
+        self.fastclip(a, m , M, out = b)
+        self.clip(a, m, M, out = bt)
+        assert_array_strict_equal(b, bt)
 
-##        print "=== OUT arg: testing native int32 input and min/max and float out ==="
-##        print "\t NOT TESTED (current clip is buggy in this case)"
-##        a   = self._generate_int_data(self.nr, self.nc)
-##        b   = zeros(a.shape, dtype = float32)
-##        m   = int32(0)
-##        M   = int32(1)
-##        act = self.clip(a, m, M, out = b)
-##        ac  = self.fastclip(a, m , M, out = b)
-##        assert_array_strict_equal(ac, act)
+    def test_type_cast_11(self):
+        "Test native int32 input and min/max and float out"
+        a   = self._generate_int_data(self.nr, self.nc)
+        b   = zeros(a.shape, dtype = float32)
+        m   = int32(0)
+        M   = int32(1)
+        act = self.clip(a, m, M, out = b)
+        ac  = self.fastclip(a, m , M, out = b)
+        assert_array_strict_equal(ac, act)
 
-##    def test_clip_with_out_simple(self):
-##        print "=== WITH OUT testing native double input with scalar min/max ==="
-##        a   = self._generate_data(self.nr, self.nc)
-##        m   = -0.5
-##        M   = 0.6
-##        ac  = zeros(a.shape)
-##        act = zeros(a.shape)
-##        self.fastclip(a, m, M, ac)
-##        self.clip(a, m, M, act)
-##        assert_array_strict_equal(ac, act)
+    def test_clip_with_out_simple(self):
+        "Test native double input with scalar min/max"
+        a   = self._generate_data(self.nr, self.nc)
+        m   = -0.5
+        M   = 0.6
+        ac  = zeros(a.shape)
+        act = zeros(a.shape)
+        self.fastclip(a, m, M, ac)
+        self.clip(a, m, M, act)
+        assert_array_strict_equal(ac, act)
 
-##    def test_clip_with_out_simple2(self):
-##        print "=== WITH OUT testing native int32 input "+\
-##                "with double min/max and int32 out ==="
-##        a   = self._generate_int32_data(self.nr, self.nc)
-##        m   = float64(0)
-##        M   = float64(2)
-##        ac  = zeros(a.shape, dtype = int32)
-##        act = ac.copy()
-##        self.fastclip(a, m, M, ac)
-##        self.clip(a, m, M, act)
-##        assert_array_strict_equal(ac, act)
+    def test_clip_with_out_simple2(self):
+        "Test native int32 input with double min/max and int32 out"
+        a   = self._generate_int32_data(self.nr, self.nc)
+        m   = float64(0)
+        M   = float64(2)
+        ac  = zeros(a.shape, dtype = int32)
+        act = ac.copy()
+        self.fastclip(a, m, M, ac)
+        self.clip(a, m, M, act)
+        assert_array_strict_equal(ac, act)
 
-##    def test_clip_with_out_simple_int32(self):
-##        print "=== WITH OUT testing native int32 input with int32 scalar min/max and int64 out ==="
-##        a   = self._generate_int32_data(self.nr, self.nc)
-##        m   = int32(-1)
-##        M   = int32(1)
-##        ac  = zeros(a.shape, dtype = int64)
-##        act = ac.copy()
-##        self.fastclip(a, m, M, ac)
-##        self.clip(a, m, M, act)
-##        assert_array_strict_equal(ac, act)
+    def test_clip_with_out_simple_int32(self):
+        "Test native int32 input with int32 scalar min/max and int64 out"
+        a   = self._generate_int32_data(self.nr, self.nc)
+        m   = int32(-1)
+        M   = int32(1)
+        ac  = zeros(a.shape, dtype = int64)
+        act = ac.copy()
+        self.fastclip(a, m, M, ac)
+        self.clip(a, m, M, act)
+        assert_array_strict_equal(ac, act)
 
-##    def test_clip_with_out_array_int32(self):
-##        print "=== WITH OUT testing native int32 input with double array min/max and int32 out ==="
-##        a   = self._generate_int32_data(self.nr, self.nc)
-##        m   = zeros(a.shape, float64)
-##        M   = float64(1)
-##        ac  = zeros(a.shape, dtype = int32)
-##        act = ac.copy()
-##        self.fastclip(a, m, M, ac)
-##        self.clip(a, m, M, act)
-##        assert_array_strict_equal(ac, act)
+    def test_clip_with_out_array_int32(self):
+        "Test native int32 input with double array min/max and int32 out"
+        a   = self._generate_int32_data(self.nr, self.nc)
+        m   = zeros(a.shape, float64)
+        M   = float64(1)
+        ac  = zeros(a.shape, dtype = int32)
+        act = ac.copy()
+        self.fastclip(a, m, M, ac)
+        self.clip(a, m, M, act)
+        assert_array_strict_equal(ac, act)
 
-##    def test_clip_with_out_array_outint32(self):
-##        print "=== WITH OUT testing native double input with scalar min/max and int out ==="
-##        a   = self._generate_data(self.nr, self.nc)
-##        m   = -1.0
-##        M   = 2.0
-##        ac  = zeros(a.shape, dtype = int32)
-##        act = ac.copy()
-##        self.fastclip(a, m, M, ac)
-##        self.clip(a, m, M, act)
-##        assert_array_strict_equal(ac, act)
+    def test_clip_with_out_array_outint32(self):
+        "Test native double input with scalar min/max and int out"
+        a   = self._generate_data(self.nr, self.nc)
+        m   = -1.0
+        M   = 2.0
+        ac  = zeros(a.shape, dtype = int32)
+        act = ac.copy()
+        self.fastclip(a, m, M, ac)
+        self.clip(a, m, M, act)
+        assert_array_strict_equal(ac, act)
 
-##    def test_clip_inplace_array(self):
-##        print "=== INPLACE: testing native double input with array min/max ==="
-##        a   = self._generate_data(self.nr, self.nc)
-##        ac  = a.copy()
-##        m   = zeros(a.shape)
-##        M   = 1.0
-##        self.fastclip(a, m, M, a)
-##        self.clip(a, m, M, ac)
-##        assert_array_strict_equal(a, ac)
+    def test_clip_inplace_array(self):
+        "Test native double input with array min/max"
+        a   = self._generate_data(self.nr, self.nc)
+        ac  = a.copy()
+        m   = zeros(a.shape)
+        M   = 1.0
+        self.fastclip(a, m, M, a)
+        self.clip(a, m, M, ac)
+        assert_array_strict_equal(a, ac)
 
-##    def test_clip_inplace_simple(self):
-##        print "=== INPLACE: testing native double input with scalar min/max ==="
-##        a   = self._generate_data(self.nr, self.nc)
-##        ac  = a.copy()
-##        m   = -0.5
-##        M   = 0.6
-##        self.fastclip(a, m, M, a)
-##        self.clip(a, m, M, ac)
-##        assert_array_strict_equal(a, ac)
+    def test_clip_inplace_simple(self):
+        "Test native double input with scalar min/max"
+        a   = self._generate_data(self.nr, self.nc)
+        ac  = a.copy()
+        m   = -0.5
+        M   = 0.6
+        self.fastclip(a, m, M, a)
+        self.clip(a, m, M, ac)
+        assert_array_strict_equal(a, ac)
 
         
 import sys




More information about the Numpy-svn mailing list