[pypy-commit] pypy object-dtype: small progress
fijal
noreply at buildbot.pypy.org
Wed Dec 10 16:47:38 CET 2014
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: object-dtype
Changeset: r74879:8471e5574836
Date: 2014-12-10 17:19 +0200
http://bitbucket.org/pypy/pypy/changeset/8471e5574836/
Log: small progress
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -601,6 +601,10 @@
# arr.storage[i] = arg[i]
return W_UnicodeBox(arr, 0, arr.dtype)
+class W_ObjectBox(W_GenericBox):
+ def __init__(self, w_obj):
+ self.w_obj = w_obj
+
W_GenericBox.typedef = TypeDef("numpy.generic",
__new__ = interp2app(W_GenericBox.descr__new__.im_func),
diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -850,6 +850,13 @@
char=NPY.UINTPLTR,
w_box_type=space.gettypefor(boxes.W_ULongBox),
)
+ self.w_objectdtype = W_Dtype(
+ types.ObjectType(),
+ num=NPY.OBJECT,
+ kind=NPY.OBJECTLTR,
+ char=NPY.OBJECTLTR,
+ w_box_type=space.gettypefor(boxes.W_ObjectBox),
+ )
aliases = {
NPY.BOOL: ['bool_', 'bool8'],
NPY.BYTE: ['byte'],
@@ -868,6 +875,7 @@
NPY.CLONGDOUBLE: ['clongdouble', 'clongfloat'],
NPY.STRING: ['string_', 'str'],
NPY.UNICODE: ['unicode_'],
+ NPY.OBJECT: ['object_'],
}
self.alternate_constructors = {
NPY.BOOL: [space.w_bool],
@@ -886,6 +894,8 @@
NPY.UNICODE: [space.w_unicode],
NPY.VOID: [space.gettypefor(boxes.W_GenericBox)],
#space.w_buffer, # XXX no buffer in space
+ NPY.OBJECT: [space.gettypefor(boxes.W_ObjectBox),
+ space.w_object],
}
float_dtypes = [self.w_float16dtype, self.w_float32dtype,
self.w_float64dtype, self.w_floatlongdtype]
@@ -905,7 +915,7 @@
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,
+ self.w_intpdtype, self.w_uintpdtype, self.w_objectdtype,
]
self.float_dtypes_by_num_bytes = sorted(
(dtype.elsize, dtype)
@@ -957,6 +967,7 @@
'USHORT': self.w_uint16dtype,
'FLOAT': self.w_float32dtype,
'BOOL': self.w_booldtype,
+ 'OBJECT': self.w_objectdtype,
}
typeinfo_partial = {
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
@@ -1614,6 +1614,20 @@
BoxType = boxes.W_ComplexLongBox
ComponentBoxType = boxes.W_FloatLongBox
+class ObjectType(BaseType):
+ T = lltype.Signed
+
+ def get_element_size(self):
+ return rffi.sizeof(lltype.Signed)
+
+ def coerce(self, space, dtype, w_item):
+ if isinstance(w_item, boxes.W_ObjectBox):
+ return w_item
+ return boxes.W_ObjectBox(w_item)
+
+ def store(self, arr, i, offset, box):
+ self._write(arr.storage, i, offset, self.unbox(box))
+
class FlexibleType(BaseType):
def get_element_size(self):
return rffi.sizeof(self.T)
More information about the pypy-commit
mailing list