Author: mattip <[email protected]>
Branch: numpypy-problems
Changeset: r56759:6171c097bef0
Date: 2012-08-19 22:58 +0300
http://bitbucket.org/pypy/pypy/changeset/6171c097bef0/
Log: add intp, uintp dtypes
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
@@ -8,6 +8,7 @@
from pypy.module.micronumpy import types, interp_boxes
from pypy.rlib.objectmodel import specialize
from pypy.rlib.rarithmetic import LONG_BIT, r_longlong, r_ulonglong
+from pypy.rpython.lltypesystem import rffi
UNSIGNEDLTR = "u"
@@ -17,6 +18,8 @@
VOIDLTR = 'V'
STRINGLTR = 'S'
UNICODELTR = 'U'
+INTPLTR = 'p'
+UINTPLTR = 'P'
class W_Dtype(Wrappable):
_immutable_fields_ = ["itemtype", "num", "kind"]
@@ -415,6 +418,35 @@
#alternate_constructors=[space.w_buffer],
# XXX no buffer in space
)
+ ptr_size = rffi.sizeof(rffi.CCHARP)
+ if ptr_size == 4:
+ intp_box = interp_boxes.W_Int32Box
+ intp_type = types.Int32()
+ uintp_box = interp_boxes.W_UInt32Box
+ uintp_type = types.UInt32()
+ elif ptr_size == 8:
+ intp_box = interp_boxes.W_Int64Box
+ intp_type = types.Int64()
+ uintp_box = interp_boxes.W_UInt64Box
+ uintp_type = types.UInt64()
+ else:
+ raise ValueError('unknown point size %d' % ptr_size)
+ self.w_intpdtype = W_Dtype(
+ intp_type,
+ num=5,
+ kind=INTPLTR,
+ name='intp',
+ char=INTPLTR,
+ w_box_type = space.gettypefor(intp_box),
+ )
+ self.w_uintpdtype = W_Dtype(
+ uintp_type,
+ num=6,
+ kind=UINTPLTR,
+ name='uintp',
+ char=UINTPLTR,
+ w_box_type = space.gettypefor(uintp_box),
+ )
self.builtin_dtypes = [
self.w_booldtype, self.w_int8dtype, self.w_uint8dtype,
self.w_int16dtype, self.w_uint16dtype, self.w_int32dtype,
@@ -422,7 +454,7 @@
self.w_int64dtype, self.w_uint64dtype,
self.w_float32dtype,
self.w_float64dtype, self.w_stringdtype, self.w_unicodedtype,
- self.w_voiddtype,
+ self.w_voiddtype, self.w_intpdtype, self.w_uintpdtype,
]
self.float_dtypes_by_num_bytes = sorted(
(dtype.itemtype.get_element_size(), dtype)
@@ -464,7 +496,8 @@
#'CDOUBLE',
#'DATETIME',
'UINT': self.w_uint32dtype,
- 'INTP': self.w_longdtype,
+ 'INTP': self.w_intpdtype,
+ 'UINTP': self.w_uintpdtype,
#'HALF',
'BYTE': self.w_int8dtype,
#'CFLOAT': ,
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
@@ -31,6 +31,8 @@
from _numpypy import dtype
assert dtype(bool).num == 0
+ assert dtype('intp').num == 5
+ assert dtype('uintp').num == 6
assert dtype(int).num == 7
assert dtype(long).num == 9
assert dtype(float).num == 12
@@ -233,6 +235,17 @@
class AppTestTypes(BaseNumpyAppTest):
+ def setup_class(cls):
+ BaseNumpyAppTest.setup_class.im_func(cls)
+ if option.runappdirect:
+ import platform
+ bits, linkage = platform.architecture()
+ ptr_size = int(bits[:-3]) // 8
+ else:
+ from pypy.rpython.lltypesystem import rffi
+ ptr_size = rffi.sizeof(rffi.CCHARP)
+ cls.w_ptr_size = cls.space.wrap(ptr_size)
+
def test_abstract_types(self):
import _numpypy as numpy
raises(TypeError, numpy.generic, 0)
@@ -471,15 +484,16 @@
def test_various_types(self):
import _numpypy as numpy
- import sys
assert numpy.int16 is numpy.short
assert numpy.int8 is numpy.byte
assert numpy.bool_ is numpy.bool8
- if sys.maxint == (1 << 63) - 1:
+ if self.ptr_size == 4:
+ assert numpy.intp is numpy.int32
+ assert numpy.uintp is numpy.uint32
+ elif self.ptr_size == 8:
assert numpy.intp is numpy.int64
- else:
- assert numpy.intp is numpy.int32
+ assert numpy.uintp is numpy.uint64
def test_mro(self):
import _numpypy as numpy
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit