Author: mattip <[email protected]>
Branch: numpypy-complex2
Changeset: r57711:64ccb5d32b9f
Date: 2012-10-01 23:28 +0200
http://bitbucket.org/pypy/pypy/changeset/64ccb5d32b9f/
Log: Merge within branch
diff --git a/pypy/module/micronumpy/test/test_complex.py
b/pypy/module/micronumpy/test/test_complex.py
--- a/pypy/module/micronumpy/test/test_complex.py
+++ b/pypy/module/micronumpy/test/test_complex.py
@@ -262,7 +262,8 @@
def test_not_complex(self):
from _numpypy import (radians, deg2rad, degrees, rad2deg,
- isneginf, isposinf, logaddexp, logaddexp2, fmod)
+ isneginf, isposinf, logaddexp, logaddexp2, fmod,
+ max, min)
raises(TypeError, radians, complex(90,90))
raises(TypeError, deg2rad, complex(90,90))
raises(TypeError, degrees, complex(90,90))
@@ -272,6 +273,8 @@
raises(TypeError, logaddexp, complex(1, 1), complex(3, 3))
raises(TypeError, logaddexp2, complex(1, 1), complex(3, 3))
raises (TypeError, fmod, complex(90,90), 3)
+ raises (TypeError, min, complex(90,90), 3)
+ raises (TypeError, max, complex(90,90), 3)
def test_isnan_isinf(self):
from _numpypy import isnan, isinf, array
@@ -414,6 +417,38 @@
if got_err:
raise AssertionError('Errors were printed to stdout')
+ def test_logical_ops(self):
+ from _numpypy import logical_and, logical_or, logical_xor, logical_not
+
+ c1 = complex(1, 1)
+ c3 = complex(3, 0)
+ c0 = complex(0, 0)
+ assert (logical_and([True, False , True, True], [c1, c1, c3, c0])
+ == [True, False, True, False]).all()
+ assert (logical_or([True, False, True, False], [c1, c3, c0, c0])
+ == [True, True, True, False]).all()
+ assert (logical_xor([True, False, True, False], [c1, c3, c0, c0])
+ == [False, True, True, False]).all()
+ assert (logical_not([c1, c0]) == [False, True]).all()
+
+ def test_minimum(self):
+ from _numpypy import array, minimum
+
+ a = array([-5.0+5j, -5.0-5j, -0.0-10j, 1.0+10j])
+ b = array([ 3.0+10.0j, 3.0, -2.0+2.0j, -3.0+4.0j])
+ c = minimum(a, b)
+ for i in range(4):
+ assert c[i] == min(a[i], b[i])
+
+ def test_maximum(self):
+ from _numpypy import array, maximum
+
+ a = array([-5.0+5j, -5.0-5j, -0.0-10j, 1.0+10j])
+ b = array([ 3.0+10.0j, 3.0, -2.0+2.0j, -3.0+4.0j])
+ c = maximum(a, b)
+ for i in range(4):
+ assert c[i] == max(a[i], b[i])
+
def test_basic(self):
from _numpypy import (complex128, complex64, add,
subtract as sub, multiply, divide, negative, abs,
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
@@ -55,7 +55,7 @@
def dispatcher(self, v):
from pypy.module.micronumpy.interp_boxes import W_GenericBox
assert isinstance(v, W_GenericBox)
- return self.RealBoxType(
+ return self.box_component(
func(
self,
self.for_computation(self.unbox(v))
@@ -991,6 +991,11 @@
rffi.cast(self._COMPONENTS_T, value),
rffi.cast(self._COMPONENTS_T, 0.0))
+ @specialize.argtype(1)
+ def box_component(self, value):
+ return self.ComponentBoxType(
+ rffi.cast(self._COMPONENTS_T, value))
+
@specialize.argtype(1, 2)
def box_complex(self, real, imag):
return self.BoxType(
@@ -1110,33 +1115,30 @@
def ge(self, v1, v2):
return self._lt(v2, v1) or self._eq(v2, v1)
+ def _bool(self, v):
+ return bool(v[0]) or bool(v[1])
+
@raw_binary_op
def logical_and(self, v1, v2):
- return bool(v1) and bool(v2)
+ return self._bool(v1) and self._bool(v2)
@raw_binary_op
def logical_or(self, v1, v2):
- return bool(v1) or bool(v2)
+ return self._bool(v1) or self._bool(v2)
@raw_unary_op
def logical_not(self, v):
- return not bool(v)
+ return not self._bool(v)
@raw_binary_op
def logical_xor(self, v1, v2):
- return bool(v1) ^ bool(v2)
+ return self._bool(v1) ^ self._bool(v2)
- def bool(self, v):
- return bool(self.for_computation(self.unbox(v)))
+ def min(self, v1, v2):
+ return self.fmin(v1, v2)
- @simple_binary_op
def max(self, v1, v2):
- return max(v1, v2)
-
- @simple_binary_op
- def min(self, v1, v2):
- return min(v1, v2)
-
+ return self.fmax(v1, v2)
@complex_binary_op
def floordiv(self, v1, v2):
@@ -1244,7 +1246,7 @@
def exp(self, v):
if math.isinf(v[1]):
if math.isinf(v[0]):
- if v[0]<0:
+ if v[0] < 0:
return 0., 0.
return rfloat.INFINITY, rfloat.NAN
elif (isfinite(v[0]) or \
@@ -1253,7 +1255,7 @@
try:
return rcomplex.c_exp(*v)
except OverflowError:
- if v[1]==0:
+ if v[1] == 0:
return rfloat.INFINITY, 0.0
return rfloat.INFINITY, rfloat.NAN
@@ -1272,7 +1274,7 @@
# to implement seterr
if math.isinf(v[1]):
if math.isinf(v[0]):
- if v[0]<0:
+ if v[0] < 0:
return -1., 0.
return rfloat.NAN, rfloat.NAN
elif (isfinite(v[0]) or \
@@ -1283,7 +1285,7 @@
res = (res[0]-1, res[1])
return res
except OverflowError:
- if v[1]==0:
+ if v[1] == 0:
return rfloat.INFINITY, 0.0
return rfloat.INFINITY, rfloat.NAN
@@ -1325,7 +1327,7 @@
@complex_unary_op
def arctan(self, v):
- if v[0]==0 and (v[1]==1 or v[1] == -1):
+ if v[0] == 0 and (v[1] == 1 or v[1] == -1):
#This is the place to print a "runtime warning"
return rfloat.NAN, math.copysign(rfloat.INFINITY, v[1])
return rcomplex.c_atan(*v)
@@ -1438,7 +1440,7 @@
@complex_unary_op
def log1p(self, v):
try:
- return rcomplex.c_log(v[0]+1, v[1])
+ return rcomplex.c_log(v[0] + 1, v[1])
except OverflowError:
return -rfloat.INFINITY, 0
except ValueError:
@@ -1450,7 +1452,7 @@
T = rffi.CHAR
_COMPONENTS_T = rffi.FLOAT
BoxType = interp_boxes.W_Complex64Box
- RealBoxType = interp_boxes.W_Float32Box
+ ComponentBoxType = interp_boxes.W_Float32Box
@@ -1462,7 +1464,7 @@
T = rffi.CHAR
_COMPONENTS_T = rffi.DOUBLE
BoxType = interp_boxes.W_Complex128Box
- RealBoxType = interp_boxes.W_Float64Box
+ ComponentBoxType = interp_boxes.W_Float64Box
NonNativeComplex128 = Complex128
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit