Skip to content

Instantly share code, notes, and snippets.

@eloraburns
Created March 13, 2012 19:09
Show Gist options
  • Save eloraburns/2030832 to your computer and use it in GitHub Desktop.
Save eloraburns/2030832 to your computer and use it in GitHub Desktop.
Getting -1 from a nan (that should have been positive...)
diff -r e90378882863 pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py Tue Mar 13 11:15:10 2012 -0700
+++ b/pypy/module/micronumpy/__init__.py Tue Mar 13 12:08:16 2012 -0700
@@ -98,6 +98,7 @@
("rad2deg", "degrees"),
("reciprocal", "reciprocal"),
("sign", "sign"),
+ ("signbit", "signbit"),
("sin", "sin"),
("sinh", "sinh"),
("subtract", "subtract"),
diff -r e90378882863 pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py Tue Mar 13 11:15:10 2012 -0700
+++ b/pypy/module/micronumpy/interp_ufuncs.py Tue Mar 13 12:08:16 2012 -0700
@@ -423,6 +423,7 @@
("negative", "neg", 1),
("absolute", "abs", 1),
("sign", "sign", 1, {"promote_bools": True}),
+ ("signbit", "signbit", 1, {"bool_result": True}),
("reciprocal", "reciprocal", 1),
("fabs", "fabs", 1, {"promote_to_float": True}),
diff -r e90378882863 pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py Tue Mar 13 11:15:10 2012 -0700
+++ b/pypy/module/micronumpy/test/test_ufuncs.py Tue Mar 13 12:08:16 2012 -0700
@@ -172,6 +172,14 @@
assert a[0] == 1
assert a[1] == 0
+ def test_signbit(self):
+ from _numpypy import signbit
+
+ assert (signbit([0, 0.0, 1, 1.0, float('inf'), float('nan')]) ==
+ [False, False, False, False, False, False]).all()
+ assert (signbit([-0, -0.0, -1, -1.0, float('-inf'), float('-nan')]) ==
+ [False, True, True, True, True, True]).all()
+
def test_reciporocal(self):
from _numpypy import array, reciprocal
diff -r e90378882863 pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py Tue Mar 13 11:15:10 2012 -0700
+++ b/pypy/module/micronumpy/types.py Tue Mar 13 12:08:16 2012 -0700
@@ -470,6 +470,14 @@
return 0.0
return rfloat.copysign(1.0, v)
+ @raw_unary_op
+ def signbit(self, v):
+ if math.isnan(v):
+ import pdb
+ pdb.set_trace()
+ print v, rfloat.copysign(1.0, v), math.copysign(1.0, v)
+ return rfloat.copysign(1.0, v) < 0.0
+
@simple_unary_op
def fabs(self, v):
return math.fabs(v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment