Author: mattip <[email protected]>
Branch: numpypy-complex2
Changeset: r57330:f3952baf88a7
Date: 2012-09-13 22:40 +0300
http://bitbucket.org/pypy/pypy/changeset/f3952baf88a7/
Log: disallow invalid ufuncs
diff --git a/pypy/module/micronumpy/interp_ufuncs.py
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -513,8 +513,10 @@
("greater_equal", "ge", 2, {"comparison_func": True}),
("isnan", "isnan", 1, {"bool_result": True}),
("isinf", "isinf", 1, {"bool_result": True}),
- ("isneginf", "isneginf", 1, {"bool_result": True}),
- ("isposinf", "isposinf", 1, {"bool_result": True}),
+ ("isneginf", "isneginf", 1, {"bool_result": True,
+ "allow_complex": False}),
+ ("isposinf", "isposinf", 1, {"bool_result": True,
+ "allow_complex": False}),
("isfinite", "isfinite", 1, {"bool_result": True}),
('logical_and', 'logical_and', 2, {'comparison_func': True,
@@ -534,7 +536,8 @@
("negative", "neg", 1),
("absolute", "abs", 1),
("sign", "sign", 1, {"promote_bools": True}),
- ("signbit", "signbit", 1, {"bool_result": True}),
+ ("signbit", "signbit", 1, {"bool_result": True,
+ "allow_complex": False}),
("reciprocal", "reciprocal", 1),
("conjugate", "conj", 1),
("real", "real", 1),
@@ -545,9 +548,12 @@
("fmax", "fmax", 2, {"promote_to_float": True}),
("fmin", "fmin", 2, {"promote_to_float": True}),
("fmod", "fmod", 2, {"promote_to_float": True, 'allow_complex':
False}),
- ("floor", "floor", 1, {"promote_to_float": True}),
- ("ceil", "ceil", 1, {"promote_to_float": True}),
- ("trunc", "trunc", 1, {"promote_to_float": True}),
+ ("floor", "floor", 1, {"promote_to_float": True,
+ "allow_complex": False}),
+ ("ceil", "ceil", 1, {"promote_to_float": True,
+ "allow_complex": False}),
+ ("trunc", "trunc", 1, {"promote_to_float": True,
+ "allow_complex": False}),
("exp", "exp", 1, {"promote_to_float": True}),
("exp2", "exp2", 1, {"promote_to_float": True}),
("expm1", "expm1", 1, {"promote_to_float": 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
@@ -1,7 +1,6 @@
from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
-from math import isnan, isinf, copysign
from pypy.conftest import option
class AppTestUfuncs(BaseNumpyAppTest):
@@ -309,6 +308,8 @@
assert (signbit([-0, -0.0, -1, -1.0, float('-inf')]) ==
[False, True, True, True, True]).all()
+ raises(TypeError, signbit, complex(1,1))
+
skip('sign of nan is non-determinant')
assert (signbit([float('nan'), float('-nan'), -float('nan')]) ==
[False, True, True]).all()
@@ -352,7 +353,7 @@
assert c[i] == a[i] - b[i]
def test_floorceiltrunc(self):
- from _numpypy import array, floor, ceil, trunc
+ from _numpypy import array, floor, ceil, trunc, complex128
import math
ninf, inf = float("-inf"), float("inf")
a = array([ninf, -1.4, -1.5, -1.0, 0.0, 1.0, 1.4, 0.5, inf])
@@ -363,6 +364,11 @@
assert all([math.copysign(1, f(abs(float("nan")))) == 1 for f in
floor, ceil, trunc])
assert all([math.copysign(1, f(-abs(float("nan")))) == -1 for f in
floor, ceil, trunc])
+ a = array([ complex(-1.4, -1.4), complex(-1.5, -1.5)])
+ raises(TypeError, floor, a)
+ raises(TypeError, ceil, a)
+ raises(TypeError, trunc, a)
+
def test_copysign(self):
from _numpypy import array, copysign, complex128
@@ -753,7 +759,7 @@
assert isinf(array([0.2])).dtype.kind == 'b'
def test_isposinf_isneginf(self):
- from _numpypy import isneginf, isposinf
+ from _numpypy import isneginf, isposinf, complex128
assert isposinf(float('inf'))
assert not isposinf(float('-inf'))
assert not isposinf(float('nan'))
@@ -765,6 +771,9 @@
assert not isneginf(0)
assert not isneginf(0.0)
+ raises(TypeError, isneginf, complex(1, 1))
+ raises(TypeError, isposinf, complex(1, 1))
+
def test_isfinite(self):
from _numpypy import isfinite
assert (isfinite([0, 0.0, 1e50, -1e-50]) ==
@@ -1019,7 +1028,7 @@
assert repr(abs(complex(float('nan'), float('nan')))) == 'nan'
assert False, 'untested: ' + \
- 'floor, ceil, trunc, numpy.real. numpy.imag' + \
+ 'numpy.real. numpy.imag' + \
'exp2, expm1, isnan, isinf, isneginf, isposinf, ' + \
'isfinite, radians, degrees, log2, log1p, ' + \
'logaddexp, npy_log2_1p, logaddexp2'
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -53,7 +53,8 @@
specialize.argtype(1)(func)
@functools.wraps(func)
def dispatcher(self, v):
- assert isinstance(v, Primitive)
+ from pypy.module.micronumpy.interp_boxes import W_GenericBox
+ assert isinstance(v, W_GenericBox)
return self.RealBoxType(
func(
self,
@@ -1214,21 +1215,22 @@
return rcomplex.c_div((v[0], -v[1]), (a2, 0.))
except ZeroDivisionError:
return rfloat.NAN, rfloat.NAN
+
+ # No floor, ceil, trunc in numpy for complex
+ #@simple_unary_op
+ #def floor(self, v):
+ # return math.floor(v)
- @simple_unary_op
- def floor(self, v):
- return math.floor(v)
+ #@simple_unary_op
+ #def ceil(self, v):
+ # return math.ceil(v)
- @simple_unary_op
- def ceil(self, v):
- return math.ceil(v)
-
- @simple_unary_op
- def trunc(self, v):
- if v < 0:
- return math.ceil(v)
- else:
- return math.floor(v)
+ #@simple_unary_op
+ #def trunc(self, v):
+ # if v < 0:
+ # return math.ceil(v)
+ # else:
+ # return math.floor(v)
@complex_unary_op
def exp(self, v):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit