Author: mattip <[email protected]>
Branch: numpypy-longdouble
Changeset: r59580:11f0a83b4131
Date: 2012-12-25 08:46 +0200
http://bitbucket.org/pypy/pypy/changeset/11f0a83b4131/
Log: test, implement clongdouble
diff --git a/pypy/module/micronumpy/__init__.py
b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -73,6 +73,8 @@
'complex_': 'interp_boxes.W_Complex128Box',
'complex128': 'interp_boxes.W_Complex128Box',
'complex64': 'interp_boxes.W_Complex64Box',
+ 'clongdouble': 'interp_boxes.W_CLongDoubleBox',
+ 'clongfloat': 'interp_boxes.W_CLongDoubleBox',
}
# ufuncs
@@ -169,5 +171,7 @@
if long_double_size == 16:
Module.interpleveldefs['float128'] = 'interp_boxes.W_Float128Box'
+ Module.interpleveldefs['complex256'] = 'interp_boxes.W_Complex256Box'
elif long_double_size == 12:
Module.interpleveldefs['float96'] = 'interp_boxes.W_Float96Box'
+ Module.interpleveldefs['complex192'] = 'interp_boxes.W_Complex192Box'
diff --git a/pypy/module/micronumpy/interp_boxes.py
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -230,17 +230,6 @@
class W_Float64Box(W_FloatingBox, PrimitiveBox):
descr__new__, _get_dtype = new_dtype_getter("float64")
-if long_double_size == 12:
- class W_Float96Box(W_FloatingBox, PrimitiveBox):
- descr__new__, _get_dtype = new_dtype_getter("float96")
- W_LongDoubleBox = W_Float96Box
-elif long_double_size == 16:
- class W_Float128Box(W_FloatingBox, PrimitiveBox):
- descr__new__, _get_dtype = new_dtype_getter("float128")
- W_LongDoubleBox = W_Float128Box
-else:
- W_LongDoubleBox = W_Float64Box
-
class W_FlexibleBox(W_GenericBox):
def __init__(self, arr, ofs, dtype):
self.arr = arr # we have to keep array alive
@@ -329,6 +318,33 @@
descr__new__, _get_dtype = new_dtype_getter("complex128")
_COMPONENTS_BOX = W_Float64Box
+if long_double_size == 12:
+ class W_Float96Box(W_FloatingBox, PrimitiveBox):
+ descr__new__, _get_dtype = new_dtype_getter("float96")
+
+ W_LongDoubleBox = W_Float96Box
+
+ class W_Complex192Box(ComplexBox, W_ComplexFloatingBox):
+ descr__new__, _get_dtype = new_dtype_getter("complex192")
+ _COMPONENTS_BOX = W_Float96Box
+
+ W_CLongDoubleBox = W_Complex192Box
+
+elif long_double_size == 16:
+ class W_Float128Box(W_FloatingBox, PrimitiveBox):
+ descr__new__, _get_dtype = new_dtype_getter("float128")
+ W_LongDoubleBox = W_Float128Box
+
+ class W_Complex256Box(ComplexBox, W_ComplexFloatingBox):
+ descr__new__, _get_dtype = new_dtype_getter("complex256")
+ _COMPONENTS_BOX = W_Float128Box
+
+ W_CLongDoubleBox = W_Complex256Box
+
+else:
+ W_LongDoubleBox = W_Float64Box
+ W_CLongDoubleBox = W_Complex64Box
+
W_GenericBox.typedef = TypeDef("generic",
__module__ = "numpypy",
@@ -499,6 +515,14 @@
__new__ = interp2app(W_Float96Box.descr__new__.im_func),
)
+
+ W_Complex192Box.typedef = TypeDef("complex192",
(W_ComplexFloatingBox.typedef, complex_typedef),
+ __module__ = "numpypy",
+ __new__ = interp2app(W_Complex192Box.descr__new__.im_func),
+ real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
+ imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
+ )
+
elif long_double_size == 16:
W_Float128Box.typedef = TypeDef("float128", (W_FloatingBox.typedef),
__module__ = "numpypy",
@@ -506,6 +530,13 @@
__new__ = interp2app(W_Float128Box.descr__new__.im_func),
)
+ W_Complex256Box.typedef = TypeDef("complex256",
(W_ComplexFloatingBox.typedef, complex_typedef),
+ __module__ = "numpypy",
+ __new__ = interp2app(W_Complex256Box.descr__new__.im_func),
+ real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
+ imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
+ )
+
W_FlexibleBox.typedef = TypeDef("flexible", W_GenericBox.typedef,
__module__ = "numpypy",
)
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
@@ -15,6 +15,7 @@
SIGNEDLTR = "i"
BOOLLTR = "b"
FLOATINGLTR = "f"
+COMPLEXLTR = "c"
VOIDLTR = 'V'
STRINGLTR = 'S'
UNICODELTR = 'U'
@@ -135,7 +136,7 @@
return self.kind == SIGNEDLTR
def is_complex_type(self):
- return (self.num == 14 or self.num == 15)
+ return (self.num == 14 or self.num == 15 or self.num == 16)
def is_bool_type(self):
return self.kind == BOOLLTR
@@ -423,6 +424,19 @@
aliases=["longfloat", "longdouble"],
)
longdouble = self.w_float96dtype
+
+ self.w_complex192dtype = W_Dtype(
+ types.Complex192(),
+ num=16,
+ kind=COMPLEXLTR,
+ name="complex192",
+ char="G",
+ w_box_type = space.gettypefor(interp_boxes.W_Complex192Box),
+ alternate_constructors=[space.w_complex],
+ aliases=["clongdouble", "clongfloat"],
+ )
+ clongdouble = self.w_complex192type
+
elif interp_boxes.long_double_size == 16:
self.w_float128dtype = W_Dtype(
types.Float128(),
@@ -434,13 +448,26 @@
aliases=["longfloat", "longdouble"],
)
longdouble = self.w_float128dtype
+
+ self.w_complex256dtype = W_Dtype(
+ types.Complex256(),
+ num=16,
+ kind=COMPLEXLTR,
+ name="complex256",
+ char="G",
+ w_box_type = space.gettypefor(interp_boxes.W_Complex256Box),
+ alternate_constructors=[space.w_complex],
+ aliases=["clongdouble", "clongfloat"],
+ )
+ clongdouble = self.w_complex256dtype
else:
self.w_float64type.aliases += ["longfloat", "longdouble"]
longdouble = self.w_float64dtype
+ clongdouble = self.w_complex64type
self.w_complex64dtype = W_Dtype(
types.Complex64(),
num=14,
- kind=FLOATINGLTR,
+ kind=COMPLEXLTR,
name="complex64",
char="F",
w_box_type = space.gettypefor(interp_boxes.W_Complex64Box),
@@ -448,7 +475,7 @@
self.w_complex128dtype = W_Dtype(
types.Complex128(),
num=15,
- kind=FLOATINGLTR,
+ kind=COMPLEXLTR,
name="complex128",
char="D",
w_box_type = space.gettypefor(interp_boxes.W_Complex128Box),
@@ -527,7 +554,7 @@
self.w_int64dtype, self.w_uint64dtype,
self.w_float16dtype, self.w_float32dtype, self.w_float64dtype,
longdouble,
- self.w_complex64dtype, self.w_complex128dtype,
+ self.w_complex64dtype, self.w_complex128dtype, clongdouble,
self.w_stringdtype, self.w_unicodedtype,
self.w_voiddtype, self.w_intpdtype, self.w_uintpdtype,
]
@@ -569,7 +596,7 @@
#'OBJECT',
'ULONGLONG': self.w_uint64dtype,
'STRING': self.w_stringdtype,
- #'CDOUBLE',
+ 'CDOUBLE': self.w_complex64dtype,
#'DATETIME',
'UINT': self.w_uint32dtype,
'INTP': self.w_intpdtype,
@@ -583,7 +610,7 @@
'USHORT': self.w_uint16dtype,
'FLOAT': self.w_float32dtype,
'BOOL': self.w_booldtype,
- #, 'CLONGDOUBLE']
+ 'CLONGDOUBLE': clongdouble,
}
typeinfo_partial = {
'Generic': interp_boxes.W_GenericBox,
@@ -593,7 +620,7 @@
'Integer': interp_boxes.W_IntegerBox,
'SignedInteger': interp_boxes.W_SignedIntegerBox,
'UnsignedInteger': interp_boxes.W_UnsignedIntegerBox,
- #'ComplexFloating',
+ 'ComplexFloating': interp_boxes.W_ComplexFloatingBox,
'Number': interp_boxes.W_NumberBox,
'Floating': interp_boxes.W_FloatingBox
}
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
@@ -376,11 +376,11 @@
return interp_dtype.get_dtype_cache(space).w_int8dtype
# Everything promotes to complex
- if dt2.num == 14 or dt2.num == 15 or dt1.num == 14 or dt2.num == 15:
- if dt2.num == 15 or dt1.num == 15:
+ if dt2.is_complex_type() or dt1.is_complex_type():
+ if dt2.num == 14 and dt1.num == 14:
+ return interp_dtype.get_dtype_cache(space).w_complex64dtype
+ else:
return interp_dtype.get_dtype_cache(space).w_complex128dtype
- else:
- return interp_dtype.get_dtype_cache(space).w_complex64dtype
if promote_to_float:
return find_unaryop_result_dtype(space, dt2, promote_to_float=True)
@@ -431,7 +431,7 @@
if not allow_complex and (dt.is_complex_type()):
raise OperationError(space.w_TypeError, space.wrap("Unsupported
types"))
if promote_to_float:
- if dt.kind == interp_dtype.FLOATINGLTR:
+ if dt.kind == interp_dtype.FLOATINGLTR or
dt.kind==interp_dtype.COMPLEXLTR:
return dt
if dt.num >= 5:
return interp_dtype.get_dtype_cache(space).w_float64dtype
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
@@ -139,7 +139,6 @@
def test_fmax(self):
from _numpypy import fmax, array
- import math
nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'),
float('-inf')
a = array((complex(ninf, 10), complex(10, ninf),
complex( inf, 10), complex(10, inf),
@@ -167,7 +166,6 @@
def test_fmin(self):
from _numpypy import fmin, array
- import math
nnan, nan, inf, ninf = float('-nan'), float('nan'), float('inf'),
float('-inf')
a = array((complex(ninf, 10), complex(10, ninf),
complex( inf, 10), complex(10, inf),
@@ -198,7 +196,7 @@
raises(TypeError, signbit, complex(1,1))
def test_reciprocal(self):
- from _numpypy import array, reciprocal, complex64, complex128
+ from _numpypy import array, reciprocal, complex64, complex128,
clongdouble
inf = float('inf')
nan = float('nan')
@@ -214,7 +212,7 @@
complex(-r, i),
-0j, 0j, cnan,
cnan, cnan, cnan]
- for c, rel_err in ((complex64, 2e-7), (complex128, 2e-15), ):
+ for c, rel_err in ((complex64, 2e-7), (complex128, 2e-15),
(clongdouble, 2e-15)):
actual = reciprocal(array([orig], dtype=c))
for b, a, e in zip(orig, actual, expected):
assert (a[0].real - e.real) < rel_err
@@ -234,13 +232,12 @@
raises(TypeError, copysign, a, b)
def test_exp2(self):
- import math
- from _numpypy import array, exp2, complex128, complex64
+ from _numpypy import array, exp2, complex128, complex64, clongfloat
inf = float('inf')
ninf = -float('inf')
nan = float('nan')
cmpl = complex
- for c,rel_err in ((complex128, 2e-15), (complex64, 1e-7)):
+ for c,rel_err in ((complex128, 2e-15), (complex64, 1e-7), (clongfloat,
2e-15)):
a = [cmpl(-5., 0), cmpl(-5., -5.), cmpl(-5., 5.),
cmpl(0., -5.), cmpl(0., 0.), cmpl(0., 5.),
cmpl(-0., -5.), cmpl(-0., 0.), cmpl(-0., 5.),
@@ -499,7 +496,7 @@
def test_basic(self):
from _numpypy import (complex128, complex64, add, array, dtype,
subtract as sub, multiply, divide, negative, abs, floor_divide,
- real, imag, sign)
+ real, imag, sign, clongfloat)
from _numpypy import (equal, not_equal, greater, greater_equal, less,
less_equal, isnan)
assert real(4.0) == 4.0
@@ -507,7 +504,7 @@
a = array([complex(3.0, 4.0)])
b = a.real
assert b.dtype == dtype(float)
- for complex_ in complex64, complex128:
+ for complex_ in complex64, complex128, clongfloat:
O = complex(0, 0)
c0 = complex_(complex(2.5, 0))
diff --git a/pypy/module/micronumpy/test/test_dtypes.py
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -540,6 +540,12 @@
assert numpy.dtype(complex).type is numpy.complex128
assert numpy.dtype("complex").type is numpy.complex128
+ d = numpy.dtype('complex64')
+ assert d.kind == 'c'
+ assert d.num == 14
+ assert d.char == 'F'
+
+
def test_subclass_type(self):
import _numpypy as numpy
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
@@ -1002,35 +1002,6 @@
BoxType = interp_boxes.W_Float64Box
format_code = "d"
-if interp_boxes.long_double_size == 12:
- class Float96(BaseType, Float):
- _attrs_ = ()
-
- T = rffi.LONGDOUBLE
- BoxType = interp_boxes.W_Float96Box
- format_code = "q"
-
- class NonNativeFloat96(Float96):
- pass
-
-
-elif interp_boxes.long_double_size == 16:
- class Float128(BaseType, Float):
- _attrs_ = ()
-
- T = rffi.LONGDOUBLE
- BoxType = interp_boxes.W_Float128Box
- format_code = "q"
-
- def runpack_str(self, s):
- assert len(s) == 16
- fval = unpack_float128(s, native_is_bigendian)
- return self.box(fval)
-
- class NonNativeFloat128(Float128):
- pass
-
-
class ComplexFloating(object):
_mixin_ = True
_attrs_ = ()
@@ -1526,7 +1497,6 @@
ComponentBoxType = interp_boxes.W_Float32Box
-
NonNativeComplex64 = Complex64
class Complex128(ComplexFloating, BaseType):
@@ -1540,6 +1510,56 @@
NonNativeComplex128 = Complex128
+if interp_boxes.long_double_size == 12:
+ class Float96(BaseType, Float):
+ _attrs_ = ()
+
+ T = rffi.LONGDOUBLE
+ BoxType = interp_boxes.W_Float96Box
+ format_code = "q"
+
+ class NonNativeFloat96(Float96):
+ pass
+
+ class Complex192(ComplexFloating, BaseType):
+ _attrs_ = ()
+
+ T = rffi.CHAR
+ _COMPONENTS_T = rffi.LONGDOUBLE
+ BoxType = interp_boxes.W_Complex192Box
+ ComponentBoxType = interp_boxes.W_Float96Box
+
+
+ NonNativeComplex192 = Complex192
+
+
+elif interp_boxes.long_double_size == 16:
+ class Float128(BaseType, Float):
+ _attrs_ = ()
+
+ T = rffi.LONGDOUBLE
+ BoxType = interp_boxes.W_Float128Box
+ format_code = "q"
+
+ def runpack_str(self, s):
+ assert len(s) == 16
+ fval = unpack_float128(s, native_is_bigendian)
+ return self.box(fval)
+
+ class NonNativeFloat128(Float128):
+ pass
+
+ class Complex256(ComplexFloating, BaseType):
+ _attrs_ = ()
+
+ T = rffi.CHAR
+ _COMPONENTS_T = rffi.LONGDOUBLE
+ BoxType = interp_boxes.W_Complex256Box
+ ComponentBoxType = interp_boxes.W_Float128Box
+
+
+ NonNativeComplex256 = Complex256
+
class BaseStringType(object):
_mixin_ = True
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit