[Numpy-svn] r8330 - trunk/numpy/core/tests

numpy-svn@scip... numpy-svn@scip...
Mon Apr 12 22:26:41 CDT 2010


Author: charris
Date: 2010-04-12 22:26:41 -0500 (Mon, 12 Apr 2010)
New Revision: 8330

Modified:
   trunk/numpy/core/tests/test_umath.py
Log:
ENH: Add test of sign ufunc removed from test_ufunclike.

Modified: trunk/numpy/core/tests/test_umath.py
===================================================================
--- trunk/numpy/core/tests/test_umath.py	2010-04-13 03:26:38 UTC (rev 8329)
+++ trunk/numpy/core/tests/test_umath.py	2010-04-13 03:26:41 UTC (rev 8330)
@@ -4,6 +4,7 @@
 import numpy.core.umath as ncu
 import numpy as np
 
+
 class TestDivision(TestCase):
     def test_division_int(self):
         # int division should follow Python
@@ -39,6 +40,7 @@
         y = np.floor_divide(x**2, x)
         assert_equal(y, [1.e+110, 0], err_msg=msg)
 
+
 class TestPower(TestCase):
     def test_power_float(self):
         x = np.array([1., 2., 3.])
@@ -84,6 +86,7 @@
             finally:
                 np.seterr(**err)
 
+
 class TestLog2(TestCase):
     def test_log2_values(self) :
         x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
@@ -93,6 +96,7 @@
             yf = np.array(y, dtype=dt)
             assert_almost_equal(np.log2(xf), yf)
 
+
 class TestExp2(TestCase):
     def test_exp2_values(self) :
         x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
@@ -102,6 +106,7 @@
             yf = np.array(y, dtype=dt)
             assert_almost_equal(np.exp2(yf), xf)
 
+
 class TestLogAddExp2(object):
     # Need test for intermediate precisions
     def test_logaddexp2_values(self) :
@@ -146,6 +151,7 @@
         assert np.isnan(np.logaddexp2(0, np.nan))
         assert np.isnan(np.logaddexp2(np.nan, np.nan))
 
+
 class TestLog(TestCase):
     def test_log_values(self) :
         x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
@@ -156,6 +162,7 @@
             yf = np.array(y, dtype=dt)*log2_
             assert_almost_equal(np.log(xf), yf)
 
+
 class TestExp(TestCase):
     def test_exp_values(self) :
         x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
@@ -166,6 +173,7 @@
             yf = np.array(y, dtype=dt)*log2_
             assert_almost_equal(np.exp(yf), xf)
 
+
 class TestLogAddExp(object):
     def test_logaddexp_values(self) :
         x = [1, 2, 3, 4, 5]
@@ -209,21 +217,25 @@
         assert np.isnan(np.logaddexp(0, np.nan))
         assert np.isnan(np.logaddexp(np.nan, np.nan))
 
+
 class TestLog1p(TestCase):
     def test_log1p(self):
         assert_almost_equal(ncu.log1p(0.2), ncu.log(1.2))
         assert_almost_equal(ncu.log1p(1e-6), ncu.log(1+1e-6))
 
+
 class TestExpm1(TestCase):
     def test_expm1(self):
         assert_almost_equal(ncu.expm1(0.2), ncu.exp(0.2)-1)
         assert_almost_equal(ncu.expm1(1e-6), ncu.exp(1e-6)-1)
 
+
 class TestHypot(TestCase, object):
     def test_simple(self):
         assert_almost_equal(ncu.hypot(1, 1), ncu.sqrt(2))
         assert_almost_equal(ncu.hypot(0, 0), 0)
 
+
 def assert_hypot_isnan(x, y):
     err = np.seterr(invalid='ignore')
     try:
@@ -231,6 +243,7 @@
     finally:
         np.seterr(**err)
 
+
 def assert_hypot_isinf(x, y):
     err = np.seterr(invalid='ignore')
     try:
@@ -238,6 +251,7 @@
     finally:
         np.seterr(**err)
 
+
 class TestHypotSpecialValues(TestCase):
     def test_nan_outputs(self):
         assert_hypot_isnan(np.nan, np.nan)
@@ -249,21 +263,27 @@
         assert_hypot_isinf(np.inf, 0)
         assert_hypot_isinf(0, np.inf)
 
+
 def assert_arctan2_isnan(x, y):
     assert np.isnan(ncu.arctan2(x, y)), "arctan(%s, %s) is %s, not nan" % (x, y, ncu.arctan2(x, y))
 
+
 def assert_arctan2_ispinf(x, y):
     assert (np.isinf(ncu.arctan2(x, y)) and ncu.arctan2(x, y) > 0), "arctan(%s, %s) is %s, not +inf" % (x, y, ncu.arctan2(x, y))
 
+
 def assert_arctan2_isninf(x, y):
     assert (np.isinf(ncu.arctan2(x, y)) and ncu.arctan2(x, y) < 0), "arctan(%s, %s) is %s, not -inf" % (x, y, ncu.arctan2(x, y))
 
+
 def assert_arctan2_ispzero(x, y):
     assert (ncu.arctan2(x, y) == 0 and not np.signbit(ncu.arctan2(x, y))), "arctan(%s, %s) is %s, not +0" % (x, y, ncu.arctan2(x, y))
 
+
 def assert_arctan2_isnzero(x, y):
     assert (ncu.arctan2(x, y) == 0 and np.signbit(ncu.arctan2(x, y))), "arctan(%s, %s) is %s, not -0" % (x, y, ncu.arctan2(x, y))
 
+
 class TestArctan2SpecialValues(TestCase):
     def test_one_one(self):
         # atan2(1, 1) returns pi/4.
@@ -332,6 +352,7 @@
         assert_arctan2_isnan(np.inf, np.nan)
         assert_arctan2_isnan(np.nan, np.nan)
 
+
 class TestMaximum(TestCase):
     def test_reduce_complex(self):
         assert_equal(np.maximum.reduce([1,2j]),1)
@@ -352,6 +373,7 @@
             out  = np.array([nan, nan, nan], dtype=np.complex)
             assert_equal(np.maximum(arg1, arg2), out)
 
+
 class TestMinimum(TestCase):
     def test_reduce_complex(self):
         assert_equal(np.minimum.reduce([1,2j]),2j)
@@ -372,6 +394,7 @@
             out  = np.array([nan, nan, nan], dtype=np.complex)
             assert_equal(np.minimum(arg1, arg2), out)
 
+
 class TestFmax(TestCase):
     def test_reduce_complex(self):
         assert_equal(np.fmax.reduce([1,2j]),1)
@@ -392,6 +415,7 @@
             out  = np.array([0,    0, nan], dtype=np.complex)
             assert_equal(np.fmax(arg1, arg2), out)
 
+
 class TestFmin(TestCase):
     def test_reduce_complex(self):
         assert_equal(np.fmin.reduce([1,2j]),2j)
@@ -412,20 +436,41 @@
             out  = np.array([0,    0, nan], dtype=np.complex)
             assert_equal(np.fmin(arg1, arg2), out)
 
+
 class TestFloatingPoint(TestCase):
     def test_floating_point(self):
         assert_equal(ncu.FLOATING_POINT_SUPPORT, 1)
 
+
 class TestDegrees(TestCase):
     def test_degrees(self):
         assert_almost_equal(ncu.degrees(np.pi), 180.0)
         assert_almost_equal(ncu.degrees(-0.5*np.pi), -90.0)
 
+
 class TestRadians(TestCase):
     def test_radians(self):
         assert_almost_equal(ncu.radians(180.0), np.pi)
         assert_almost_equal(ncu.radians(-90.0), -0.5*np.pi)
 
+
+class TestSign(TestCase):
+    def test_sign(self):
+        a = np.array([np.inf, -np.inf, np.nan, 0.0, 3.0, -3.0])
+        out = np.zeros(a.shape)
+        tgt = np.array([1., -1., np.nan, 0.0, 1.0, -1.0])
+
+        olderr = np.seterr(invalid='ignore')
+        try:
+            res = ncu.sign(a)
+            assert_equal(res, tgt)
+            res = ncu.sign(a, out)
+            assert_equal(res, tgt)
+            assert_equal(out, tgt)
+        finally:
+            np.seterr(**olderr)
+
+
 class TestSpecialMethods(TestCase):
     def test_wrap(self):
         class with_wrap(object):
@@ -596,6 +641,7 @@
     info = np.finfo(np.longcomplex)
     return not np.isfinite(np.log10(info.tiny/info.eps))
 
+
 class TestComplexFunctions(object):
     funcs = [np.arcsin,  np.arccos,  np.arctan, np.arcsinh, np.arccosh,
              np.arctanh, np.sin,     np.cos,    np.tan,     np.exp,
@@ -786,6 +832,7 @@
     def test_loss_of_precision_longcomplex(self):
         self.check_loss_of_precision(np.longcomplex)
 
+
 class TestAttributes(TestCase):
     def test_attributes(self):
         add = ncu.add
@@ -797,6 +844,7 @@
         assert_equal(add.nout, 1)
         assert_equal(add.identity, 0)
 
+
 class TestSubclass(TestCase):
     def test_subclass_op(self):
         class simple(np.ndarray):



More information about the Numpy-svn mailing list