Author: Brian Kearns <[email protected]>
Branch:
Changeset: r69353:a55cda9fb045
Date: 2014-02-24 09:03 -0500
http://bitbucket.org/pypy/pypy/changeset/a55cda9fb045/
Log: remove duplication of name attribute on dtype descriptors
diff --git a/pypy/module/micronumpy/arrayimpl/sort.py
b/pypy/module/micronumpy/arrayimpl/sort.py
--- a/pypy/module/micronumpy/arrayimpl/sort.py
+++ b/pypy/module/micronumpy/arrayimpl/sort.py
@@ -177,7 +177,7 @@
# XXX this should probably be changed
raise oefmt(space.w_NotImplementedError,
"sorting of non-numeric types '%s' is not implemented",
- arr.dtype.name)
+ arr.dtype.get_name())
all_types = (types.all_float_types + types.all_complex_types +
types.all_int_types)
@@ -320,7 +320,7 @@
# XXX this should probably be changed
raise oefmt(space.w_NotImplementedError,
"sorting of non-numeric types '%s' is not implemented",
- arr.dtype.name)
+ arr.dtype.get_name())
all_types = (types.all_float_types + types.all_complex_types +
types.all_int_types)
diff --git a/pypy/module/micronumpy/compile.py
b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -218,7 +218,7 @@
return w_type.lookup(name)
def gettypefor(self, w_obj):
- return None
+ return W_TypeObject(w_obj.typedef.name)
def call_function(self, tp, w_dtype):
return w_dtype
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
@@ -38,20 +38,19 @@
class W_Dtype(W_Root):
_immutable_fields_ = [
- "num", "kind", "name", "char", "w_box_type", "float_type",
+ "num", "kind", "char", "w_box_type", "float_type",
"itemtype?", "byteorder?", "names?", "fields?", "size?",
"shape?", "subdtype?", "base?",
"alternate_constructors", "aliases",
]
- def __init__(self, itemtype, num, kind, name, char, w_box_type,
+ def __init__(self, itemtype, num, kind, char, w_box_type,
float_type=None, byteorder=None, names=[], fields={},
size=1, shape=[], subdtype=None,
alternate_constructors=[], aliases=[]):
self.itemtype = itemtype
self.num = num
self.kind = kind
- self.name = name
self.char = char
self.w_box_type = w_box_type
self.float_type = float_type
@@ -180,10 +179,16 @@
return space.w_None
return space.newtuple([space.wrap(self.subdtype),
self.descr_get_shape(space)])
+ def get_name(self):
+ return self.w_box_type.name
+
def descr_get_name(self, space):
+ name = self.get_name()
+ if name[-1] == '_':
+ name = name[:-1]
if self.is_flexible_type():
- return space.wrap(self.name + str(self.get_size() * 8))
- return space.wrap(self.name)
+ return space.wrap(name + str(self.get_size() * 8))
+ return space.wrap(name)
def descr_get_str(self, space):
size = self.get_size()
@@ -290,8 +295,8 @@
def descr_getitem(self, space, w_item):
if not self.fields:
- raise OperationError(space.w_KeyError, space.wrap(
- "There are no fields in dtype %s." % self.name))
+ raise oefmt(space.w_KeyError, "There are no fields in dtype %s.",
+ self.get_name())
if space.isinstance_w(w_item, space.w_basestring):
item = space.str_w(w_item)
elif space.isinstance_w(w_item, space.w_int):
@@ -421,7 +426,7 @@
elif newendian != NPY.IGNORE:
endian = newendian
itemtype = self.itemtype.__class__(endian in (NPY.NATIVE, NPY.NATBYTE))
- return W_Dtype(itemtype, self.num, self.kind, self.name, self.char,
+ return W_Dtype(itemtype, self.num, self.kind, self.char,
self.w_box_type, self.float_type, byteorder=endian,
size=self.size)
@@ -455,8 +460,8 @@
fields[fldname] = (offset, subdtype)
offset += subdtype.get_size()
names.append(fldname)
- return W_Dtype(types.RecordType(), NPY.VOID, NPY.VOIDLTR, "void",
- NPY.VOIDLTR, space.gettypefor(interp_boxes.W_VoidBox),
+ return W_Dtype(types.RecordType(), NPY.VOID, NPY.VOIDLTR, NPY.VOIDLTR,
+ space.gettypefor(interp_boxes.W_VoidBox),
names=names, fields=fields, size=offset)
@@ -496,11 +501,10 @@
size *= dim
if size == 1:
return subdtype
- return W_Dtype(types.VoidType(), NPY.VOID, NPY.VOIDLTR,
- "void" + str(8 * subdtype.get_size() * size),
- NPY.VOIDLTR, space.gettypefor(interp_boxes.W_VoidBox),
- shape=shape, subdtype=subdtype,
- size=subdtype.get_size() * size)
+ size *= subdtype.get_size()
+ return W_Dtype(types.VoidType(), NPY.VOID, NPY.VOIDLTR, NPY.VOIDLTR,
+ space.gettypefor(interp_boxes.W_VoidBox),
+ shape=shape, subdtype=subdtype, size=size)
if space.is_none(w_dtype):
return cache.w_float64dtype
@@ -615,7 +619,6 @@
size=size,
num=NPY.STRING,
kind=NPY.STRINGLTR,
- name='string',
char=NPY.STRINGLTR,
w_box_type=space.gettypefor(interp_boxes.W_StringBox),
)
@@ -627,7 +630,6 @@
size=size,
num=NPY.UNICODE,
kind=NPY.UNICODELTR,
- name='unicode',
char=NPY.UNICODELTR,
w_box_type=space.gettypefor(interp_boxes.W_UnicodeBox),
)
@@ -639,7 +641,6 @@
size=size,
num=NPY.VOID,
kind=NPY.VOIDLTR,
- name='void',
char=NPY.VOIDLTR,
w_box_type=space.gettypefor(interp_boxes.W_VoidBox),
)
@@ -651,17 +652,15 @@
types.Bool(),
num=NPY.BOOL,
kind=NPY.GENBOOLLTR,
- name="bool",
char=NPY.BOOLLTR,
w_box_type=space.gettypefor(interp_boxes.W_BoolBox),
alternate_constructors=[space.w_bool],
- aliases=['bool8'],
+ aliases=['bool', 'bool8'],
)
self.w_int8dtype = W_Dtype(
types.Int8(),
num=NPY.BYTE,
kind=NPY.SIGNEDLTR,
- name="int8",
char=NPY.BYTELTR,
w_box_type=space.gettypefor(interp_boxes.W_Int8Box),
aliases=['byte'],
@@ -670,7 +669,6 @@
types.UInt8(),
num=NPY.UBYTE,
kind=NPY.UNSIGNEDLTR,
- name="uint8",
char=NPY.UBYTELTR,
w_box_type=space.gettypefor(interp_boxes.W_UInt8Box),
aliases=['ubyte'],
@@ -679,7 +677,6 @@
types.Int16(),
num=NPY.SHORT,
kind=NPY.SIGNEDLTR,
- name="int16",
char=NPY.SHORTLTR,
w_box_type=space.gettypefor(interp_boxes.W_Int16Box),
aliases=['short'],
@@ -688,7 +685,6 @@
types.UInt16(),
num=NPY.USHORT,
kind=NPY.UNSIGNEDLTR,
- name="uint16",
char=NPY.USHORTLTR,
w_box_type=space.gettypefor(interp_boxes.W_UInt16Box),
aliases=['ushort'],
@@ -697,7 +693,6 @@
types.Int32(),
num=NPY.INT,
kind=NPY.SIGNEDLTR,
- name="int32",
char=NPY.INTLTR,
w_box_type=space.gettypefor(interp_boxes.W_Int32Box),
)
@@ -705,7 +700,6 @@
types.UInt32(),
num=NPY.UINT,
kind=NPY.UNSIGNEDLTR,
- name="uint32",
char=NPY.UINTLTR,
w_box_type=space.gettypefor(interp_boxes.W_UInt32Box),
)
@@ -713,31 +707,28 @@
types.Long(),
num=NPY.LONG,
kind=NPY.SIGNEDLTR,
- name="int%d" % LONG_BIT,
char=NPY.LONGLTR,
w_box_type=space.gettypefor(interp_boxes.W_LongBox),
alternate_constructors=[space.w_int,
space.gettypefor(interp_boxes.W_IntegerBox),
space.gettypefor(interp_boxes.W_SignedIntegerBox),
],
- aliases=['int'],
+ aliases=['int', 'intp', 'p'],
)
self.w_ulongdtype = W_Dtype(
types.ULong(),
num=NPY.ULONG,
kind=NPY.UNSIGNEDLTR,
- name="uint%d" % LONG_BIT,
char=NPY.ULONGLTR,
w_box_type=space.gettypefor(interp_boxes.W_ULongBox),
alternate_constructors=[space.gettypefor(interp_boxes.W_UnsignedIntegerBox),
],
- aliases=['uint'],
+ aliases=['uint', 'uintp', 'P'],
)
self.w_int64dtype = W_Dtype(
types.Int64(),
num=NPY.LONGLONG,
kind=NPY.SIGNEDLTR,
- name="int64",
char=NPY.LONGLONGLTR,
w_box_type=space.gettypefor(interp_boxes.W_Int64Box),
alternate_constructors=[space.w_long],
@@ -747,7 +738,6 @@
types.UInt64(),
num=NPY.ULONGLONG,
kind=NPY.UNSIGNEDLTR,
- name="uint64",
char=NPY.ULONGLONGLTR,
w_box_type=space.gettypefor(interp_boxes.W_UInt64Box),
aliases=['ulonglong'],
@@ -756,7 +746,6 @@
types.Float32(),
num=NPY.FLOAT,
kind=NPY.FLOATINGLTR,
- name="float32",
char=NPY.FLOATLTR,
w_box_type=space.gettypefor(interp_boxes.W_Float32Box),
aliases=['single']
@@ -765,9 +754,8 @@
types.Float64(),
num=NPY.DOUBLE,
kind=NPY.FLOATINGLTR,
- name="float64",
char=NPY.DOUBLELTR,
- w_box_type = space.gettypefor(interp_boxes.W_Float64Box),
+ w_box_type=space.gettypefor(interp_boxes.W_Float64Box),
alternate_constructors=[space.w_float,
space.gettypefor(interp_boxes.W_NumberBox),
space.gettypefor(interp_boxes.W_FloatingBox),
@@ -778,7 +766,6 @@
types.FloatLong(),
num=NPY.LONGDOUBLE,
kind=NPY.FLOATINGLTR,
- name="float%d" % (interp_boxes.long_double_size * 8),
char=NPY.LONGDOUBLELTR,
w_box_type=space.gettypefor(interp_boxes.W_FloatLongBox),
aliases=["longdouble", "longfloat"],
@@ -787,9 +774,8 @@
types.Complex64(),
num=NPY.CFLOAT,
kind=NPY.COMPLEXLTR,
- name="complex64",
char=NPY.CFLOATLTR,
- w_box_type = space.gettypefor(interp_boxes.W_Complex64Box),
+ w_box_type=space.gettypefor(interp_boxes.W_Complex64Box),
aliases=['csingle'],
float_type=NPY.FLOATLTR,
)
@@ -797,9 +783,8 @@
types.Complex128(),
num=NPY.CDOUBLE,
kind=NPY.COMPLEXLTR,
- name="complex128",
char=NPY.CDOUBLELTR,
- w_box_type = space.gettypefor(interp_boxes.W_Complex128Box),
+ w_box_type=space.gettypefor(interp_boxes.W_Complex128Box),
alternate_constructors=[space.w_complex,
space.gettypefor(interp_boxes.W_ComplexFloatingBox)],
aliases=["complex", 'cfloat', 'cdouble'],
@@ -809,9 +794,8 @@
types.ComplexLong(),
num=NPY.CLONGDOUBLE,
kind=NPY.COMPLEXLTR,
- name="complex%d" % (interp_boxes.long_double_size * 16),
char=NPY.CLONGDOUBLELTR,
- w_box_type = space.gettypefor(interp_boxes.W_ComplexLongBox),
+ w_box_type=space.gettypefor(interp_boxes.W_ComplexLongBox),
aliases=["clongdouble", "clongfloat"],
float_type=NPY.LONGDOUBLELTR,
)
@@ -820,31 +804,29 @@
size=0,
num=NPY.STRING,
kind=NPY.STRINGLTR,
- name='string',
char=NPY.STRINGLTR,
- w_box_type = space.gettypefor(interp_boxes.W_StringBox),
+ w_box_type=space.gettypefor(interp_boxes.W_StringBox),
alternate_constructors=[space.w_str,
space.gettypefor(interp_boxes.W_CharacterBox)],
- aliases=["str"],
+ aliases=['string', "str"],
)
self.w_unicodedtype = W_Dtype(
types.UnicodeType(),
size=0,
num=NPY.UNICODE,
kind=NPY.UNICODELTR,
- name='unicode',
char=NPY.UNICODELTR,
- w_box_type = space.gettypefor(interp_boxes.W_UnicodeBox),
+ w_box_type=space.gettypefor(interp_boxes.W_UnicodeBox),
alternate_constructors=[space.w_unicode],
+ aliases=['unicode'],
)
self.w_voiddtype = W_Dtype(
types.VoidType(),
size=0,
num=NPY.VOID,
kind=NPY.VOIDLTR,
- name='void',
char=NPY.VOIDLTR,
- w_box_type = space.gettypefor(interp_boxes.W_VoidBox),
+ w_box_type=space.gettypefor(interp_boxes.W_VoidBox),
#alternate_constructors=[space.w_buffer],
# XXX no buffer in space
#alternate_constructors=[space.gettypefor(interp_boxes.W_GenericBox)],
@@ -854,7 +836,6 @@
types.Float16(),
num=NPY.HALF,
kind=NPY.FLOATINGLTR,
- name="float16",
char=NPY.HALFLTR,
w_box_type=space.gettypefor(interp_boxes.W_Float16Box),
)
@@ -862,17 +843,15 @@
types.Long(),
num=NPY.LONG,
kind=NPY.SIGNEDLTR,
- name='intp',
char=NPY.INTPLTR,
- w_box_type = space.gettypefor(interp_boxes.W_LongBox),
+ w_box_type=space.gettypefor(interp_boxes.W_LongBox),
)
self.w_uintpdtype = W_Dtype(
types.ULong(),
num=NPY.ULONG,
kind=NPY.UNSIGNEDLTR,
- name='uintp',
char=NPY.UINTPLTR,
- w_box_type = space.gettypefor(interp_boxes.W_ULongBox),
+ w_box_type=space.gettypefor(interp_boxes.W_ULongBox),
)
float_dtypes = [self.w_float16dtype, self.w_float32dtype,
self.w_float64dtype, self.w_floatlongdtype]
@@ -900,7 +879,7 @@
for dtype in reversed(self.builtin_dtypes):
dtype.fields = None # mark these as builtin
self.dtypes_by_num[dtype.num] = dtype
- self.dtypes_by_name[dtype.name] = dtype
+ self.dtypes_by_name[dtype.get_name()] = dtype
for can_name in [dtype.kind + str(dtype.get_size()),
dtype.char]:
self.dtypes_by_name[can_name] = dtype
diff --git a/pypy/module/micronumpy/interp_numarray.py
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -573,7 +573,8 @@
space.call_function(space.gettypefor(interp_dtype.W_Dtype),
w_dtype))
if new_dtype.num == NPY.VOID:
raise oefmt(space.w_NotImplementedError,
- "%s.astype(%s) not implemented yet", cur_dtype.name,
new_dtype.name)
+ "astype(%s) not implemented yet",
+ new_dtype.get_name())
if new_dtype.num == NPY.STRING and new_dtype.size == 0:
if cur_dtype.num == NPY.STRING:
new_dtype = interp_dtype.variable_dtype(space,
@@ -1029,7 +1030,7 @@
except AttributeError:
raise oefmt(space.w_NotImplementedError,
'%s not implemented for %s',
- op_name, self.get_dtype().name)
+ op_name, self.get_dtype().get_name())
return space.wrap(res)
return func_with_new_name(impl, "reduce_arg%s_impl" % op_name)
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
@@ -386,8 +386,9 @@
return space.w_NotImplemented
else:
raise oefmt(space.w_TypeError,
- 'unsupported operand dtypes %s and %s for "%s"',
- w_rdtype.name, w_ldtype.name, self.name)
+ 'unsupported operand dtypes %s and %s for "%s"',
+ w_rdtype.get_name(), w_ldtype.get_name(),
+ self.name)
if self.are_common_types(w_ldtype, w_rdtype):
if not w_lhs.is_scalar() and w_rhs.is_scalar():
@@ -612,7 +613,7 @@
except AttributeError:
raise oefmt(space.w_NotImplementedError,
"%s not implemented for %s",
- ufunc_name, dtype.name)
+ ufunc_name, dtype.get_name())
if argcount == 1:
def impl(res_dtype, value):
res = get_op(res_dtype)(value)
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
@@ -900,22 +900,22 @@
def test_intp(self):
from numpypy import dtype
- assert dtype('p') is dtype('intp')
- assert dtype('P') is dtype('uintp')
- #assert dtype('p') is dtype('int')
- #assert dtype('P') is dtype('uint')
+ for s in ['p', 'int']:
+ assert dtype(s) is dtype('intp')
+ for s in ['P', 'uint']:
+ assert dtype(s) is dtype('uintp')
assert dtype('p').num == 7
assert dtype('P').num == 8
- #assert dtype('p').char == 'l'
- #assert dtype('P').char == 'L'
+ assert dtype('p').char == 'l'
+ assert dtype('P').char == 'L'
assert dtype('p').kind == 'i'
assert dtype('P').kind == 'u'
- #if self.ptr_size == 4:
- # assert dtype('p').name == 'int32'
- # assert dtype('P').name == 'uint32'
- #else:
- # assert dtype('p').name == 'int64'
- # assert dtype('P').name == 'uint64'
+ if self.ptr_size == 4:
+ assert dtype('p').name == 'int32'
+ assert dtype('P').name == 'uint32'
+ else:
+ assert dtype('p').name == 'int64'
+ assert dtype('P').name == 'uint64'
def test_alignment(self):
from numpypy import dtype
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -60,6 +60,8 @@
pass
class W_MyType(W_MyObject):
+ name = "foobar"
+
def __init__(self):
self.mro_w = [w_some_obj(), w_some_obj()]
self.dict_w = {'__str__': w_some_obj()}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit