Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r69298:cd03cd6fcd23 Date: 2014-02-23 16:12 -0500 http://bitbucket.org/pypy/pypy/changeset/cd03cd6fcd23/
Log: different pattern for micronumpy constants diff --git a/pypy/module/micronumpy/constants.py b/pypy/module/micronumpy/constants.py --- a/pypy/module/micronumpy/constants.py +++ b/pypy/module/micronumpy/constants.py @@ -1,88 +1,88 @@ -NPY_BOOL = 0 -NPY_BYTE = 1 -NPY_UBYTE = 2 -NPY_SHORT = 3 -NPY_USHORT = 4 -NPY_INT = 5 -NPY_UINT = 6 -NPY_LONG = 7 -NPY_ULONG = 8 -NPY_LONGLONG = 9 -NPY_ULONGLONG = 10 -NPY_FLOAT = 11 -NPY_DOUBLE = 12 -NPY_LONGDOUBLE = 13 -NPY_CFLOAT = 14 -NPY_CDOUBLE = 15 -NPY_CLONGDOUBLE = 16 -NPY_OBJECT = 17 -NPY_STRING = 18 -NPY_UNICODE = 19 -NPY_VOID = 20 -NPY_DATETIME = 21 -NPY_TIMEDELTA = 22 -NPY_HALF = 23 -NPY_NTYPES = 24 -NPY_NOTYPE = 25 -NPY_CHAR = 26 -NPY_USERDEF = 256 +BOOL = 0 +BYTE = 1 +UBYTE = 2 +SHORT = 3 +USHORT = 4 +INT = 5 +UINT = 6 +LONG = 7 +ULONG = 8 +LONGLONG = 9 +ULONGLONG = 10 +FLOAT = 11 +DOUBLE = 12 +LONGDOUBLE = 13 +CFLOAT = 14 +CDOUBLE = 15 +CLONGDOUBLE = 16 +OBJECT = 17 +STRING = 18 +UNICODE = 19 +VOID = 20 +DATETIME = 21 +TIMEDELTA = 22 +HALF = 23 +NTYPES = 24 +NOTYPE = 25 +CHAR = 26 +USERDEF = 256 -NPY_BOOLLTR = '?' -NPY_BYTELTR = 'b' -NPY_UBYTELTR = 'B' -NPY_SHORTLTR = 'h' -NPY_USHORTLTR = 'H' -NPY_INTLTR = 'i' -NPY_UINTLTR = 'I' -NPY_LONGLTR = 'l' -NPY_ULONGLTR = 'L' -NPY_LONGLONGLTR = 'q' -NPY_ULONGLONGLTR = 'Q' -NPY_HALFLTR = 'e' -NPY_FLOATLTR = 'f' -NPY_DOUBLELTR = 'd' -NPY_LONGDOUBLELTR = 'g' -NPY_CFLOATLTR = 'F' -NPY_CDOUBLELTR = 'D' -NPY_CLONGDOUBLELTR = 'G' -NPY_OBJECTLTR = 'O' -NPY_STRINGLTR = 'S' -NPY_STRINGLTR2 = 'a' -NPY_UNICODELTR = 'U' -NPY_VOIDLTR = 'V' -NPY_DATETIMELTR = 'M' -NPY_TIMEDELTALTR = 'm' -NPY_CHARLTR = 'c' +BOOLLTR = '?' +BYTELTR = 'b' +UBYTELTR = 'B' +SHORTLTR = 'h' +USHORTLTR = 'H' +INTLTR = 'i' +UINTLTR = 'I' +LONGLTR = 'l' +ULONGLTR = 'L' +LONGLONGLTR = 'q' +ULONGLONGLTR = 'Q' +HALFLTR = 'e' +FLOATLTR = 'f' +DOUBLELTR = 'd' +LONGDOUBLELTR = 'g' +CFLOATLTR = 'F' +CDOUBLELTR = 'D' +CLONGDOUBLELTR = 'G' +OBJECTLTR = 'O' +STRINGLTR = 'S' +STRINGLTR2 = 'a' +UNICODELTR = 'U' +VOIDLTR = 'V' +DATETIMELTR = 'M' +TIMEDELTALTR = 'm' +CHARLTR = 'c' -NPY_INTPLTR = 'p' -NPY_UINTPLTR = 'P' +INTPLTR = 'p' +UINTPLTR = 'P' -NPY_GENBOOLLTR ='b' -NPY_SIGNEDLTR = 'i' -NPY_UNSIGNEDLTR = 'u' -NPY_FLOATINGLTR = 'f' -NPY_COMPLEXLTR = 'c' +GENBOOLLTR ='b' +SIGNEDLTR = 'i' +UNSIGNEDLTR = 'u' +FLOATINGLTR = 'f' +COMPLEXLTR = 'c' -NPY_ANYORDER = -1 -NPY_CORDER = 0 -NPY_FORTRANORDER = 1 -NPY_KEEPORDER = 2 +ANYORDER = -1 +CORDER = 0 +FORTRANORDER = 1 +KEEPORDER = 2 -NPY_CLIP = 0 -NPY_WRAP = 1 -NPY_RAISE = 2 +CLIP = 0 +WRAP = 1 +RAISE = 2 -NPY_LITTLE = '<' -NPY_BIG = '>' -NPY_NATIVE = '=' -NPY_SWAP = 's' -NPY_IGNORE = '|' +LITTLE = '<' +BIG = '>' +NATIVE = '=' +SWAP = 's' +IGNORE = '|' import sys if sys.byteorder == 'big': - NPY_NATBYTE = NPY_BIG - NPY_OPPBYTE = NPY_LITTLE + NATBYTE = BIG + OPPBYTE = LITTLE else: - NPY_NATBYTE = NPY_LITTLE - NPY_OPPBYTE = NPY_BIG + NATBYTE = LITTLE + OPPBYTE = BIG del sys diff --git a/pypy/module/micronumpy/conversion_utils.py b/pypy/module/micronumpy/conversion_utils.py --- a/pypy/module/micronumpy/conversion_utils.py +++ b/pypy/module/micronumpy/conversion_utils.py @@ -1,21 +1,21 @@ from pypy.interpreter.error import OperationError -from pypy.module.micronumpy.constants import * +from pypy.module.micronumpy import constants as NPY def byteorder_converter(space, new_order): endian = new_order[0] - if endian not in (NPY_BIG, NPY_LITTLE, NPY_NATIVE, NPY_IGNORE, NPY_SWAP): + if endian not in (NPY.BIG, NPY.LITTLE, NPY.NATIVE, NPY.IGNORE, NPY.SWAP): ch = endian if ch in ('b', 'B'): - endian = NPY_BIG + endian = NPY.BIG elif ch in ('l', 'L'): - endian = NPY_LITTLE + endian = NPY.LITTLE elif ch in ('n', 'N'): - endian = NPY_NATIVE + endian = NPY.NATIVE elif ch in ('i', 'I'): - endian = NPY_IGNORE + endian = NPY.IGNORE elif ch in ('s', 'S'): - endian = NPY_SWAP + endian = NPY.SWAP else: raise OperationError(space.w_ValueError, space.wrap( "%s is an unrecognized byteorder" % new_order)) @@ -24,18 +24,18 @@ def clipmode_converter(space, w_mode): if space.is_none(w_mode): - return NPY_RAISE + return NPY.RAISE if space.isinstance_w(w_mode, space.w_str): mode = space.str_w(w_mode) if mode.startswith('C') or mode.startswith('c'): - return NPY_CLIP + return NPY.CLIP if mode.startswith('W') or mode.startswith('w'): - return NPY_WRAP + return NPY.WRAP if mode.startswith('R') or mode.startswith('r'): - return NPY_RAISE + return NPY.RAISE elif space.isinstance_w(w_mode, space.w_int): mode = space.int_w(w_mode) - if NPY_CLIP <= mode <= NPY_RAISE: + if NPY.CLIP <= mode <= NPY.RAISE: return mode raise OperationError(space.w_TypeError, space.wrap("clipmode not understood")) @@ -46,19 +46,19 @@ return default if not space.isinstance_w(w_order, space.w_str): if space.is_true(w_order): - return NPY_FORTRANORDER + return NPY.FORTRANORDER else: - return NPY_CORDER + return NPY.CORDER else: order = space.str_w(w_order) if order.startswith('C') or order.startswith('c'): - return NPY_CORDER + return NPY.CORDER elif order.startswith('F') or order.startswith('f'): - return NPY_FORTRANORDER + return NPY.FORTRANORDER elif order.startswith('A') or order.startswith('a'): - return NPY_ANYORDER + return NPY.ANYORDER elif order.startswith('K') or order.startswith('k'): - return NPY_KEEPORDER + return NPY.KEEPORDER else: raise OperationError(space.w_TypeError, space.wrap( "order not understood")) diff --git a/pypy/module/micronumpy/interp_arrayops.py b/pypy/module/micronumpy/interp_arrayops.py --- a/pypy/module/micronumpy/interp_arrayops.py +++ b/pypy/module/micronumpy/interp_arrayops.py @@ -6,7 +6,7 @@ from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import unwrap_spec from pypy.module.micronumpy.conversion_utils import clipmode_converter -from pypy.module.micronumpy.constants import * +from pypy.module.micronumpy import constants as NPY def where(space, w_arr, w_x=None, w_y=None): """where(condition, [x, y]) @@ -238,12 +238,12 @@ index = index_w(space, idx) if index < 0 or index >= arr.get_size(): - if mode == NPY_RAISE: + if mode == NPY.RAISE: raise OperationError(space.w_IndexError, space.wrap( "index %d is out of bounds for axis 0 with size %d" % (index, arr.get_size()))) - elif mode == NPY_WRAP: + elif mode == NPY.WRAP: index = index % arr.get_size() - elif mode == NPY_CLIP: + elif mode == NPY.CLIP: if index < 0: index = 0 else: 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 @@ -17,7 +17,7 @@ from rpython.rtyper.lltypesystem import lltype from rpython.rlib.rstring import StringBuilder from rpython.rlib import jit -from pypy.module.micronumpy.constants import NPY_LONGDOUBLELTR, NPY_CLONGDOUBLELTR +from pypy.module.micronumpy import constants as NPY MIXIN_32 = (W_IntObject.typedef,) if LONG_BIT == 32 else () @@ -445,10 +445,10 @@ if long_double_size in (8, 12, 16): class W_FloatLongBox(W_FloatingBox, PrimitiveBox): - descr__new__, _get_dtype, descr_reduce = new_dtype_getter(NPY_LONGDOUBLELTR) + descr__new__, _get_dtype, descr_reduce = new_dtype_getter(NPY.LONGDOUBLELTR) class W_ComplexLongBox(ComplexBox, W_ComplexFloatingBox): - descr__new__, _get_dtype, descr_reduce = new_dtype_getter(NPY_CLONGDOUBLELTR) + descr__new__, _get_dtype, descr_reduce = new_dtype_getter(NPY.CLONGDOUBLELTR) _COMPONENTS_BOX = W_FloatLongBox class W_FlexibleBox(W_GenericBox): 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 @@ -7,11 +7,10 @@ from pypy.module.micronumpy import types, interp_boxes, base from rpython.rlib.objectmodel import specialize from rpython.rlib.rarithmetic import LONG_BIT, r_longlong, r_ulonglong -from rpython.rtyper.lltypesystem import rffi from rpython.rlib import jit from pypy.module.micronumpy.appbridge import get_appbridge_cache from pypy.module.micronumpy.conversion_utils import byteorder_converter -from pypy.module.micronumpy.constants import * +from pypy.module.micronumpy import constants as NPY def decode_w_dtype(space, w_dtype): @@ -42,7 +41,7 @@ "w_box_type", "byteorder", "size?", "float_type", "fields?", "fieldnames?", "shape", "subdtype", "base"] - def __init__(self, itemtype, num, kind, name, char, w_box_type, byteorder=NPY_NATIVE, + def __init__(self, itemtype, num, kind, name, char, w_box_type, byteorder=NPY.NATIVE, size=1, alternate_constructors=[], aliases=[], float_type=None, fields=None, fieldnames=None, shape=[], subdtype=None): self.itemtype = itemtype @@ -87,35 +86,35 @@ return self.itemtype.coerce(space, self, w_item) def is_int_type(self): - return (self.kind == NPY_SIGNEDLTR or self.kind == NPY_UNSIGNEDLTR or - self.kind == NPY_GENBOOLLTR) + return (self.kind == NPY.SIGNEDLTR or self.kind == NPY.UNSIGNEDLTR or + self.kind == NPY.GENBOOLLTR) def is_signed(self): - return self.kind == NPY_SIGNEDLTR + return self.kind == NPY.SIGNEDLTR def is_complex_type(self): - return self.kind == NPY_COMPLEXLTR + return self.kind == NPY.COMPLEXLTR def is_float_type(self): - return self.kind == NPY_FLOATINGLTR or self.kind == NPY_COMPLEXLTR + return self.kind == NPY.FLOATINGLTR or self.kind == NPY.COMPLEXLTR def is_bool_type(self): - return self.kind == NPY_GENBOOLLTR + return self.kind == NPY.GENBOOLLTR def is_record_type(self): return self.fields is not None def is_str_type(self): - return self.num == NPY_STRING + return self.num == NPY.STRING def is_str_or_unicode(self): - return (self.num == NPY_STRING or self.num == NPY_UNICODE) + return (self.num == NPY.STRING or self.num == NPY.UNICODE) def is_flexible_type(self): return (self.is_str_or_unicode() or self.is_record_type()) def is_native(self): - return self.byteorder in (NPY_NATIVE, NPY_NATBYTE) + return self.byteorder in (NPY.NATIVE, NPY.NATBYTE) def get_size(self): return self.size * self.itemtype.get_element_size() @@ -126,7 +125,7 @@ return self.name def get_float_dtype(self, space): - assert self.kind == NPY_COMPLEXLTR + assert self.kind == NPY.COMPLEXLTR assert self.float_type is not None return get_dtype_cache(space).dtypes_by_name[self.byteorder + self.float_type] @@ -150,15 +149,15 @@ def descr_get_str(self, space): size = self.get_size() basic = self.kind - if basic == NPY_UNICODELTR: + if basic == NPY.UNICODELTR: size >>= 2 - endian = NPY_NATBYTE + endian = NPY.NATBYTE elif size // (self.size or 1) <= 1: - endian = NPY_IGNORE + endian = NPY.IGNORE else: endian = self.byteorder - if endian == NPY_NATIVE: - endian = NPY_NATBYTE + if endian == NPY.NATIVE: + endian = NPY.NATBYTE return space.wrap("%s%s%s" % (endian, basic, size)) def descr_get_descr(self, space): @@ -305,7 +304,7 @@ names = self.descr_get_names(space) values = self.descr_get_fields(space) if self.fields: - endian = NPY_IGNORE + endian = NPY.IGNORE #TODO: Implement this when subarrays are implemented subdescr = space.w_None size = 0 @@ -318,8 +317,8 @@ alignment = space.wrap(1) else: endian = self.byteorder - if endian == NPY_NATIVE: - endian = NPY_NATBYTE + if endian == NPY.NATIVE: + endian = NPY.NATBYTE subdescr = space.w_None w_size = space.wrap(-1) alignment = space.wrap(-1) @@ -333,8 +332,8 @@ raise OperationError(space.w_NotImplementedError, space.wrap("Pickling protocol version not supported")) endian = space.str_w(space.getitem(w_data, space.wrap(1))) - if endian == NPY_NATBYTE: - endian = NPY_NATIVE + if endian == NPY.NATBYTE: + endian = NPY.NATIVE self.byteorder = endian fieldnames = space.getitem(w_data, space.wrap(3)) @@ -344,15 +343,15 @@ self.descr_set_fields(space, fields) @unwrap_spec(new_order=str) - def descr_newbyteorder(self, space, new_order=NPY_SWAP): + def descr_newbyteorder(self, space, new_order=NPY.SWAP): newendian = byteorder_converter(space, new_order) endian = self.byteorder - if endian != NPY_IGNORE: - if newendian == NPY_SWAP: - endian = NPY_OPPBYTE if self.is_native() else NPY_NATBYTE - elif newendian != NPY_IGNORE: + if endian != NPY.IGNORE: + if newendian == NPY.SWAP: + endian = NPY.OPPBYTE if self.is_native() else NPY.NATBYTE + elif newendian != NPY.IGNORE: endian = newendian - itemtype = self.itemtype.__class__(endian in (NPY_NATIVE, NPY_NATBYTE)) + itemtype = self.itemtype.__class__(endian in (NPY.NATIVE, NPY.NATBYTE)) return W_Dtype(itemtype, self.num, self.kind, self.name, self.char, self.w_box_type, endian, size=self.size) @@ -387,9 +386,9 @@ offset += subdtype.get_size() fieldnames.append(fldname) itemtype = types.RecordType() - return W_Dtype(itemtype, NPY_VOID, NPY_VOIDLTR, + return W_Dtype(itemtype, NPY.VOID, NPY.VOIDLTR, "void" + str(8 * offset * itemtype.get_element_size()), - NPY_VOIDLTR, space.gettypefor(interp_boxes.W_VoidBox), + NPY.VOIDLTR, space.gettypefor(interp_boxes.W_VoidBox), fields=fields, fieldnames=fieldnames, size=offset) @@ -429,9 +428,9 @@ size *= dim if size == 1: return subdtype - return W_Dtype(types.VoidType(), NPY_VOID, NPY_VOIDLTR, + return W_Dtype(types.VoidType(), NPY.VOID, NPY.VOIDLTR, "void" + str(8 * subdtype.get_size() * size), - NPY_VOIDLTR, space.gettypefor(interp_boxes.W_VoidBox), + NPY.VOIDLTR, space.gettypefor(interp_boxes.W_VoidBox), shape=shape, subdtype=subdtype, size=subdtype.get_size() * size) @@ -523,24 +522,24 @@ size = int(name[1:]) except ValueError: raise OperationError(space.w_TypeError, space.wrap("data type not understood")) - if char == NPY_CHARLTR: - char = NPY_STRINGLTR + if char == NPY.CHARLTR: + char = NPY.STRINGLTR size = 1 - if char == NPY_STRINGLTR: + if char == NPY.STRINGLTR: itemtype = types.StringType() basename = 'string' - num = NPY_STRING + num = NPY.STRING w_box_type = space.gettypefor(interp_boxes.W_StringBox) - elif char == NPY_VOIDLTR: + elif char == NPY.VOIDLTR: itemtype = types.VoidType() basename = 'void' - num = NPY_VOID + num = NPY.VOID w_box_type = space.gettypefor(interp_boxes.W_VoidBox) - elif char == NPY_UNICODELTR: + elif char == NPY.UNICODELTR: itemtype = types.UnicodeType() basename = 'unicode' - num = NPY_UNICODE + num = NPY.UNICODE w_box_type = space.gettypefor(interp_boxes.W_UnicodeBox) else: assert False @@ -555,10 +554,10 @@ return W_Dtype( itemtype, size=size, - num=NPY_STRING, - kind=NPY_STRINGLTR, + num=NPY.STRING, + kind=NPY.STRINGLTR, name='string' + str(8 * size * itemtype.get_element_size()), - char=NPY_STRINGLTR, + char=NPY.STRINGLTR, w_box_type = space.gettypefor(interp_boxes.W_StringBox), ) @@ -568,10 +567,10 @@ return W_Dtype( itemtype, size=size, - num=NPY_UNICODE, - kind=NPY_UNICODELTR, + num=NPY.UNICODE, + kind=NPY.UNICODELTR, name='unicode' + str(8 * size * itemtype.get_element_size()), - char=NPY_UNICODELTR, + char=NPY.UNICODELTR, w_box_type = space.gettypefor(interp_boxes.W_UnicodeBox), ) @@ -580,72 +579,72 @@ def __init__(self, space): self.w_booldtype = W_Dtype( types.Bool(), - num=NPY_BOOL, - kind=NPY_GENBOOLLTR, + num=NPY.BOOL, + kind=NPY.GENBOOLLTR, name="bool", - char=NPY_BOOLLTR, + char=NPY.BOOLLTR, w_box_type=space.gettypefor(interp_boxes.W_BoolBox), alternate_constructors=[space.w_bool], aliases=['bool8'], ) self.w_int8dtype = W_Dtype( types.Int8(), - num=NPY_BYTE, - kind=NPY_SIGNEDLTR, + num=NPY.BYTE, + kind=NPY.SIGNEDLTR, name="int8", - char=NPY_BYTELTR, + char=NPY.BYTELTR, w_box_type=space.gettypefor(interp_boxes.W_Int8Box), aliases=['byte'], ) self.w_uint8dtype = W_Dtype( types.UInt8(), - num=NPY_UBYTE, - kind=NPY_UNSIGNEDLTR, + num=NPY.UBYTE, + kind=NPY.UNSIGNEDLTR, name="uint8", - char=NPY_UBYTELTR, + char=NPY.UBYTELTR, w_box_type=space.gettypefor(interp_boxes.W_UInt8Box), aliases=['ubyte'], ) self.w_int16dtype = W_Dtype( types.Int16(), - num=NPY_SHORT, - kind=NPY_SIGNEDLTR, + num=NPY.SHORT, + kind=NPY.SIGNEDLTR, name="int16", - char=NPY_SHORTLTR, + char=NPY.SHORTLTR, w_box_type=space.gettypefor(interp_boxes.W_Int16Box), aliases=['short'], ) self.w_uint16dtype = W_Dtype( types.UInt16(), - num=NPY_USHORT, - kind=NPY_UNSIGNEDLTR, + num=NPY.USHORT, + kind=NPY.UNSIGNEDLTR, name="uint16", - char=NPY_USHORTLTR, + char=NPY.USHORTLTR, w_box_type=space.gettypefor(interp_boxes.W_UInt16Box), aliases=['ushort'], ) self.w_int32dtype = W_Dtype( types.Int32(), - num=NPY_INT, - kind=NPY_SIGNEDLTR, + num=NPY.INT, + kind=NPY.SIGNEDLTR, name="int32", - char=NPY_INTLTR, + char=NPY.INTLTR, w_box_type=space.gettypefor(interp_boxes.W_Int32Box), ) self.w_uint32dtype = W_Dtype( types.UInt32(), - num=NPY_UINT, - kind=NPY_UNSIGNEDLTR, + num=NPY.UINT, + kind=NPY.UNSIGNEDLTR, name="uint32", - char=NPY_UINTLTR, + char=NPY.UINTLTR, w_box_type=space.gettypefor(interp_boxes.W_UInt32Box), ) self.w_longdtype = W_Dtype( types.Long(), - num=NPY_LONG, - kind=NPY_SIGNEDLTR, + num=NPY.LONG, + kind=NPY.SIGNEDLTR, name="int%d" % LONG_BIT, - char=NPY_LONGLTR, + char=NPY.LONGLTR, w_box_type=space.gettypefor(interp_boxes.W_LongBox), alternate_constructors=[space.w_int, space.gettypefor(interp_boxes.W_IntegerBox), @@ -655,10 +654,10 @@ ) self.w_ulongdtype = W_Dtype( types.ULong(), - num=NPY_ULONG, - kind=NPY_UNSIGNEDLTR, + num=NPY.ULONG, + kind=NPY.UNSIGNEDLTR, name="uint%d" % LONG_BIT, - char=NPY_ULONGLTR, + char=NPY.ULONGLTR, w_box_type=space.gettypefor(interp_boxes.W_ULongBox), alternate_constructors=[space.gettypefor(interp_boxes.W_UnsignedIntegerBox), ], @@ -666,38 +665,38 @@ ) self.w_int64dtype = W_Dtype( types.Int64(), - num=NPY_LONGLONG, - kind=NPY_SIGNEDLTR, + num=NPY.LONGLONG, + kind=NPY.SIGNEDLTR, name="int64", - char=NPY_LONGLONGLTR, + char=NPY.LONGLONGLTR, w_box_type=space.gettypefor(interp_boxes.W_Int64Box), alternate_constructors=[space.w_long], aliases=['longlong'], ) self.w_uint64dtype = W_Dtype( types.UInt64(), - num=NPY_ULONGLONG, - kind=NPY_UNSIGNEDLTR, + num=NPY.ULONGLONG, + kind=NPY.UNSIGNEDLTR, name="uint64", - char=NPY_ULONGLONGLTR, + char=NPY.ULONGLONGLTR, w_box_type=space.gettypefor(interp_boxes.W_UInt64Box), aliases=['ulonglong'], ) self.w_float32dtype = W_Dtype( types.Float32(), - num=NPY_FLOAT, - kind=NPY_FLOATINGLTR, + num=NPY.FLOAT, + kind=NPY.FLOATINGLTR, name="float32", - char=NPY_FLOATLTR, + char=NPY.FLOATLTR, w_box_type=space.gettypefor(interp_boxes.W_Float32Box), aliases=['single'] ) self.w_float64dtype = W_Dtype( types.Float64(), - num=NPY_DOUBLE, - kind=NPY_FLOATINGLTR, + num=NPY.DOUBLE, + kind=NPY.FLOATINGLTR, name="float64", - char=NPY_DOUBLELTR, + char=NPY.DOUBLELTR, w_box_type = space.gettypefor(interp_boxes.W_Float64Box), alternate_constructors=[space.w_float, space.gettypefor(interp_boxes.W_NumberBox), @@ -707,52 +706,52 @@ ) self.w_floatlongdtype = W_Dtype( types.FloatLong(), - num=NPY_LONGDOUBLE, - kind=NPY_FLOATINGLTR, + num=NPY.LONGDOUBLE, + kind=NPY.FLOATINGLTR, name="float%d" % (interp_boxes.long_double_size * 8), - char=NPY_LONGDOUBLELTR, + char=NPY.LONGDOUBLELTR, w_box_type=space.gettypefor(interp_boxes.W_FloatLongBox), aliases=["longdouble", "longfloat"], ) self.w_complex64dtype = W_Dtype( types.Complex64(), - num=NPY_CFLOAT, - kind=NPY_COMPLEXLTR, + num=NPY.CFLOAT, + kind=NPY.COMPLEXLTR, name="complex64", - char=NPY_CFLOATLTR, + char=NPY.CFLOATLTR, w_box_type = space.gettypefor(interp_boxes.W_Complex64Box), aliases=['csingle'], - float_type=NPY_FLOATLTR, + float_type=NPY.FLOATLTR, ) self.w_complex128dtype = W_Dtype( types.Complex128(), - num=NPY_CDOUBLE, - kind=NPY_COMPLEXLTR, + num=NPY.CDOUBLE, + kind=NPY.COMPLEXLTR, name="complex128", - char=NPY_CDOUBLELTR, + char=NPY.CDOUBLELTR, w_box_type = space.gettypefor(interp_boxes.W_Complex128Box), alternate_constructors=[space.w_complex, space.gettypefor(interp_boxes.W_ComplexFloatingBox)], aliases=["complex", 'cfloat', 'cdouble'], - float_type=NPY_DOUBLELTR, + float_type=NPY.DOUBLELTR, ) self.w_complexlongdtype = W_Dtype( types.ComplexLong(), - num=NPY_CLONGDOUBLE, - kind=NPY_COMPLEXLTR, + num=NPY.CLONGDOUBLE, + kind=NPY.COMPLEXLTR, name="complex%d" % (interp_boxes.long_double_size * 16), - char=NPY_CLONGDOUBLELTR, + char=NPY.CLONGDOUBLELTR, w_box_type = space.gettypefor(interp_boxes.W_ComplexLongBox), aliases=["clongdouble", "clongfloat"], - float_type=NPY_LONGDOUBLELTR, + float_type=NPY.LONGDOUBLELTR, ) self.w_stringdtype = W_Dtype( types.StringType(), size=0, - num=NPY_STRING, - kind=NPY_STRINGLTR, + num=NPY.STRING, + kind=NPY.STRINGLTR, name='string', - char=NPY_STRINGLTR, + char=NPY.STRINGLTR, w_box_type = space.gettypefor(interp_boxes.W_StringBox), alternate_constructors=[space.w_str, space.gettypefor(interp_boxes.W_CharacterBox)], @@ -761,20 +760,20 @@ self.w_unicodedtype = W_Dtype( types.UnicodeType(), size=0, - num=NPY_UNICODE, - kind=NPY_UNICODELTR, + num=NPY.UNICODE, + kind=NPY.UNICODELTR, name='unicode', - char=NPY_UNICODELTR, + char=NPY.UNICODELTR, w_box_type = space.gettypefor(interp_boxes.W_UnicodeBox), alternate_constructors=[space.w_unicode], ) self.w_voiddtype = W_Dtype( types.VoidType(), size=0, - num=NPY_VOID, - kind=NPY_VOIDLTR, + num=NPY.VOID, + kind=NPY.VOIDLTR, name='void', - char=NPY_VOIDLTR, + char=NPY.VOIDLTR, w_box_type = space.gettypefor(interp_boxes.W_VoidBox), #alternate_constructors=[space.w_buffer], # XXX no buffer in space @@ -783,26 +782,26 @@ ) self.w_float16dtype = W_Dtype( types.Float16(), - num=NPY_HALF, - kind=NPY_FLOATINGLTR, + num=NPY.HALF, + kind=NPY.FLOATINGLTR, name="float16", - char=NPY_HALFLTR, + char=NPY.HALFLTR, w_box_type=space.gettypefor(interp_boxes.W_Float16Box), ) self.w_intpdtype = W_Dtype( types.Long(), - num=NPY_LONG, - kind=NPY_SIGNEDLTR, + num=NPY.LONG, + kind=NPY.SIGNEDLTR, name='intp', - char=NPY_INTPLTR, + char=NPY.INTPLTR, w_box_type = space.gettypefor(interp_boxes.W_LongBox), ) self.w_uintpdtype = W_Dtype( types.ULong(), - num=NPY_ULONG, - kind=NPY_UNSIGNEDLTR, + num=NPY.ULONG, + kind=NPY.UNSIGNEDLTR, name='uintp', - char=NPY_UINTPLTR, + char=NPY.UINTPLTR, w_box_type = space.gettypefor(interp_boxes.W_ULongBox), ) float_dtypes = [self.w_float16dtype, self.w_float32dtype, @@ -834,14 +833,14 @@ for can_name in [dtype.kind + str(dtype.get_size()), dtype.char]: self.dtypes_by_name[can_name] = dtype - self.dtypes_by_name[NPY_NATBYTE + can_name] = dtype - self.dtypes_by_name[NPY_NATIVE + can_name] = dtype - self.dtypes_by_name[NPY_IGNORE + can_name] = dtype - new_name = NPY_OPPBYTE + can_name + self.dtypes_by_name[NPY.NATBYTE + can_name] = dtype + self.dtypes_by_name[NPY.NATIVE + can_name] = dtype + self.dtypes_by_name[NPY.IGNORE + can_name] = dtype + new_name = NPY.OPPBYTE + can_name itemtype = type(dtype.itemtype)(False) self.dtypes_by_name[new_name] = W_Dtype( itemtype, dtype.num, dtype.kind, new_name, dtype.char, - dtype.w_box_type, byteorder=NPY_OPPBYTE, + dtype.w_box_type, byteorder=NPY.OPPBYTE, float_type=dtype.float_type) for alias in dtype.aliases: self.dtypes_by_name[alias] = dtype @@ -898,7 +897,7 @@ space.wrap(itembits), space.wrap(dtype.itemtype.get_element_size())] if dtype.is_int_type(): - if dtype.kind == NPY_GENBOOLLTR: + if dtype.kind == NPY.GENBOOLLTR: w_maxobj = space.wrap(1) w_minobj = space.wrap(0) elif dtype.is_signed(): 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 @@ -23,7 +23,7 @@ from pypy.module.micronumpy.arrayimpl.base import BaseArrayImplementation from pypy.module.micronumpy.conversion_utils import order_converter, multi_axis_converter from pypy.module.micronumpy import support -from pypy.module.micronumpy.constants import * +from pypy.module.micronumpy import constants as NPY def _find_shape(space, w_size, dtype): if space.is_none(w_size): @@ -110,8 +110,8 @@ self.fill(space, self.get_dtype().coerce(space, w_value)) def descr_tostring(self, space, w_order=None): - order = order_converter(space, w_order, NPY_CORDER) - if order == NPY_FORTRANORDER: + order = order_converter(space, w_order, NPY.CORDER) + if order == NPY.FORTRANORDER: raise OperationError(space.w_NotImplementedError, space.wrap( "unsupported value for order")) return space.wrap(loop.tostring(space, self)) @@ -320,8 +320,8 @@ return self.implementation.get_scalar_value() def descr_copy(self, space, w_order=None): - order = order_converter(space, w_order, NPY_KEEPORDER) - if order == NPY_FORTRANORDER: + order = order_converter(space, w_order, NPY.KEEPORDER) + if order == NPY.FORTRANORDER: raise OperationError(space.w_NotImplementedError, space.wrap( "unsupported value for order")) copy = self.implementation.copy(space) @@ -375,7 +375,7 @@ numpy.reshape : equivalent function """ args_w, kw_w = __args__.unpack() - order = NPY_CORDER + order = NPY.CORDER if kw_w: if "order" in kw_w: order = order_converter(space, kw_w["order"], order) @@ -383,10 +383,10 @@ if kw_w: raise OperationError(space.w_TypeError, space.wrap( "reshape() got unexpected keyword argument(s)")) - if order == NPY_KEEPORDER: + if order == NPY.KEEPORDER: raise OperationError(space.w_ValueError, space.wrap( "order 'K' is not permitted for reshaping")) - if order != NPY_CORDER and order != NPY_ANYORDER: + if order != NPY.CORDER and order != NPY.ANYORDER: raise OperationError(space.w_NotImplementedError, space.wrap( "unsupported value for order")) if len(args_w) == 1: @@ -561,7 +561,7 @@ # by converting nonnative byte order. if self.is_scalar(): return space.wrap(0) - dtype = self.get_dtype().descr_newbyteorder(space, NPY_NATIVE) + dtype = self.get_dtype().descr_newbyteorder(space, NPY.NATIVE) contig = self.implementation.astype(space, dtype) return contig.argsort(space, w_axis) @@ -662,7 +662,7 @@ "getfield not implemented yet")) @unwrap_spec(new_order=str) - def descr_newbyteorder(self, space, new_order=NPY_SWAP): + def descr_newbyteorder(self, space, new_order=NPY.SWAP): return self.descr_view(space, self.get_dtype().descr_newbyteorder(space, new_order)) @@ -1138,7 +1138,7 @@ "__setstate__ called with len(args[1])==%d, not 5 or 4" % lens)) shape = space.getitem(w_state, space.wrap(base_index)) dtype = space.getitem(w_state, space.wrap(base_index+1)) - isfortran = space.getitem(w_state, space.wrap(base_index+2)) + #isfortran = space.getitem(w_state, space.wrap(base_index+2)) storage = space.getitem(w_state, space.wrap(base_index+3)) if not isinstance(dtype, interp_dtype.W_Dtype): raise OperationError(space.w_ValueError, space.wrap( @@ -1192,8 +1192,8 @@ w_base=w_buffer, writable=buf.is_writable()) - order = order_converter(space, w_order, NPY_CORDER) - if order == NPY_CORDER: + order = order_converter(space, w_order, NPY.CORDER) + if order == NPY.CORDER: order = 'C' else: order = 'F' 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 @@ -9,7 +9,7 @@ from pypy.module.micronumpy.interp_support import unwrap_axis_arg from pypy.module.micronumpy.strides import shape_agreement from pypy.module.micronumpy.base import convert_to_array, W_NDimArray -from pypy.module.micronumpy.constants import * +from pypy.module.micronumpy import constants as NPY def done_if_true(dtype, val): return dtype.itemtype.bool(val) @@ -462,24 +462,24 @@ if dt1.num > dt2.num: dt1, dt2 = dt2, dt1 # Some operations promote op(bool, bool) to return int8, rather than bool - if promote_bools and (dt1.kind == dt2.kind == NPY_GENBOOLLTR): + if promote_bools and (dt1.kind == dt2.kind == NPY.GENBOOLLTR): return interp_dtype.get_dtype_cache(space).w_int8dtype # Everything numeric promotes to complex if dt2.is_complex_type() or dt1.is_complex_type(): - if dt2.num == NPY_HALF: + if dt2.num == NPY.HALF: dt1, dt2 = dt2, dt1 - if dt2.num == NPY_CFLOAT: - if dt1.num == NPY_DOUBLE: + if dt2.num == NPY.CFLOAT: + if dt1.num == NPY.DOUBLE: return interp_dtype.get_dtype_cache(space).w_complex128dtype - elif dt1.num == NPY_LONGDOUBLE: + elif dt1.num == NPY.LONGDOUBLE: return interp_dtype.get_dtype_cache(space).w_complexlongdtype return interp_dtype.get_dtype_cache(space).w_complex64dtype - elif dt2.num == NPY_CDOUBLE: - if dt1.num == NPY_LONGDOUBLE: + elif dt2.num == NPY.CDOUBLE: + if dt1.num == NPY.LONGDOUBLE: return interp_dtype.get_dtype_cache(space).w_complexlongdtype return interp_dtype.get_dtype_cache(space).w_complex128dtype - elif dt2.num == NPY_CLONGDOUBLE: + elif dt2.num == NPY.CLONGDOUBLE: return interp_dtype.get_dtype_cache(space).w_complexlongdtype else: raise OperationError(space.w_TypeError, space.wrap("Unsupported types")) @@ -488,30 +488,30 @@ return find_unaryop_result_dtype(space, dt2, promote_to_float=True) # If they're the same kind, choose the greater one. if dt1.kind == dt2.kind and not dt2.is_flexible_type(): - if dt2.num == NPY_HALF: + if dt2.num == NPY.HALF: return dt1 return dt2 # Everything promotes to float, and bool promotes to everything. - if dt2.kind == NPY_FLOATINGLTR or dt1.kind == NPY_GENBOOLLTR: - if dt2.num == NPY_HALF and dt1.itemtype.get_element_size() == 2: + if dt2.kind == NPY.FLOATINGLTR or dt1.kind == NPY.GENBOOLLTR: + if dt2.num == NPY.HALF and dt1.itemtype.get_element_size() == 2: return interp_dtype.get_dtype_cache(space).w_float32dtype - if dt2.num == NPY_HALF and dt1.itemtype.get_element_size() >= 4: + if dt2.num == NPY.HALF and dt1.itemtype.get_element_size() >= 4: return interp_dtype.get_dtype_cache(space).w_float64dtype - if dt2.num == NPY_FLOAT and dt1.itemtype.get_element_size() >= 4: + if dt2.num == NPY.FLOAT and dt1.itemtype.get_element_size() >= 4: return interp_dtype.get_dtype_cache(space).w_float64dtype return dt2 # for now this means mixing signed and unsigned - if dt2.kind == NPY_SIGNEDLTR: + if dt2.kind == NPY.SIGNEDLTR: # if dt2 has a greater number of bytes, then just go with it if dt1.itemtype.get_element_size() < dt2.itemtype.get_element_size(): return dt2 # we need to promote both dtypes dtypenum = dt2.num + 2 - elif dt2.num == NPY_ULONGLONG or (LONG_BIT == 64 and dt2.num == NPY_ULONG): + elif dt2.num == NPY.ULONGLONG or (LONG_BIT == 64 and dt2.num == NPY.ULONG): # UInt64 + signed = Float64 - dtypenum = NPY_DOUBLE + dtypenum = NPY.DOUBLE elif dt2.is_flexible_type(): # For those operations that get here (concatenate, stack), # flexible types take precedence over numeric type @@ -528,7 +528,7 @@ newdtype = interp_dtype.get_dtype_cache(space).dtypes_by_num[dtypenum] if (newdtype.itemtype.get_element_size() > dt2.itemtype.get_element_size() or - newdtype.kind == NPY_FLOATINGLTR): + newdtype.kind == NPY.FLOATINGLTR): return newdtype else: # we only promoted to long on 32-bit or to longlong on 64-bit @@ -540,24 +540,24 @@ def find_unaryop_result_dtype(space, dt, promote_to_float=False, promote_bools=False, promote_to_largest=False): if promote_to_largest: - if dt.kind == NPY_GENBOOLLTR or dt.kind == NPY_SIGNEDLTR: + if dt.kind == NPY.GENBOOLLTR or dt.kind == NPY.SIGNEDLTR: if dt.get_size() * 8 < LONG_BIT: return interp_dtype.get_dtype_cache(space).w_longdtype - elif dt.kind == NPY_UNSIGNEDLTR: + elif dt.kind == NPY.UNSIGNEDLTR: if dt.get_size() * 8 < LONG_BIT: return interp_dtype.get_dtype_cache(space).w_ulongdtype else: - assert dt.kind == NPY_FLOATINGLTR or dt.kind == NPY_COMPLEXLTR + assert dt.kind == NPY.FLOATINGLTR or dt.kind == NPY.COMPLEXLTR return dt - if promote_bools and (dt.kind == NPY_GENBOOLLTR): + if promote_bools and (dt.kind == NPY.GENBOOLLTR): return interp_dtype.get_dtype_cache(space).w_int8dtype if promote_to_float: - if dt.kind == NPY_FLOATINGLTR or dt.kind == NPY_COMPLEXLTR: + if dt.kind == NPY.FLOATINGLTR or dt.kind == NPY.COMPLEXLTR: return dt - if dt.num >= NPY_INT: + if dt.num >= NPY.INT: return interp_dtype.get_dtype_cache(space).w_float64dtype for bytes, dtype in interp_dtype.get_dtype_cache(space).float_dtypes_by_num_bytes: - if (dtype.kind == NPY_FLOATINGLTR and + if (dtype.kind == NPY.FLOATINGLTR and dtype.itemtype.get_element_size() > dt.itemtype.get_element_size()): return dtype return dt @@ -594,7 +594,7 @@ if current_guess is None: return interp_dtype.variable_dtype(space, 'S%d' % space.len_w(w_obj)) - elif current_guess.num == NPY_STRING: + elif current_guess.num == NPY.STRING: if current_guess.get_size() < space.len_w(w_obj): return interp_dtype.variable_dtype(space, 'S%d' % space.len_w(w_obj)) diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py --- a/pypy/module/micronumpy/loop.py +++ b/pypy/module/micronumpy/loop.py @@ -11,7 +11,7 @@ from pypy.module.micronumpy.base import W_NDimArray from pypy.module.micronumpy.iter import PureShapeIterator from pypy.module.micronumpy.support import index_w -from pypy.module.micronumpy.constants import * +from pypy.module.micronumpy import constants as NPY call2_driver = jit.JitDriver(name='numpy_call2', greens = ['shapelen', 'func', 'calc_dtype', @@ -597,13 +597,13 @@ mode=mode) index = index_w(space, arr_iter.getitem()) if index < 0 or index >= len(iterators): - if mode == NPY_RAISE: + if mode == NPY.RAISE: raise OperationError(space.w_ValueError, space.wrap( "invalid entry in choice array")) - elif mode == NPY_WRAP: + elif mode == NPY.WRAP: index = index % (len(iterators)) else: - assert mode == NPY_CLIP + assert mode == NPY.CLIP if index < 0: index = 0 else: diff --git a/pypy/module/micronumpy/test/test_base.py b/pypy/module/micronumpy/test/test_base.py --- a/pypy/module/micronumpy/test/test_base.py +++ b/pypy/module/micronumpy/test/test_base.py @@ -1,4 +1,4 @@ -from pypy.module.micronumpy.interp_dtype import NPY_NATBYTE, NPY_OPPBYTE +from pypy.module.micronumpy import constants as NPY from pypy.conftest import option class BaseNumpyAppTest(object): @@ -23,5 +23,5 @@ import sys sys.modules['numpypy'] = numpy """) - cls.w_non_native_prefix = cls.space.wrap(NPY_OPPBYTE) - cls.w_native_prefix = cls.space.wrap(NPY_NATBYTE) + cls.w_non_native_prefix = cls.space.wrap(NPY.OPPBYTE) + cls.w_native_prefix = cls.space.wrap(NPY.NATBYTE) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit