[pypy-commit] pypy ndarray-attributes: merge with numpypy-problems
mattip
noreply at buildbot.pypy.org
Tue Aug 21 23:47:05 CEST 2012
Author: mattip <matti.picus at gmail.com>
Branch: ndarray-attributes
Changeset: r56785:09c48270379e
Date: 2012-08-22 00:46 +0300
http://bitbucket.org/pypy/pypy/changeset/09c48270379e/
Log: merge with numpypy-problems
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
@@ -432,6 +432,7 @@
W_VoidBox.typedef = TypeDef("void", W_FlexibleBox.typedef,
__module__ = "numpypy",
+ __new__ = interp2app(W_VoidBox.descr__new__.im_func),
__getitem__ = interp2app(W_VoidBox.descr_getitem),
__setitem__ = interp2app(W_VoidBox.descr_setitem),
)
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
@@ -176,10 +178,15 @@
def test_cant_subclass(self):
from _numpypy import dtype
-
# You can't subclass dtype
raises(TypeError, type, "Foo", (dtype,), {})
+ def test_can_subclass(self):
+ import _numpypy
+ class xyz(_numpypy.void):
+ pass
+ assert True
+
def test_aliases(self):
from _numpypy import dtype
@@ -228,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)
@@ -269,7 +287,9 @@
def test_int8(self):
import _numpypy as numpy
- assert numpy.int8.mro() == [numpy.int8, numpy.signedinteger, numpy.integer, numpy.number, numpy.generic, object]
+ assert numpy.int8.mro() == [numpy.int8, numpy.signedinteger,
+ numpy.integer, numpy.number,
+ numpy.generic, object]
a = numpy.array([1, 2, 3], numpy.int8)
assert type(a[1]) is numpy.int8
@@ -291,7 +311,9 @@
def test_uint8(self):
import _numpypy as numpy
- assert numpy.uint8.mro() == [numpy.uint8, numpy.unsignedinteger, numpy.integer, numpy.number, numpy.generic, object]
+ assert numpy.uint8.mro() == [numpy.uint8, numpy.unsignedinteger,
+ numpy.integer, numpy.number,
+ numpy.generic, object]
a = numpy.array([1, 2, 3], numpy.uint8)
assert type(a[1]) is numpy.uint8
@@ -361,16 +383,22 @@
import _numpypy as numpy
assert numpy.int_ is numpy.dtype(int).type
- assert numpy.int_.mro() == [numpy.int_, numpy.signedinteger, numpy.integer, numpy.number, numpy.generic, int, object]
+ assert numpy.int_.mro() == [numpy.int_, numpy.signedinteger,
+ numpy.integer, numpy.number,
+ numpy.generic, int, object]
def test_int64(self):
import sys
import _numpypy as numpy
if sys.maxint == 2 ** 63 -1:
- assert numpy.int64.mro() == [numpy.int64, numpy.signedinteger, numpy.integer, numpy.number, numpy.generic, int, object]
+ assert numpy.int64.mro() == [numpy.int64, numpy.signedinteger,
+ numpy.integer, numpy.number,
+ numpy.generic, int, object]
else:
- assert numpy.int64.mro() == [numpy.int64, numpy.signedinteger, numpy.integer, numpy.number, numpy.generic, object]
+ assert numpy.int64.mro() == [numpy.int64, numpy.signedinteger,
+ numpy.integer, numpy.number,
+ numpy.generic, object]
assert numpy.dtype(numpy.int64).type is numpy.int64
assert numpy.int64(3) == 3
@@ -385,7 +413,9 @@
import sys
import _numpypy as numpy
- assert numpy.uint64.mro() == [numpy.uint64, numpy.unsignedinteger, numpy.integer, numpy.number, numpy.generic, object]
+ assert numpy.uint64.mro() == [numpy.uint64, numpy.unsignedinteger,
+ numpy.integer, numpy.number,
+ numpy.generic, object]
assert numpy.dtype(numpy.uint64).type is numpy.uint64
skip("see comment")
@@ -400,7 +430,9 @@
def test_float32(self):
import _numpypy as numpy
- assert numpy.float32.mro() == [numpy.float32, numpy.floating, numpy.inexact, numpy.number, numpy.generic, object]
+ assert numpy.float32.mro() == [numpy.float32, numpy.floating,
+ numpy.inexact, numpy.number,
+ numpy.generic, object]
assert numpy.float32(12) == numpy.float64(12)
assert numpy.float32('23.4') == numpy.float32(23.4)
@@ -409,7 +441,9 @@
def test_float64(self):
import _numpypy as numpy
- assert numpy.float64.mro() == [numpy.float64, numpy.floating, numpy.inexact, numpy.number, numpy.generic, float, object]
+ assert numpy.float64.mro() == [numpy.float64, numpy.floating,
+ numpy.inexact, numpy.number,
+ numpy.generic, float, object]
a = numpy.array([1, 2, 3], numpy.float64)
assert type(a[1]) is numpy.float64
@@ -450,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
@@ -504,6 +539,11 @@
assert dtype('=i8').byteorder == '='
assert dtype(byteorder + 'i8').byteorder == '='
+ def test_intp(self):
+ from _numpypy import dtype
+ assert dtype('p') == dtype('intp')
+ assert dtype('P') == dtype('uintp')
+
def test_alignment(self):
from _numpypy import dtype
assert dtype('i4').alignment == 4
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -2261,4 +2261,17 @@
assert arr[1]['y']['y'] == 3.5
assert arr[1]['y']['x'] == 0.0
assert arr[1]['x'] == 15
-
+
+ def test_string_record(self):
+ from _numpypy import dtype, array
+ d = dtype([('x', str), ('y', 'int32')])
+ assert d.fields['x'] == (dtype(str), 0)
+ assert d.fields['y'] == (dtype('int32'), 1)
+ d = dtype([('x', 'S1'), ('y', 'int32')])
+ assert d.fields['x'] == (dtype(str), 0)
+ assert d.fields['y'] == (dtype('int32'), 1)
+ a = array([('a', 2), ('c', 1)], dtype=d)
+ assert a[0]['x'] == 'a'
+ assert a[1]['y'] == 1
+
+
diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -1,3 +1,6 @@
+"""
+This whole file is DEPRECATED. Use jit_libffi.py instead.
+"""
from __future__ import with_statement
from pypy.rpython.lltypesystem import rffi, lltype
More information about the pypy-commit
mailing list