Author: Brian Kearns <[email protected]>
Branch:
Changeset: r67406:82f81f0ed787
Date: 2013-10-16 00:12 -0400
http://bitbucket.org/pypy/pypy/changeset/82f81f0ed787/
Log: provide long double based on double until rpython support is done
diff --git a/lib_pypy/numpypy/core/arrayprint.py
b/lib_pypy/numpypy/core/arrayprint.py
--- a/lib_pypy/numpypy/core/arrayprint.py
+++ b/lib_pypy/numpypy/core/arrayprint.py
@@ -247,10 +247,11 @@
formatdict = {'bool' : _boolFormatter,
'int' : IntegerFormat(data),
'float' : FloatFormat(data, precision, suppress_small),
- 'longfloat' : LongFloatFormat(precision),
+ 'longfloat' : FloatFormat(data, precision, suppress_small),
'complexfloat' : ComplexFormat(data, precision,
suppress_small),
- 'longcomplexfloat' : LongComplexFormat(precision),
+ 'longcomplexfloat' : ComplexFormat(data, precision,
+ suppress_small),
'datetime' : DatetimeFormat(data),
'timedelta' : TimedeltaFormat(data),
'numpystr' : repr_format,
diff --git a/lib_pypy/numpypy/core/numerictypes.py
b/lib_pypy/numpypy/core/numerictypes.py
--- a/lib_pypy/numpypy/core/numerictypes.py
+++ b/lib_pypy/numpypy/core/numerictypes.py
@@ -395,6 +395,9 @@
('int_', 'long'),
('uint', 'ulong'),
('cfloat', 'cdouble'),
+ ('longfloat', 'longdouble'),
+ ('clongfloat', 'clongdouble'),
+ ('longcomplex', 'clongdouble'),
('bool_', 'bool'),
('unicode_', 'unicode'),
]
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
@@ -1,5 +1,4 @@
from pypy.interpreter.mixedmodule import MixedModule
-from pypy.module.micronumpy.interp_boxes import long_double_size,
ENABLED_LONG_DOUBLE
class MultiArrayModule(MixedModule):
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
@@ -20,14 +20,14 @@
MIXIN_32 = (int_typedef,) if LONG_BIT == 32 else ()
MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else ()
-# Is this the proper place for this?
-ENABLED_LONG_DOUBLE = False
-long_double_size = rffi.sizeof_c_type('long double', ignore_errors=True)
+#long_double_size = rffi.sizeof_c_type('long double', ignore_errors=True)
+#import os
+#if long_double_size == 8 and os.name == 'nt':
+# # this is a lie, or maybe a wish, MS fakes longdouble math with double
+# long_double_size = 12
-import os
-if long_double_size == 8 and os.name == 'nt':
- # this is a lie, or maybe a wish, MS fakes longdouble math with double
- long_double_size = 12
+# hardcode to 8 for now (simulate using normal double) until long double works
+long_double_size = 8
def new_dtype_getter(name):
@@ -438,32 +438,18 @@
descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex128")
_COMPONENTS_BOX = W_Float64Box
-if ENABLED_LONG_DOUBLE and long_double_size == 12:
- class W_Float96Box(W_FloatingBox, PrimitiveBox):
- descr__new__, _get_dtype, descr_reduce = new_dtype_getter("float96")
- W_LongDoubleBox = W_Float96Box
+if long_double_size == 8:
+ W_FloatLongBox = W_Float64Box
+ W_ComplexLongBox = W_Complex128Box
- class W_Complex192Box(ComplexBox, W_ComplexFloatingBox):
- descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex192")
- _COMPONENTS_BOX = W_Float96Box
+elif long_double_size in (12, 16):
+ class W_FloatLongBox(W_FloatingBox, PrimitiveBox):
+ descr__new__, _get_dtype, descr_reduce = new_dtype_getter("float%d" %
long_double_size * 8)
- W_CLongDoubleBox = W_Complex192Box
-
-elif ENABLED_LONG_DOUBLE and long_double_size == 16:
- class W_Float128Box(W_FloatingBox, PrimitiveBox):
- descr__new__, _get_dtype, descr_reduce = new_dtype_getter("float128")
- W_LongDoubleBox = W_Float128Box
-
- class W_Complex256Box(ComplexBox, W_ComplexFloatingBox):
- descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex256")
- _COMPONENTS_BOX = W_Float128Box
-
- W_CLongDoubleBox = W_Complex256Box
-
-elif ENABLED_LONG_DOUBLE:
- W_LongDoubleBox = W_Float64Box
- W_CLongDoubleBox = W_Complex64Box
+ class W_ComplexLongBox(ComplexBox, W_ComplexFloatingBox):
+ descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex%d"
% long_double_size * 16)
+ _COMPONENTS_BOX = W_FloatLongBox
W_GenericBox.typedef = TypeDef("generic",
@@ -647,34 +633,18 @@
__reduce__ = interp2app(W_Float64Box.descr_reduce),
)
-if ENABLED_LONG_DOUBLE and long_double_size == 12:
- W_Float96Box.typedef = TypeDef("float96", (W_FloatingBox.typedef),
+if long_double_size in (12, 16):
+ W_FloatLongBox.typedef = TypeDef("float%d" % long_double_size * 8,
(W_FloatingBox.typedef),
__module__ = "numpypy",
- __reduce__ = interp2app(W_Float96Box.descr_reduce),
+ __reduce__ = interp2app(W_FloatLongBox.descr_reduce),
- __new__ = interp2app(W_Float96Box.descr__new__.im_func),
+ __new__ = interp2app(W_FloatLongBox.descr__new__.im_func),
)
- W_Complex192Box.typedef = TypeDef("complex192",
(W_ComplexFloatingBox.typedef, complex_typedef),
+ W_ComplexLongBox.typedef = TypeDef("complex%d" % long_double_size * 16,
(W_ComplexFloatingBox.typedef, complex_typedef),
__module__ = "numpypy",
- __new__ = interp2app(W_Complex192Box.descr__new__.im_func),
- __reduce__ = interp2app(W_Complex192Box.descr_reduce),
- real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
- imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
- )
-
-elif ENABLED_LONG_DOUBLE and long_double_size == 16:
- W_Float128Box.typedef = TypeDef("float128", (W_FloatingBox.typedef),
- __module__ = "numpypy",
-
- __new__ = interp2app(W_Float128Box.descr__new__.im_func),
- __reduce__ = interp2app(W_Float128Box.descr_reduce),
- )
-
- W_Complex256Box.typedef = TypeDef("complex256",
(W_ComplexFloatingBox.typedef, complex_typedef),
- __module__ = "numpypy",
- __new__ = interp2app(W_Complex256Box.descr__new__.im_func),
- __reduce__ = interp2app(W_Complex256Box.descr_reduce),
+ __new__ = interp2app(W_ComplexLongBox.descr__new__.im_func),
+ __reduce__ = interp2app(W_ComplexLongBox.descr_reduce),
real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
)
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
@@ -542,15 +542,11 @@
char="I",
w_box_type=space.gettypefor(interp_boxes.W_UInt32Box),
)
- if LONG_BIT == 32:
- name = "int32"
- elif LONG_BIT == 64:
- name = "int64"
self.w_longdtype = W_Dtype(
types.Long(),
num=7,
kind=SIGNEDLTR,
- name=name,
+ name="int%d" % LONG_BIT,
char="l",
w_box_type=space.gettypefor(interp_boxes.W_LongBox),
alternate_constructors=[space.w_int,
@@ -563,7 +559,7 @@
types.ULong(),
num=8,
kind=UNSIGNEDLTR,
- name="u" + name,
+ name="uint%d" % LONG_BIT,
char="L",
w_box_type=space.gettypefor(interp_boxes.W_ULongBox),
alternate_constructors=[
space.gettypefor(interp_boxes.W_UnsignedIntegerBox),
@@ -607,6 +603,15 @@
],
aliases=["float", "double"],
)
+ self.w_floatlongdtype = W_Dtype(
+ types.FloatLong(),
+ num=13,
+ kind=FLOATINGLTR,
+ name="float%d" % interp_boxes.long_double_size * 8,
+ char="g",
+ w_box_type=space.gettypefor(interp_boxes.W_FloatLongBox),
+ aliases=["longdouble", "longfloat"],
+ )
self.w_complex64dtype = W_ComplexDtype(
types.Complex64(),
num=14,
@@ -627,57 +632,16 @@
aliases=["complex"],
float_type = self.w_float64dtype,
)
- if interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size
== 12:
- self.w_float96dtype = W_Dtype(
- types.Float96(),
- num=13,
- kind=FLOATINGLTR,
- name="float96",
- char="g",
- w_box_type=space.gettypefor(interp_boxes.W_Float96Box),
- aliases=["longdouble", "longfloat"],
- )
- self.w_complex192dtype = W_ComplexDtype(
- 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"],
- float_type = self.w_float96dtype,
- )
- self.w_longdouble = self.w_float96dtype
- self.w_clongdouble = self.w_complex192dtype
- elif interp_boxes.ENABLED_LONG_DOUBLE and
interp_boxes.long_double_size == 16:
- self.w_float128dtype = W_Dtype(
- types.Float128(),
- num=13,
- kind=FLOATINGLTR,
- name="float128",
- char="g",
- w_box_type=space.gettypefor(interp_boxes.W_Float128Box),
- aliases=["longdouble", "longfloat"],
- )
- self.w_complex256dtype = W_ComplexDtype(
- 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"],
- float_type = self.w_float128dtype,
- )
- self.w_longdouble = self.w_float128dtype
- self.w_clongdouble = self.w_complex256dtype
- elif interp_boxes.ENABLED_LONG_DOUBLE:
- self.w_float64dtype.aliases += ["longdouble", "longfloat"]
- self.w_complex128dtype.aliases += ["clongdouble", "clongfloat"]
- self.w_longdouble = self.w_float64dtype
- self.w_clongdouble = self.w_complex128dtype
+ self.w_complexlongdtype = W_ComplexDtype(
+ types.ComplexLong(),
+ num=16,
+ kind=COMPLEXLTR,
+ name="complex%d" % interp_boxes.long_double_size * 16,
+ char="G",
+ w_box_type = space.gettypefor(interp_boxes.W_ComplexLongBox),
+ aliases=["clongdouble", "clongfloat"],
+ float_type = self.w_floatlongdtype,
+ )
self.w_stringdtype = W_Dtype(
types.StringType(0),
num=18,
@@ -750,21 +714,18 @@
char=UINTPLTR,
w_box_type = space.gettypefor(uintp_box),
)
- float_dtypes = [self.w_float16dtype,
- self.w_float32dtype, self.w_float64dtype,
- ]
- complex_dtypes = [self.w_complex64dtype, self.w_complex128dtype]
- if interp_boxes.ENABLED_LONG_DOUBLE:
- float_dtypes.append(self.w_longdouble)
- complex_dtypes.append(self.w_clongdouble)
+ float_dtypes = [self.w_float16dtype, self.w_float32dtype,
+ self.w_float64dtype, self.w_floatlongdtype]
+ complex_dtypes = [self.w_complex64dtype, self.w_complex128dtype,
+ self.w_complexlongdtype]
self.builtin_dtypes = [
self.w_booldtype,
self.w_int8dtype, self.w_uint8dtype,
self.w_int16dtype, self.w_uint16dtype,
self.w_longdtype, self.w_ulongdtype,
self.w_int32dtype, self.w_uint32dtype,
- self.w_int64dtype, self.w_uint64dtype] + \
- float_dtypes + complex_dtypes + [
+ self.w_int64dtype, self.w_uint64dtype,
+ ] + float_dtypes + complex_dtypes + [
self.w_stringdtype, self.w_unicodedtype, self.w_voiddtype,
self.w_intpdtype, self.w_uintpdtype,
]
@@ -818,6 +779,7 @@
'STRING': self.w_stringdtype,
'CFLOAT': self.w_complex64dtype,
'CDOUBLE': self.w_complex128dtype,
+ 'CLONGDOUBLE': self.w_complexlongdtype,
#'DATETIME',
'UINT': self.w_uint32dtype,
'INTP': self.w_intpdtype,
@@ -827,13 +789,11 @@
#'TIMEDELTA',
'INT': self.w_int32dtype,
'DOUBLE': self.w_float64dtype,
+ 'LONGDOUBLE': self.w_floatlongdtype,
'USHORT': self.w_uint16dtype,
'FLOAT': self.w_float32dtype,
'BOOL': self.w_booldtype,
}
- if interp_boxes.ENABLED_LONG_DOUBLE:
- typeinfo_full['LONGDOUBLE'] = self.w_longdouble
- typeinfo_full['CLONGDOUBLE'] = self.w_clongdouble
typeinfo_partial = {
'Generic': interp_boxes.W_GenericBox,
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
@@ -449,8 +449,8 @@
return interp_dtype.get_dtype_cache(space).w_complex64dtype
elif dt2.num == 15:
return interp_dtype.get_dtype_cache(space).w_complex128dtype
- elif interp_boxes.ENABLED_LONG_DOUBLE and dt2.num == 16:
- return interp_dtype.get_dtype_cache(space).w_clongdouble
+ elif dt2.num == 16:
+ return interp_dtype.get_dtype_cache(space).w_complexlongdtype
else:
raise OperationError(space.w_TypeError, space.wrap("Unsupported
types"))
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
@@ -196,13 +196,8 @@
raises(TypeError, signbit, complex(1,1))
def test_reciprocal(self):
- from numpypy import array, reciprocal, complex64, complex128
- c_and_relerr = [(complex64, 2e-7), (complex128, 2e-15)]
- try:
- from numpypy import clongdouble
- c_and_relerr.append((clongdouble, 2e-30))
- except:
- pass # no longdouble yet
+ from numpypy import array, reciprocal, complex64, complex128,
clongdouble
+ c_and_relerr = [(complex64, 2e-7), (complex128, 2e-15), (clongdouble,
2e-15)]
inf = float('inf')
nan = float('nan')
#complex
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
@@ -914,36 +914,7 @@
assert typeinfo['CDOUBLE'] == ('D', 15, 128, 8, complex128)
assert typeinfo['HALF'] == ('e', 23, 16, 2, float16)
-class AppTestNoLongDoubleDtypes(BaseNumpyAppTest):
- def setup_class(cls):
- from pypy.module.micronumpy import Module
- if Module.interpleveldefs.get('longfloat', None):
- py.test.skip('longdouble exists, skip these tests')
- if option.runappdirect and '__pypy__' not in sys.builtin_module_names:
- py.test.skip("pypy only test for no longdouble support")
- BaseNumpyAppTest.setup_class.im_func(cls)
-
- def test_nolongfloat(self):
- import numpypy
- from numpypy import dtype
- assert not getattr(numpypy, 'longdouble', False)
- assert not getattr(numpypy, 'float128', False)
- assert not getattr(numpypy, 'float96', False)
- raises(TypeError, dtype, 'longdouble')
- raises(TypeError, dtype, 'clongdouble')
- raises(TypeError, dtype, 'longfloat')
- raises(TypeError, dtype, 'clongfloat')
- raises(TypeError, dtype, 'float128')
- raises(TypeError, dtype, 'float96')
-
class AppTestLongDoubleDtypes(BaseNumpyAppTest):
- def setup_class(cls):
- from pypy.module.micronumpy import Module
- print dir(Module.interpleveldefs)
- if not Module.interpleveldefs.get('longfloat', None):
- py.test.skip('no longdouble types yet')
- BaseNumpyAppTest.setup_class.im_func(cls)
-
def test_longfloat(self):
import numpypy as numpy
# it can be float96 or float128
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
@@ -1661,16 +1661,22 @@
NonNativeComplex128 = Complex128
-if interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size == 12:
- class Float96(BaseType, Float):
+if interp_boxes.long_double_size == 8:
+ FloatLong = Float64
+ NonNativeFloatLong = NonNativeFloat64
+ ComplexLong = Complex128
+ NonNativeComplexLong = NonNativeComplex128
+
+elif interp_boxes.long_double_size in (12, 16):
+ class FloatLong(BaseType, Float):
_attrs_ = ()
T = rffi.LONGDOUBLE
- BoxType = interp_boxes.W_Float96Box
+ BoxType = interp_boxes.W_FloatLongBox
format_code = "q"
def runpack_str(self, s):
- assert len(s) == 12
+ assert len(s) == interp_boxes.long_double_size
fval = unpack_float80(s, native_is_bigendian)
return self.box(fval)
@@ -1680,46 +1686,17 @@
pack_float80(result, value, 10, not native_is_bigendian)
return self.box(unpack_float80(result.build(),
native_is_bigendian))
- NonNativeFloat96 = Float96
+ NonNativeFloatLong = FloatLong
- class Complex192(ComplexFloating, BaseType):
+ class ComplexLong(ComplexFloating, BaseType):
_attrs_ = ()
T = rffi.LONGDOUBLE
- BoxType = interp_boxes.W_Complex192Box
- ComponentBoxType = interp_boxes.W_Float96Box
+ BoxType = interp_boxes.W_ComplexLongBox
+ ComponentBoxType = interp_boxes.W_FloatLongBox
- NonNativeComplex192 = Complex192
+ NonNativeComplexLong = ComplexLong
-elif interp_boxes.ENABLED_LONG_DOUBLE and 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_float80(s, native_is_bigendian)
- return self.box(fval)
-
- def byteswap(self, w_v):
- value = self.unbox(w_v)
- result = StringBuilder(10)
- pack_float80(result, value, 10, not native_is_bigendian)
- return self.box(unpack_float80(result.build(),
native_is_bigendian))
-
- NonNativeFloat128 = Float128
-
- class Complex256(ComplexFloating, BaseType):
- _attrs_ = ()
-
- 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]
https://mail.python.org/mailman/listinfo/pypy-commit