Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: 
Changeset: r49887:f8cc091116a7
Date: 2011-11-28 12:18 +0200
http://bitbucket.org/pypy/pypy/changeset/f8cc091116a7/

Log:    merge

diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -295,7 +295,10 @@
         return math.atanh(v)
     @unaryop
     def sqrt(self, v):
-        return math.sqrt(v)
+        try:
+            return math.sqrt(v)
+        except ValueError:
+            return rfloat.NAN
 
 class IntegerArithmeticDtype(ArithmeticTypeMixin):
     _mixin_ = True
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py 
b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -320,10 +320,15 @@
             assert arctanh(v) == math.copysign(float("inf"), v)
 
     def test_sqrt(self):
+        import math
         from numpypy import sqrt
-        import math
-        assert (sqrt([1, 2, 3]) == [math.sqrt(1), math.sqrt(2),
-                                    math.sqrt(3)]).all()
+
+        nan, inf = float("nan"), float("inf")
+        data = [1, 2, 3, inf]
+        results = [math.sqrt(1), math.sqrt(2), math.sqrt(3), inf]
+        assert (sqrt(data) == results).all()
+        assert math.isnan(sqrt(-1))
+        assert math.isnan(sqrt(nan))
 
     def test_reduce_errors(self):
         from numpypy import sin, add
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to