Author: Ronan Lamy <[email protected]>
Branch: can_cast
Changeset: r76914:05d75330bba0
Date: 2015-04-24 06:00 +0100
http://bitbucket.org/pypy/pypy/changeset/05d75330bba0/
Log: remove num, kind, char from W_Dtype
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
@@ -42,18 +42,12 @@
class W_Dtype(W_Root):
_immutable_fields_ = [
- "itemtype?", "num", "kind", "char", "w_box_type",
- "byteorder?", "names?", "fields?", "elsize?", "alignment?",
- "shape?", "subdtype?", "base?",
- ]
+ "itemtype?", "w_box_type", "byteorder?", "names?", "fields?",
+ "elsize?", "alignment?", "shape?", "subdtype?", "base?"]
- def __init__(self, itemtype, num, kind, char, w_box_type,
- byteorder=None, names=[], fields={},
- elsize=None, shape=[], subdtype=None):
+ def __init__(self, itemtype, w_box_type, byteorder=None, names=[],
+ fields={}, elsize=None, shape=[], subdtype=None):
self.itemtype = itemtype
- self.num = num
- self.kind = kind
- self.char = char
self.w_box_type = w_box_type
if byteorder is None:
if itemtype.get_element_size() == 1 or isinstance(itemtype,
types.ObjectType):
@@ -74,6 +68,18 @@
else:
self.base = subdtype.base
+ @property
+ def num(self):
+ return self.itemtype.num
+
+ @property
+ def kind(self):
+ return self.itemtype.kind
+
+ @property
+ def char(self):
+ return self.itemtype.char
+
def __repr__(self):
if self.fields:
return '<DType %r>' % self.fields
@@ -453,7 +459,7 @@
fields = self.fields
if fields is None:
fields = {}
- return W_Dtype(itemtype, self.num, self.kind, self.char,
+ return W_Dtype(itemtype,
self.w_box_type, byteorder=endian, elsize=self.elsize,
names=self.names, fields=fields,
shape=self.shape, subdtype=self.subdtype)
@@ -488,8 +494,7 @@
fields[fldname] = (offset, subdtype)
offset += subdtype.elsize
names.append(fldname)
- return W_Dtype(types.RecordType(space), NPY.VOID, NPY.VOIDLTR, NPY.VOIDLTR,
- space.gettypefor(boxes.W_VoidBox),
+ return W_Dtype(types.RecordType(space), space.gettypefor(boxes.W_VoidBox),
names=names, fields=fields, elsize=offset)
@@ -556,7 +561,7 @@
if size == 1:
return subdtype
size *= subdtype.elsize
- return W_Dtype(types.VoidType(space), NPY.VOID, NPY.VOIDLTR,
NPY.VOIDLTR,
+ return W_Dtype(types.VoidType(space),
space.gettypefor(boxes.W_VoidBox),
shape=shape, subdtype=subdtype, elsize=size)
@@ -657,7 +662,10 @@
except ValueError:
raise oefmt(space.w_TypeError, "data type not understood")
if char == NPY.CHARLTR:
- return new_string_dtype(space, 1, NPY.CHARLTR)
+ return W_Dtype(
+ types.CharType(space),
+ elsize=1,
+ w_box_type=space.gettypefor(boxes.W_StringBox))
elif char == NPY.STRINGLTR or char == NPY.STRINGLTR2:
return new_string_dtype(space, size)
elif char == NPY.UNICODELTR:
@@ -667,13 +675,10 @@
assert False
-def new_string_dtype(space, size, char=NPY.STRINGLTR):
+def new_string_dtype(space, size):
return W_Dtype(
types.StringType(space),
elsize=size,
- num=NPY.STRING,
- kind=NPY.STRINGLTR,
- char=char,
w_box_type=space.gettypefor(boxes.W_StringBox),
)
@@ -683,9 +688,6 @@
return W_Dtype(
itemtype,
elsize=size * itemtype.get_element_size(),
- num=NPY.UNICODE,
- kind=NPY.UNICODELTR,
- char=NPY.UNICODELTR,
w_box_type=space.gettypefor(boxes.W_UnicodeBox),
)
@@ -694,9 +696,6 @@
return W_Dtype(
types.VoidType(space),
elsize=size,
- num=NPY.VOID,
- kind=NPY.VOIDLTR,
- char=NPY.VOIDLTR,
w_box_type=space.gettypefor(boxes.W_VoidBox),
)
@@ -705,159 +704,93 @@
def __init__(self, space):
self.w_booldtype = W_Dtype(
types.Bool(space),
- num=NPY.BOOL,
- kind=NPY.GENBOOLLTR,
- char=NPY.BOOLLTR,
w_box_type=space.gettypefor(boxes.W_BoolBox),
)
self.w_int8dtype = W_Dtype(
types.Int8(space),
- num=NPY.BYTE,
- kind=NPY.SIGNEDLTR,
- char=NPY.BYTELTR,
w_box_type=space.gettypefor(boxes.W_Int8Box),
)
self.w_uint8dtype = W_Dtype(
types.UInt8(space),
- num=NPY.UBYTE,
- kind=NPY.UNSIGNEDLTR,
- char=NPY.UBYTELTR,
w_box_type=space.gettypefor(boxes.W_UInt8Box),
)
self.w_int16dtype = W_Dtype(
types.Int16(space),
- num=NPY.SHORT,
- kind=NPY.SIGNEDLTR,
- char=NPY.SHORTLTR,
w_box_type=space.gettypefor(boxes.W_Int16Box),
)
self.w_uint16dtype = W_Dtype(
types.UInt16(space),
- num=NPY.USHORT,
- kind=NPY.UNSIGNEDLTR,
- char=NPY.USHORTLTR,
w_box_type=space.gettypefor(boxes.W_UInt16Box),
)
self.w_int32dtype = W_Dtype(
types.Int32(space),
- num=NPY.INT,
- kind=NPY.SIGNEDLTR,
- char=NPY.INTLTR,
w_box_type=space.gettypefor(boxes.W_Int32Box),
)
self.w_uint32dtype = W_Dtype(
types.UInt32(space),
- num=NPY.UINT,
- kind=NPY.UNSIGNEDLTR,
- char=NPY.UINTLTR,
w_box_type=space.gettypefor(boxes.W_UInt32Box),
)
self.w_longdtype = W_Dtype(
types.Long(space),
- num=NPY.LONG,
- kind=NPY.SIGNEDLTR,
- char=NPY.LONGLTR,
w_box_type=space.gettypefor(boxes.W_LongBox),
)
self.w_ulongdtype = W_Dtype(
types.ULong(space),
- num=NPY.ULONG,
- kind=NPY.UNSIGNEDLTR,
- char=NPY.ULONGLTR,
w_box_type=space.gettypefor(boxes.W_ULongBox),
)
self.w_int64dtype = W_Dtype(
types.Int64(space),
- num=NPY.LONGLONG,
- kind=NPY.SIGNEDLTR,
- char=NPY.LONGLONGLTR,
w_box_type=space.gettypefor(boxes.W_Int64Box),
)
self.w_uint64dtype = W_Dtype(
types.UInt64(space),
- num=NPY.ULONGLONG,
- kind=NPY.UNSIGNEDLTR,
- char=NPY.ULONGLONGLTR,
w_box_type=space.gettypefor(boxes.W_UInt64Box),
)
self.w_float32dtype = W_Dtype(
types.Float32(space),
- num=NPY.FLOAT,
- kind=NPY.FLOATINGLTR,
- char=NPY.FLOATLTR,
w_box_type=space.gettypefor(boxes.W_Float32Box),
)
self.w_float64dtype = W_Dtype(
types.Float64(space),
- num=NPY.DOUBLE,
- kind=NPY.FLOATINGLTR,
- char=NPY.DOUBLELTR,
w_box_type=space.gettypefor(boxes.W_Float64Box),
)
self.w_floatlongdtype = W_Dtype(
types.FloatLong(space),
- num=NPY.LONGDOUBLE,
- kind=NPY.FLOATINGLTR,
- char=NPY.LONGDOUBLELTR,
w_box_type=space.gettypefor(boxes.W_FloatLongBox),
)
self.w_complex64dtype = W_Dtype(
types.Complex64(space),
- num=NPY.CFLOAT,
- kind=NPY.COMPLEXLTR,
- char=NPY.CFLOATLTR,
w_box_type=space.gettypefor(boxes.W_Complex64Box),
)
self.w_complex128dtype = W_Dtype(
types.Complex128(space),
- num=NPY.CDOUBLE,
- kind=NPY.COMPLEXLTR,
- char=NPY.CDOUBLELTR,
w_box_type=space.gettypefor(boxes.W_Complex128Box),
)
self.w_complexlongdtype = W_Dtype(
types.ComplexLong(space),
- num=NPY.CLONGDOUBLE,
- kind=NPY.COMPLEXLTR,
- char=NPY.CLONGDOUBLELTR,
w_box_type=space.gettypefor(boxes.W_ComplexLongBox),
)
self.w_stringdtype = W_Dtype(
types.StringType(space),
elsize=0,
- num=NPY.STRING,
- kind=NPY.STRINGLTR,
- char=NPY.STRINGLTR,
w_box_type=space.gettypefor(boxes.W_StringBox),
)
self.w_unicodedtype = W_Dtype(
types.UnicodeType(space),
elsize=0,
- num=NPY.UNICODE,
- kind=NPY.UNICODELTR,
- char=NPY.UNICODELTR,
w_box_type=space.gettypefor(boxes.W_UnicodeBox),
)
self.w_voiddtype = W_Dtype(
types.VoidType(space),
elsize=0,
- num=NPY.VOID,
- kind=NPY.VOIDLTR,
- char=NPY.VOIDLTR,
w_box_type=space.gettypefor(boxes.W_VoidBox),
)
self.w_float16dtype = W_Dtype(
types.Float16(space),
- num=NPY.HALF,
- kind=NPY.FLOATINGLTR,
- char=NPY.HALFLTR,
w_box_type=space.gettypefor(boxes.W_Float16Box),
)
self.w_objectdtype = W_Dtype(
types.ObjectType(space),
- num=NPY.OBJECT,
- kind=NPY.OBJECTLTR,
- char=NPY.OBJECTLTR,
w_box_type=space.gettypefor(boxes.W_ObjectBox),
)
aliases = {
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
@@ -2267,6 +2267,9 @@
"item() for Void aray with no fields not implemented"))
return space.newtuple(ret_unwrapped)
+class CharType(StringType):
+ char = NPY.CHARLTR
+
class RecordType(FlexibleType):
T = lltype.Char
num = NPY.VOID
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit