[pypy-commit] pypy default: merge numpy-refactor

bdkearns noreply at buildbot.pypy.org
Thu Feb 27 07:11:27 CET 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r69496:05dd17c81105
Date: 2014-02-27 01:10 -0500
http://bitbucket.org/pypy/pypy/changeset/05dd17c81105/

Log:	merge numpy-refactor

diff --git a/pypy/module/cpyext/ndarrayobject.py b/pypy/module/cpyext/ndarrayobject.py
--- a/pypy/module/cpyext/ndarrayobject.py
+++ b/pypy/module/cpyext/ndarrayobject.py
@@ -7,8 +7,9 @@
 from rpython.rtyper.lltypesystem import rffi, lltype
 from pypy.module.cpyext.api import cpython_api, Py_ssize_t, CANNOT_FAIL
 from pypy.module.cpyext.api import PyObject
-from pypy.module.micronumpy.interp_numarray import W_NDimArray, array
-from pypy.module.micronumpy.interp_dtype import get_dtype_cache, W_Dtype
+from pypy.module.micronumpy.ndarray import W_NDimArray
+from pypy.module.micronumpy.ctors import array
+from pypy.module.micronumpy.descriptor import get_dtype_cache, W_Dtype
 from pypy.module.micronumpy.concrete import ConcreteArray
 from rpython.rlib.rawstorage import RAW_STORAGE_PTR
 
diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py b/pypy/module/cpyext/test/test_ndarrayobject.py
--- a/pypy/module/cpyext/test/test_ndarrayobject.py
+++ b/pypy/module/cpyext/test/test_ndarrayobject.py
@@ -2,8 +2,8 @@
 from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 from rpython.rtyper.lltypesystem import rffi, lltype
 
-from pypy.module.micronumpy.interp_numarray import W_NDimArray
-from pypy.module.micronumpy.interp_dtype import get_dtype_cache
+from pypy.module.micronumpy.ndarray import W_NDimArray
+from pypy.module.micronumpy.descriptor import get_dtype_cache
 
 def scalar(space):
     dtype = get_dtype_cache(space).w_float64dtype
diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -4,24 +4,24 @@
 class MultiArrayModule(MixedModule):
     appleveldefs = {'arange': 'app_numpy.arange'}
     interpleveldefs = {
-        'ndarray': 'interp_numarray.W_NDimArray',
-        'dtype': 'interp_dtype.W_Dtype',
+        'ndarray': 'ndarray.W_NDimArray',
+        'dtype': 'descriptor.W_Dtype',
 
-        'array': 'interp_numarray.array',
-        'zeros': 'interp_numarray.zeros',
-        'empty': 'interp_numarray.zeros',
-        'empty_like': 'interp_numarray.empty_like',
-        '_reconstruct' : 'interp_numarray._reconstruct',
-        'scalar' : 'interp_numarray.build_scalar',
-        'dot': 'interp_arrayops.dot',
-        'fromstring': 'interp_support.fromstring',
-        'flatiter': 'interp_flatiter.W_FlatIterator',
-        'concatenate': 'interp_arrayops.concatenate',
-        'where': 'interp_arrayops.where',
-        'count_nonzero': 'interp_arrayops.count_nonzero',
+        'array': 'ctors.array',
+        'zeros': 'ctors.zeros',
+        'empty': 'ctors.zeros',
+        'empty_like': 'ctors.empty_like',
+        '_reconstruct' : 'ndarray._reconstruct',
+        'scalar' : 'ctors.build_scalar',
+        'dot': 'arrayops.dot',
+        'fromstring': 'ctors.fromstring',
+        'flatiter': 'flatiter.W_FlatIterator',
+        'concatenate': 'arrayops.concatenate',
+        'where': 'arrayops.where',
+        'count_nonzero': 'arrayops.count_nonzero',
 
         'set_string_function': 'appbridge.set_string_function',
-        'typeinfo': 'interp_dtype.get_dtype_cache(space).w_typeinfo',
+        'typeinfo': 'descriptor.get_dtype_cache(space).w_typeinfo',
     }
 
 
@@ -107,7 +107,7 @@
         ('real', 'real'),
         ('imag', 'imag'),
     ]:
-        interpleveldefs[exposed] = "interp_ufuncs.get(space).%s" % impl
+        interpleveldefs[exposed] = "ufuncs.get(space).%s" % impl
 
 
 class Module(MixedModule):
diff --git a/pypy/module/micronumpy/interp_arrayops.py b/pypy/module/micronumpy/arrayops.py
rename from pypy/module/micronumpy/interp_arrayops.py
rename to pypy/module/micronumpy/arrayops.py
--- a/pypy/module/micronumpy/interp_arrayops.py
+++ b/pypy/module/micronumpy/arrayops.py
@@ -1,10 +1,10 @@
 from pypy.module.micronumpy.base import convert_to_array, W_NDimArray
-from pypy.module.micronumpy import loop, interp_dtype, interp_ufuncs
+from pypy.module.micronumpy import loop, descriptor, ufuncs
 from pypy.module.micronumpy.strides import Chunk, Chunks, shape_agreement, \
     shape_agreement_multiple
 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.converters import clipmode_converter
 from pypy.module.micronumpy import support
 from pypy.module.micronumpy import constants as NPY
 
@@ -84,7 +84,7 @@
         if arr.get_dtype().itemtype.bool(arr.get_scalar_value()):
             return x
         return y
-    dtype = interp_ufuncs.find_binop_result_dtype(space, x.get_dtype(),
+    dtype = ufuncs.find_binop_result_dtype(space, x.get_dtype(),
                                                   y.get_dtype())
     shape = shape_agreement(space, arr.get_shape(), x)
     shape = shape_agreement(space, shape, y)
@@ -147,7 +147,7 @@
         elif dtype.is_record() or a_dt.is_record():
             raise OperationError(space.w_TypeError,
                         space.wrap("invalid type promotion"))
-        dtype = interp_ufuncs.find_binop_result_dtype(space, dtype,
+        dtype = ufuncs.find_binop_result_dtype(space, dtype,
                                                       arr.get_dtype())
     # concatenate does not handle ndarray subtypes, it always returns a ndarray
     res = W_NDimArray.from_shape(space, shape, dtype, 'C')
@@ -202,7 +202,7 @@
         raise OperationError(space.w_TypeError, space.wrap(
             "return arrays must be of ArrayType"))
     shape = shape_agreement_multiple(space, choices + [w_out])
-    out = interp_dtype.dtype_agreement(space, choices, shape, w_out)
+    out = descriptor.dtype_agreement(space, choices, shape, w_out)
     dtype = out.get_dtype()
     mode = clipmode_converter(space, w_mode)
     loop.choose(space, arr, choices, shape, dtype, out, mode)
diff --git a/pypy/module/micronumpy/base.py b/pypy/module/micronumpy/base.py
--- a/pypy/module/micronumpy/base.py
+++ b/pypy/module/micronumpy/base.py
@@ -86,7 +86,7 @@
 
 
 def convert_to_array(space, w_obj):
-    from pypy.module.micronumpy.interp_numarray import array
+    from pypy.module.micronumpy.ctors import array
     if isinstance(w_obj, W_NDimArray):
         return w_obj
     return array(space, w_obj)
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/boxes.py
rename from pypy/module/micronumpy/interp_boxes.py
rename to pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -12,7 +12,7 @@
 from rpython.tool.sourcetools import func_with_new_name
 from pypy.module.micronumpy.concrete import VoidBoxStorage
 from pypy.module.micronumpy.base import W_NDimArray
-from pypy.module.micronumpy.interp_flagsobj import W_FlagsObject
+from pypy.module.micronumpy.flagsobj import W_FlagsObject
 from pypy.interpreter.mixedmodule import MixedModule
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rlib.rstring import StringBuilder
@@ -36,11 +36,11 @@
 def new_dtype_getter(num):
     @specialize.memo()
     def _get_dtype(space):
-        from pypy.module.micronumpy.interp_dtype import get_dtype_cache
+        from pypy.module.micronumpy.descriptor import get_dtype_cache
         return get_dtype_cache(space).dtypes_by_num[num]
 
     def descr__new__(space, w_subtype, w_value=None):
-        from pypy.module.micronumpy.interp_numarray import array
+        from pypy.module.micronumpy.ctors import array
         dtype = _get_dtype(space)
         if not space.is_none(w_value):
             w_arr = array(space, w_value, dtype, copy=False)
@@ -188,22 +188,22 @@
 
     def _binop_impl(ufunc_name):
         def impl(self, space, w_other, w_out=None):
-            from pypy.module.micronumpy import interp_ufuncs
-            return getattr(interp_ufuncs.get(space), ufunc_name).call(space,
+            from pypy.module.micronumpy import ufuncs
+            return getattr(ufuncs.get(space), ufunc_name).call(space,
                                                             [self, w_other, w_out])
         return func_with_new_name(impl, "binop_%s_impl" % ufunc_name)
 
     def _binop_right_impl(ufunc_name):
         def impl(self, space, w_other, w_out=None):
-            from pypy.module.micronumpy import interp_ufuncs
-            return getattr(interp_ufuncs.get(space), ufunc_name).call(space,
+            from pypy.module.micronumpy import ufuncs
+            return getattr(ufuncs.get(space), ufunc_name).call(space,
                                                             [w_other, self, w_out])
         return func_with_new_name(impl, "binop_right_%s_impl" % ufunc_name)
 
     def _unaryop_impl(ufunc_name):
         def impl(self, space, w_out=None):
-            from pypy.module.micronumpy import interp_ufuncs
-            return getattr(interp_ufuncs.get(space), ufunc_name).call(space,
+            from pypy.module.micronumpy import ufuncs
+            return getattr(ufuncs.get(space), ufunc_name).call(space,
                                                                     [self, w_out])
         return func_with_new_name(impl, "unaryop_%s_impl" % ufunc_name)
 
@@ -259,17 +259,17 @@
         return space.newtuple([w_quotient, w_remainder])
 
     def descr_any(self, space):
-        from pypy.module.micronumpy.interp_dtype import get_dtype_cache
+        from pypy.module.micronumpy.descriptor import get_dtype_cache
         value = space.is_true(self)
         return get_dtype_cache(space).w_booldtype.box(value)
 
     def descr_all(self, space):
-        from pypy.module.micronumpy.interp_dtype import get_dtype_cache
+        from pypy.module.micronumpy.descriptor import get_dtype_cache
         value = space.is_true(self)
         return get_dtype_cache(space).w_booldtype.box(value)
 
     def descr_zero(self, space):
-        from pypy.module.micronumpy.interp_dtype import get_dtype_cache
+        from pypy.module.micronumpy.descriptor import get_dtype_cache
         return get_dtype_cache(space).w_longdtype.box(0)
 
     def descr_ravel(self, space):
@@ -285,13 +285,13 @@
         return self.get_dtype(space).itemtype.round(self, decimals)
 
     def descr_astype(self, space, w_dtype):
-        from pypy.module.micronumpy.interp_dtype import W_Dtype
+        from pypy.module.micronumpy.descriptor import W_Dtype
         dtype = space.interp_w(W_Dtype,
             space.call_function(space.gettypefor(W_Dtype), w_dtype))
         return self.convert_to(space, dtype)
 
     def descr_view(self, space, w_dtype):
-        from pypy.module.micronumpy.interp_dtype import W_Dtype
+        from pypy.module.micronumpy.descriptor import W_Dtype
         try:
             subclass = space.is_true(space.issubtype(
                 w_dtype, space.gettypefor(W_NDimArray)))
@@ -520,7 +520,7 @@
 
 class W_StringBox(W_CharacterBox):
     def descr__new__string_box(space, w_subtype, w_arg):
-        from pypy.module.micronumpy.interp_dtype import new_string_dtype
+        from pypy.module.micronumpy.descriptor import new_string_dtype
         arg = space.str_w(space.str(w_arg))
         arr = VoidBoxStorage(len(arg), new_string_dtype(space, len(arg)))
         for i in range(len(arg)):
@@ -531,7 +531,7 @@
     def descr__new__unicode_box(space, w_subtype, w_arg):
         raise OperationError(space.w_NotImplementedError, space.wrap("Unicode is not supported yet"))
 
-        from pypy.module.micronumpy.interp_dtype import new_unicode_dtype
+        from pypy.module.micronumpy.descriptor import new_unicode_dtype
 
         arg = space.unicode_w(space.unicode_from_object(w_arg))
         # XXX size computations, we need tests anyway
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
@@ -7,12 +7,12 @@
 from pypy.interpreter import special
 from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root
 from pypy.interpreter.error import OperationError
-from pypy.module.micronumpy import interp_boxes
-from pypy.module.micronumpy.interp_dtype import get_dtype_cache
+from pypy.module.micronumpy import boxes
+from pypy.module.micronumpy.descriptor import get_dtype_cache
 from pypy.module.micronumpy.base import W_NDimArray
-from pypy.module.micronumpy.interp_numarray import array
-from pypy.module.micronumpy.interp_arrayops import where
-from pypy.module.micronumpy import interp_ufuncs
+from pypy.module.micronumpy.ctors import array
+from pypy.module.micronumpy.arrayops import where
+from pypy.module.micronumpy import ufuncs
 from rpython.rlib.objectmodel import specialize, instantiate
 from rpython.rlib.nonconst import NonConstant
 
@@ -151,7 +151,7 @@
     def float(self, w_obj):
         if isinstance(w_obj, FloatObject):
             return w_obj
-        assert isinstance(w_obj, interp_boxes.W_GenericBox)
+        assert isinstance(w_obj, boxes.W_GenericBox)
         return self.float(w_obj.descr_float(self))
 
     def float_w(self, w_obj):
@@ -183,13 +183,13 @@
     def int(self, w_obj):
         if isinstance(w_obj, IntObject):
             return w_obj
-        assert isinstance(w_obj, interp_boxes.W_GenericBox)
+        assert isinstance(w_obj, boxes.W_GenericBox)
         return self.int(w_obj.descr_int(self))
 
     def str(self, w_obj):
         if isinstance(w_obj, StringObject):
             return w_obj
-        assert isinstance(w_obj, interp_boxes.W_GenericBox)
+        assert isinstance(w_obj, boxes.W_GenericBox)
         return self.str(w_obj.descr_str(self))
 
     def is_true(self, w_obj):
@@ -399,7 +399,7 @@
         else:
             raise NotImplementedError
         if (not isinstance(w_res, W_NDimArray) and
-            not isinstance(w_res, interp_boxes.W_GenericBox)):
+            not isinstance(w_res, boxes.W_GenericBox)):
             dtype = get_dtype_cache(interp.space).w_float64dtype
             w_res = W_NDimArray.new_scalar(interp.space, dtype, w_res)
         return w_res
@@ -554,10 +554,10 @@
             elif self.name == "all":
                 w_res = arr.descr_all(interp.space)
             elif self.name == "unegative":
-                neg = interp_ufuncs.get(interp.space).negative
+                neg = ufuncs.get(interp.space).negative
                 w_res = neg.call(interp.space, [arr])
             elif self.name == "cos":
-                cos = interp_ufuncs.get(interp.space).cos
+                cos = ufuncs.get(interp.space).cos
                 w_res = cos.call(interp.space, [arr])
             elif self.name == "flat":
                 w_res = arr.descr_get_flatiter(interp.space)
@@ -611,7 +611,7 @@
             dtype = get_dtype_cache(interp.space).w_int64dtype
         elif isinstance(w_res, BoolObject):
             dtype = get_dtype_cache(interp.space).w_booldtype
-        elif isinstance(w_res, interp_boxes.W_GenericBox):
+        elif isinstance(w_res, boxes.W_GenericBox):
             dtype = w_res.get_dtype(interp.space)
         else:
             dtype = None
diff --git a/pypy/module/micronumpy/conversion_utils.py b/pypy/module/micronumpy/converters.py
rename from pypy/module/micronumpy/conversion_utils.py
rename to pypy/module/micronumpy/converters.py
--- a/pypy/module/micronumpy/conversion_utils.py
+++ b/pypy/module/micronumpy/converters.py
@@ -84,3 +84,15 @@
                 "duplicate value in 'axis'"))
         out[axis] = True
     return out
+
+
+def shape_converter(space, w_size, dtype):
+    if space.is_none(w_size):
+        return []
+    if space.isinstance_w(w_size, space.w_int):
+        return [space.int_w(w_size)]
+    shape = []
+    for w_item in space.fixedview(w_size):
+        shape.append(space.int_w(w_item))
+    shape += dtype.shape
+    return shape[:]
diff --git a/pypy/module/micronumpy/interp_support.py b/pypy/module/micronumpy/ctors.py
rename from pypy/module/micronumpy/interp_support.py
rename to pypy/module/micronumpy/ctors.py
--- a/pypy/module/micronumpy/interp_support.py
+++ b/pypy/module/micronumpy/ctors.py
@@ -1,12 +1,119 @@
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
 from rpython.rtyper.lltypesystem import lltype, rffi
-from pypy.module.micronumpy import interp_dtype, loop
+from pypy.module.micronumpy import descriptor, loop
 from rpython.rlib.rstring import strip_spaces
-from rpython.rlib.rarithmetic import maxint
-from pypy.module.micronumpy.base import W_NDimArray
+from pypy.module.micronumpy import ufuncs
+from pypy.module.micronumpy.base import W_NDimArray, convert_to_array
+from pypy.module.micronumpy.converters import shape_converter
+from pypy.module.micronumpy.strides import find_shape_and_elems
 
-FLOAT_SIZE = rffi.sizeof(lltype.Float)
+
+def build_scalar(space, w_dtype, w_state):
+    from rpython.rtyper.lltypesystem import rffi, lltype
+    if not isinstance(w_dtype, descriptor.W_Dtype):
+        raise oefmt(space.w_TypeError,
+                    "argument 1 must be numpy.dtype, not %T", w_dtype)
+    if w_dtype.elsize == 0:
+        raise oefmt(space.w_ValueError, "itemsize cannot be zero")
+    if not space.isinstance_w(w_state, space.w_str):
+        raise oefmt(space.w_TypeError, "initializing object must be a string")
+    if space.len_w(w_state) != w_dtype.elsize:
+        raise oefmt(space.w_ValueError, "initialization string is too small")
+    state = rffi.str2charp(space.str_w(w_state))
+    box = w_dtype.itemtype.box_raw_data(state)
+    lltype.free(state, flavor="raw")
+    return box
+
+
+ at unwrap_spec(ndmin=int, copy=bool, subok=bool)
+def array(space, w_object, w_dtype=None, copy=True, w_order=None, subok=False,
+          ndmin=0):
+    # for anything that isn't already an array, try __array__ method first
+    if not isinstance(w_object, W_NDimArray):
+        w___array__ = space.lookup(w_object, "__array__")
+        if w___array__ is not None:
+            if space.is_none(w_dtype):
+                w_dtype = space.w_None
+            w_array = space.get_and_call_function(w___array__, w_object, w_dtype)
+            if isinstance(w_array, W_NDimArray):
+                # feed w_array back into array() for other properties
+                return array(space, w_array, w_dtype, False, w_order, subok, ndmin)
+            else:
+                raise oefmt(space.w_ValueError,
+                            "object __array__ method not producing an array")
+
+    dtype = descriptor.decode_w_dtype(space, w_dtype)
+
+    if space.is_none(w_order):
+        order = 'C'
+    else:
+        order = space.str_w(w_order)
+        if order != 'C':  # or order != 'F':
+            raise oefmt(space.w_ValueError, "Unknown order: %s", order)
+
+    # arrays with correct dtype
+    if isinstance(w_object, W_NDimArray) and \
+            (space.is_none(w_dtype) or w_object.get_dtype() is dtype):
+        shape = w_object.get_shape()
+        if copy:
+            w_ret = w_object.descr_copy(space)
+        else:
+            if ndmin <= len(shape):
+                return w_object
+            new_impl = w_object.implementation.set_shape(space, w_object, shape)
+            w_ret = W_NDimArray(new_impl)
+        if ndmin > len(shape):
+            shape = [1] * (ndmin - len(shape)) + shape
+            w_ret.implementation = w_ret.implementation.set_shape(space,
+                                                                  w_ret, shape)
+        return w_ret
+
+    # not an array or incorrect dtype
+    shape, elems_w = find_shape_and_elems(space, w_object, dtype)
+    if dtype is None or (dtype.is_str_or_unicode() and dtype.elsize < 1):
+        for w_elem in elems_w:
+            if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar():
+                w_elem = w_elem.get_scalar_value()
+            dtype = ufuncs.find_dtype_for_scalar(space, w_elem, dtype)
+        if dtype is None:
+            dtype = descriptor.get_dtype_cache(space).w_float64dtype
+        elif dtype.is_str_or_unicode() and dtype.elsize < 1:
+            # promote S0 -> S1, U0 -> U1
+            dtype = descriptor.variable_dtype(space, dtype.char + '1')
+
+    if ndmin > len(shape):
+        shape = [1] * (ndmin - len(shape)) + shape
+    w_arr = W_NDimArray.from_shape(space, shape, dtype, order=order)
+    arr_iter = w_arr.create_iter()
+    for w_elem in elems_w:
+        arr_iter.setitem(dtype.coerce(space, w_elem))
+        arr_iter.next()
+    return w_arr
+
+
+def zeros(space, w_shape, w_dtype=None, w_order=None):
+    dtype = space.interp_w(descriptor.W_Dtype,
+        space.call_function(space.gettypefor(descriptor.W_Dtype), w_dtype))
+    if dtype.is_str_or_unicode() and dtype.elsize < 1:
+        dtype = descriptor.variable_dtype(space, dtype.char + '1')
+    shape = shape_converter(space, w_shape, dtype)
+    return W_NDimArray.from_shape(space, shape, dtype=dtype)
+
+
+ at unwrap_spec(subok=bool)
+def empty_like(space, w_a, w_dtype=None, w_order=None, subok=True):
+    w_a = convert_to_array(space, w_a)
+    if w_dtype is None:
+        dtype = w_a.get_dtype()
+    else:
+        dtype = space.interp_w(descriptor.W_Dtype,
+            space.call_function(space.gettypefor(descriptor.W_Dtype), w_dtype))
+        if dtype.is_str_or_unicode() and dtype.elsize < 1:
+            dtype = descriptor.variable_dtype(space, dtype.char + '1')
+    return W_NDimArray.from_shape(space, w_a.get_shape(), dtype=dtype,
+                                  w_instance=w_a if subok else None)
+
 
 def _fromstring_text(space, s, count, sep, length, dtype):
     sep_stripped = strip_spaces(sep)
@@ -58,6 +165,7 @@
 
     return space.wrap(a)
 
+
 def _fromstring_bin(space, s, count, length, dtype):
     itemsize = dtype.elsize
     assert itemsize >= 0
@@ -75,26 +183,13 @@
     loop.fromstring_loop(space, a, dtype, itemsize, s)
     return space.wrap(a)
 
+
 @unwrap_spec(s=str, count=int, sep=str, w_dtype=WrappedDefault(None))
 def fromstring(space, s, w_dtype=None, count=-1, sep=''):
-    dtype = space.interp_w(interp_dtype.W_Dtype,
-        space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype)
-    )
+    dtype = space.interp_w(descriptor.W_Dtype,
+        space.call_function(space.gettypefor(descriptor.W_Dtype), w_dtype))
     length = len(s)
     if sep == '':
         return _fromstring_bin(space, s, count, length, dtype)
     else:
         return _fromstring_text(space, s, count, sep, length, dtype)
-
-def unwrap_axis_arg(space, shapelen, w_axis):
-    if space.is_none(w_axis):
-        axis = maxint
-    else:
-        axis = space.int_w(w_axis)
-        if axis < -shapelen or axis >= shapelen:
-            raise oefmt(space.w_ValueError,
-                        "axis entry %d is out of bounds [%d, %d)",
-                        axis, -shapelen, shapelen)
-        if axis < 0:
-            axis += shapelen
-    return axis
diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/descriptor.py
rename from pypy/module/micronumpy/interp_dtype.py
rename to pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -4,12 +4,12 @@
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import (TypeDef, GetSetProperty,
                                       interp_attrproperty, interp_attrproperty_w)
-from pypy.module.micronumpy import types, interp_boxes, base
+from pypy.module.micronumpy import types, boxes, base
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.rarithmetic import r_longlong, r_ulonglong
 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.converters import byteorder_converter
 from pypy.module.micronumpy import support
 from pypy.module.micronumpy import constants as NPY
 
@@ -26,7 +26,7 @@
     """ agree on dtype from a list of arrays. if out is allocated,
     use it's dtype, otherwise allocate a new one with agreed dtype
     """
-    from pypy.module.micronumpy.interp_ufuncs import find_binop_result_dtype
+    from pypy.module.micronumpy.ufuncs import find_binop_result_dtype
 
     if not space.is_none(out):
         return out
@@ -448,7 +448,7 @@
         offset += subdtype.elsize
         names.append(fldname)
     return W_Dtype(types.RecordType(), NPY.VOID, NPY.VOIDLTR, NPY.VOIDLTR,
-                   space.gettypefor(interp_boxes.W_VoidBox),
+                   space.gettypefor(boxes.W_VoidBox),
                    names=names, fields=fields, elsize=offset)
 
 
@@ -490,7 +490,7 @@
             return subdtype
         size *= subdtype.elsize
         return W_Dtype(types.VoidType(), NPY.VOID, NPY.VOIDLTR, NPY.VOIDLTR,
-                       space.gettypefor(interp_boxes.W_VoidBox),
+                       space.gettypefor(boxes.W_VoidBox),
                        shape=shape, subdtype=subdtype, elsize=size)
 
     if space.is_none(w_dtype):
@@ -606,7 +606,7 @@
         num=NPY.STRING,
         kind=NPY.STRINGLTR,
         char=char,
-        w_box_type=space.gettypefor(interp_boxes.W_StringBox),
+        w_box_type=space.gettypefor(boxes.W_StringBox),
     )
 
 
@@ -618,7 +618,7 @@
         num=NPY.UNICODE,
         kind=NPY.UNICODELTR,
         char=NPY.UNICODELTR,
-        w_box_type=space.gettypefor(interp_boxes.W_UnicodeBox),
+        w_box_type=space.gettypefor(boxes.W_UnicodeBox),
     )
 
 
@@ -629,7 +629,7 @@
         num=NPY.VOID,
         kind=NPY.VOIDLTR,
         char=NPY.VOIDLTR,
-        w_box_type=space.gettypefor(interp_boxes.W_VoidBox),
+        w_box_type=space.gettypefor(boxes.W_VoidBox),
     )
 
 
@@ -640,119 +640,119 @@
             num=NPY.BOOL,
             kind=NPY.GENBOOLLTR,
             char=NPY.BOOLLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_BoolBox),
+            w_box_type=space.gettypefor(boxes.W_BoolBox),
         )
         self.w_int8dtype = W_Dtype(
             types.Int8(),
             num=NPY.BYTE,
             kind=NPY.SIGNEDLTR,
             char=NPY.BYTELTR,
-            w_box_type=space.gettypefor(interp_boxes.W_Int8Box),
+            w_box_type=space.gettypefor(boxes.W_Int8Box),
         )
         self.w_uint8dtype = W_Dtype(
             types.UInt8(),
             num=NPY.UBYTE,
             kind=NPY.UNSIGNEDLTR,
             char=NPY.UBYTELTR,
-            w_box_type=space.gettypefor(interp_boxes.W_UInt8Box),
+            w_box_type=space.gettypefor(boxes.W_UInt8Box),
         )
         self.w_int16dtype = W_Dtype(
             types.Int16(),
             num=NPY.SHORT,
             kind=NPY.SIGNEDLTR,
             char=NPY.SHORTLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_Int16Box),
+            w_box_type=space.gettypefor(boxes.W_Int16Box),
         )
         self.w_uint16dtype = W_Dtype(
             types.UInt16(),
             num=NPY.USHORT,
             kind=NPY.UNSIGNEDLTR,
             char=NPY.USHORTLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_UInt16Box),
+            w_box_type=space.gettypefor(boxes.W_UInt16Box),
         )
         self.w_int32dtype = W_Dtype(
             types.Int32(),
             num=NPY.INT,
             kind=NPY.SIGNEDLTR,
             char=NPY.INTLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_Int32Box),
+            w_box_type=space.gettypefor(boxes.W_Int32Box),
         )
         self.w_uint32dtype = W_Dtype(
             types.UInt32(),
             num=NPY.UINT,
             kind=NPY.UNSIGNEDLTR,
             char=NPY.UINTLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_UInt32Box),
+            w_box_type=space.gettypefor(boxes.W_UInt32Box),
         )
         self.w_longdtype = W_Dtype(
             types.Long(),
             num=NPY.LONG,
             kind=NPY.SIGNEDLTR,
             char=NPY.LONGLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_LongBox),
+            w_box_type=space.gettypefor(boxes.W_LongBox),
         )
         self.w_ulongdtype = W_Dtype(
             types.ULong(),
             num=NPY.ULONG,
             kind=NPY.UNSIGNEDLTR,
             char=NPY.ULONGLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_ULongBox),
+            w_box_type=space.gettypefor(boxes.W_ULongBox),
         )
         self.w_int64dtype = W_Dtype(
             types.Int64(),
             num=NPY.LONGLONG,
             kind=NPY.SIGNEDLTR,
             char=NPY.LONGLONGLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_Int64Box),
+            w_box_type=space.gettypefor(boxes.W_Int64Box),
         )
         self.w_uint64dtype = W_Dtype(
             types.UInt64(),
             num=NPY.ULONGLONG,
             kind=NPY.UNSIGNEDLTR,
             char=NPY.ULONGLONGLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_UInt64Box),
+            w_box_type=space.gettypefor(boxes.W_UInt64Box),
         )
         self.w_float32dtype = W_Dtype(
             types.Float32(),
             num=NPY.FLOAT,
             kind=NPY.FLOATINGLTR,
             char=NPY.FLOATLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_Float32Box),
+            w_box_type=space.gettypefor(boxes.W_Float32Box),
         )
         self.w_float64dtype = W_Dtype(
             types.Float64(),
             num=NPY.DOUBLE,
             kind=NPY.FLOATINGLTR,
             char=NPY.DOUBLELTR,
-            w_box_type=space.gettypefor(interp_boxes.W_Float64Box),
+            w_box_type=space.gettypefor(boxes.W_Float64Box),
         )
         self.w_floatlongdtype = W_Dtype(
             types.FloatLong(),
             num=NPY.LONGDOUBLE,
             kind=NPY.FLOATINGLTR,
             char=NPY.LONGDOUBLELTR,
-            w_box_type=space.gettypefor(interp_boxes.W_FloatLongBox),
+            w_box_type=space.gettypefor(boxes.W_FloatLongBox),
         )
         self.w_complex64dtype = W_Dtype(
             types.Complex64(),
             num=NPY.CFLOAT,
             kind=NPY.COMPLEXLTR,
             char=NPY.CFLOATLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_Complex64Box),
+            w_box_type=space.gettypefor(boxes.W_Complex64Box),
         )
         self.w_complex128dtype = W_Dtype(
             types.Complex128(),
             num=NPY.CDOUBLE,
             kind=NPY.COMPLEXLTR,
             char=NPY.CDOUBLELTR,
-            w_box_type=space.gettypefor(interp_boxes.W_Complex128Box),
+            w_box_type=space.gettypefor(boxes.W_Complex128Box),
         )
         self.w_complexlongdtype = W_Dtype(
             types.ComplexLong(),
             num=NPY.CLONGDOUBLE,
             kind=NPY.COMPLEXLTR,
             char=NPY.CLONGDOUBLELTR,
-            w_box_type=space.gettypefor(interp_boxes.W_ComplexLongBox),
+            w_box_type=space.gettypefor(boxes.W_ComplexLongBox),
         )
         self.w_stringdtype = W_Dtype(
             types.StringType(),
@@ -760,7 +760,7 @@
             num=NPY.STRING,
             kind=NPY.STRINGLTR,
             char=NPY.STRINGLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_StringBox),
+            w_box_type=space.gettypefor(boxes.W_StringBox),
         )
         self.w_unicodedtype = W_Dtype(
             types.UnicodeType(),
@@ -768,7 +768,7 @@
             num=NPY.UNICODE,
             kind=NPY.UNICODELTR,
             char=NPY.UNICODELTR,
-            w_box_type=space.gettypefor(interp_boxes.W_UnicodeBox),
+            w_box_type=space.gettypefor(boxes.W_UnicodeBox),
         )
         self.w_voiddtype = W_Dtype(
             types.VoidType(),
@@ -776,28 +776,28 @@
             num=NPY.VOID,
             kind=NPY.VOIDLTR,
             char=NPY.VOIDLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_VoidBox),
+            w_box_type=space.gettypefor(boxes.W_VoidBox),
         )
         self.w_float16dtype = W_Dtype(
             types.Float16(),
             num=NPY.HALF,
             kind=NPY.FLOATINGLTR,
             char=NPY.HALFLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_Float16Box),
+            w_box_type=space.gettypefor(boxes.W_Float16Box),
         )
         self.w_intpdtype = W_Dtype(
             types.Long(),
             num=NPY.LONG,
             kind=NPY.SIGNEDLTR,
             char=NPY.INTPLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_LongBox),
+            w_box_type=space.gettypefor(boxes.W_LongBox),
         )
         self.w_uintpdtype = W_Dtype(
             types.ULong(),
             num=NPY.ULONG,
             kind=NPY.UNSIGNEDLTR,
             char=NPY.UINTPLTR,
-            w_box_type=space.gettypefor(interp_boxes.W_ULongBox),
+            w_box_type=space.gettypefor(boxes.W_ULongBox),
         )
         aliases = {
             NPY.BOOL:        ['bool', 'bool8'],
@@ -821,19 +821,19 @@
         self.alternate_constructors = {
             NPY.BOOL:     [space.w_bool],
             NPY.LONG:     [space.w_int,
-                           space.gettypefor(interp_boxes.W_IntegerBox),
-                           space.gettypefor(interp_boxes.W_SignedIntegerBox)],
-            NPY.ULONG:    [space.gettypefor(interp_boxes.W_UnsignedIntegerBox)],
+                           space.gettypefor(boxes.W_IntegerBox),
+                           space.gettypefor(boxes.W_SignedIntegerBox)],
+            NPY.ULONG:    [space.gettypefor(boxes.W_UnsignedIntegerBox)],
             NPY.LONGLONG: [space.w_long],
             NPY.DOUBLE:   [space.w_float,
-                           space.gettypefor(interp_boxes.W_NumberBox),
-                           space.gettypefor(interp_boxes.W_FloatingBox)],
+                           space.gettypefor(boxes.W_NumberBox),
+                           space.gettypefor(boxes.W_FloatingBox)],
             NPY.CDOUBLE:  [space.w_complex,
-                           space.gettypefor(interp_boxes.W_ComplexFloatingBox)],
+                           space.gettypefor(boxes.W_ComplexFloatingBox)],
             NPY.STRING:   [space.w_str,
-                           space.gettypefor(interp_boxes.W_CharacterBox)],
+                           space.gettypefor(boxes.W_CharacterBox)],
             NPY.UNICODE:  [space.w_unicode],
-            NPY.VOID:     [space.gettypefor(interp_boxes.W_GenericBox)],
+            NPY.VOID:     [space.gettypefor(boxes.W_GenericBox)],
                            #space.w_buffer,  # XXX no buffer in space
         }
         float_dtypes = [self.w_float16dtype, self.w_float32dtype,
@@ -909,16 +909,16 @@
         }
 
         typeinfo_partial = {
-            'Generic': interp_boxes.W_GenericBox,
-            'Character': interp_boxes.W_CharacterBox,
-            'Flexible': interp_boxes.W_FlexibleBox,
-            'Inexact': interp_boxes.W_InexactBox,
-            'Integer': interp_boxes.W_IntegerBox,
-            'SignedInteger': interp_boxes.W_SignedIntegerBox,
-            'UnsignedInteger': interp_boxes.W_UnsignedIntegerBox,
-            'ComplexFloating': interp_boxes.W_ComplexFloatingBox,
-            'Number': interp_boxes.W_NumberBox,
-            'Floating': interp_boxes.W_FloatingBox
+            'Generic': boxes.W_GenericBox,
+            'Character': boxes.W_CharacterBox,
+            'Flexible': boxes.W_FlexibleBox,
+            'Inexact': boxes.W_InexactBox,
+            'Integer': boxes.W_IntegerBox,
+            'SignedInteger': boxes.W_SignedIntegerBox,
+            'UnsignedInteger': boxes.W_UnsignedIntegerBox,
+            'ComplexFloating': boxes.W_ComplexFloatingBox,
+            'Number': boxes.W_NumberBox,
+            'Floating': boxes.W_FloatingBox
         }
         w_typeinfo = space.newdict()
         for k, v in typeinfo_partial.iteritems():
diff --git a/pypy/module/micronumpy/interp_flagsobj.py b/pypy/module/micronumpy/flagsobj.py
rename from pypy/module/micronumpy/interp_flagsobj.py
rename to pypy/module/micronumpy/flagsobj.py
diff --git a/pypy/module/micronumpy/interp_flatiter.py b/pypy/module/micronumpy/flatiter.py
rename from pypy/module/micronumpy/interp_flatiter.py
rename to pypy/module/micronumpy/flatiter.py
--- a/pypy/module/micronumpy/interp_flatiter.py
+++ b/pypy/module/micronumpy/flatiter.py
@@ -1,7 +1,7 @@
 from pypy.module.micronumpy.base import W_NDimArray, convert_to_array
 from pypy.module.micronumpy import loop
 from pypy.module.micronumpy.concrete import BaseConcreteArray
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 
 
 class FakeArrayImplementation(BaseConcreteArray):
@@ -23,6 +23,7 @@
         assert isinstance(self.base(), W_NDimArray)
         return self.base().create_iter()
 
+
 class W_FlatIterator(W_NDimArray):
     def __init__(self, arr):
         self.base = arr
@@ -54,9 +55,8 @@
 
     def descr_getitem(self, space, w_idx):
         if not (space.isinstance_w(w_idx, space.w_int) or
-            space.isinstance_w(w_idx, space.w_slice)):
-            raise OperationError(space.w_IndexError,
-                                 space.wrap('unsupported iterator index'))
+                space.isinstance_w(w_idx, space.w_slice)):
+            raise oefmt(space.w_IndexError, 'unsupported iterator index')
         self.reset()
         base = self.base
         start, stop, step, length = space.decode_index4(w_idx, base.get_size())
@@ -70,9 +70,8 @@
 
     def descr_setitem(self, space, w_idx, w_value):
         if not (space.isinstance_w(w_idx, space.w_int) or
-            space.isinstance_w(w_idx, space.w_slice)):
-            raise OperationError(space.w_IndexError,
-                                 space.wrap('unsupported iterator index'))
+                space.isinstance_w(w_idx, space.w_slice)):
+            raise oefmt(space.w_IndexError, 'unsupported iterator index')
         base = self.base
         start, stop, step, length = space.decode_index4(w_idx, base.get_size())
         arr = convert_to_array(space, w_value)
@@ -84,4 +83,4 @@
     def descr_base(self, space):
         return space.wrap(self.base)
 
-# typedef is in interp_numarray, so we see the additional arguments
+# typedef is in interp_ndarray, so we see the additional arguments
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/ndarray.py
rename from pypy/module/micronumpy/interp_numarray.py
rename to pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -6,34 +6,23 @@
                                      WrappedDefault
 from pypy.module.micronumpy.base import W_NDimArray, convert_to_array,\
      ArrayArgumentException, wrap_impl
-from pypy.module.micronumpy import interp_dtype, interp_ufuncs, interp_boxes,\
-     interp_arrayops
-from pypy.module.micronumpy.strides import find_shape_and_elems,\
-     get_shape_from_iterable, to_coords, shape_agreement, \
-     shape_agreement_multiple
-from pypy.module.micronumpy.interp_flagsobj import W_FlagsObject
-from pypy.module.micronumpy.interp_flatiter import W_FlatIterator
+from pypy.module.micronumpy import descriptor, ufuncs, boxes, arrayops
+from pypy.module.micronumpy.strides import get_shape_from_iterable, to_coords, \
+    shape_agreement, shape_agreement_multiple
+from pypy.module.micronumpy.flagsobj import W_FlagsObject
+from pypy.module.micronumpy.flatiter import W_FlatIterator
 from pypy.module.micronumpy.appbridge import get_appbridge_cache
 from pypy.module.micronumpy import loop
-from pypy.module.micronumpy.interp_arrayops import repeat, choose, put
+from pypy.module.micronumpy.arrayops import repeat, choose, put
 from rpython.tool.sourcetools import func_with_new_name
 from rpython.rlib import jit
 from rpython.rlib.rstring import StringBuilder
 from pypy.module.micronumpy.concrete import BaseConcreteArray
-from pypy.module.micronumpy.conversion_utils import order_converter, multi_axis_converter
+from pypy.module.micronumpy.converters import order_converter, shape_converter, \
+    multi_axis_converter
 from pypy.module.micronumpy import support
 from pypy.module.micronumpy import constants as NPY
 
-def _find_shape(space, w_size, dtype):
-    if space.is_none(w_size):
-        return []
-    if space.isinstance_w(w_size, space.w_int):
-        return [space.int_w(w_size)]
-    shape = []
-    for w_item in space.fixedview(w_size):
-        shape.append(space.int_w(w_item))
-    shape += dtype.shape
-    return shape[:]
 
 def _match_dot_shapes(space, left, right):
     left_shape = left.get_shape()
@@ -84,8 +73,8 @@
         return self.implementation.dtype
 
     def descr_set_dtype(self, space, w_dtype):
-        dtype = space.interp_w(interp_dtype.W_Dtype,
-            space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
+        dtype = space.interp_w(descriptor.W_Dtype,
+            space.call_function(space.gettypefor(descriptor.W_Dtype), w_dtype))
         if (dtype.elsize != self.get_dtype().elsize or
                 dtype.is_flexible() or self.get_dtype().is_flexible()):
             raise OperationError(space.w_ValueError, space.wrap(
@@ -424,7 +413,7 @@
         return self.implementation.swapaxes(space, self, axis1, axis2)
 
     def descr_nonzero(self, space):
-        index_type = interp_dtype.get_dtype_cache(space).w_int64dtype
+        index_type = descriptor.get_dtype_cache(space).w_int64dtype
         return self.implementation.nonzero(space, index_type)
 
     def descr_tolist(self, space):
@@ -492,7 +481,7 @@
         if space.is_none(w_arg):
             if self.get_size() == 1:
                 w_obj = self.get_scalar_value()
-                assert isinstance(w_obj, interp_boxes.W_GenericBox)
+                assert isinstance(w_obj, boxes.W_GenericBox)
                 return w_obj.item(space)
             raise oefmt(space.w_ValueError,
                 "can only convert an array of size 1 to a Python scalar")
@@ -501,7 +490,7 @@
                 raise oefmt(space.w_IndexError, "index out of bounds")
             i = self.to_coords(space, w_arg)
             item = self.getitem(space, i)
-            assert isinstance(item, interp_boxes.W_GenericBox)
+            assert isinstance(item, boxes.W_GenericBox)
             return item.item(space)
         raise OperationError(space.w_NotImplementedError, space.wrap(
             "non-int arg not supported"))
@@ -565,15 +554,15 @@
 
     def descr_astype(self, space, w_dtype):
         cur_dtype = self.get_dtype()
-        new_dtype = space.interp_w(interp_dtype.W_Dtype,
-            space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
+        new_dtype = space.interp_w(descriptor.W_Dtype,
+            space.call_function(space.gettypefor(descriptor.W_Dtype), w_dtype))
         if new_dtype.num == NPY.VOID:
             raise oefmt(space.w_NotImplementedError,
                         "astype(%s) not implemented yet",
                         new_dtype.get_name())
         if new_dtype.num == NPY.STRING and new_dtype.elsize == 0:
             if cur_dtype.num == NPY.STRING:
-                new_dtype = interp_dtype.variable_dtype(space,
+                new_dtype = descriptor.variable_dtype(space,
                     'S' + str(cur_dtype.elsize))
         impl = self.implementation
         new_impl = impl.astype(space, new_dtype)
@@ -608,7 +597,7 @@
         min = convert_to_array(space, w_min)
         max = convert_to_array(space, w_max)
         shape = shape_agreement_multiple(space, [self, min, max, w_out])
-        out = interp_dtype.dtype_agreement(space, [self, min, max], shape,
+        out = descriptor.dtype_agreement(space, [self, min, max], shape,
                                            w_out)
         loop.clip(space, self, shape, min, max, out)
         return out
@@ -633,7 +622,7 @@
         if axis1 == axis2:
             raise OperationError(space.w_ValueError, space.wrap(
                 "axis1 and axis2 cannot be the same"))
-        return interp_arrayops.diagonal(space, self.implementation, offset,
+        return arrayops.diagonal(space, self.implementation, offset,
                                         axis1, axis2)
 
     @unwrap_spec(offset=int, axis1=int, axis2=int)
@@ -685,16 +674,16 @@
             if self.get_dtype().is_bool():
                 #numpy promotes bool.round() to float16. Go figure.
                 w_out = W_NDimArray.from_shape(space, self.get_shape(),
-                       interp_dtype.get_dtype_cache(space).w_float16dtype)
+                       descriptor.get_dtype_cache(space).w_float16dtype)
             else:
                 w_out = None
         elif not isinstance(w_out, W_NDimArray):
             raise OperationError(space.w_TypeError, space.wrap(
                 "return arrays must be of ArrayType"))
-        out = interp_dtype.dtype_agreement(space, [self], self.get_shape(),
+        out = descriptor.dtype_agreement(space, [self], self.get_shape(),
                                            w_out)
         if out.get_dtype().is_bool() and self.get_dtype().is_bool():
-            calc_dtype = interp_dtype.get_dtype_cache(space).w_longdtype
+            calc_dtype = descriptor.get_dtype_cache(space).w_longdtype
         else:
             calc_dtype = out.get_dtype()
 
@@ -769,8 +758,8 @@
                 else:
                     raise
         if w_dtype:
-            dtype = space.interp_w(interp_dtype.W_Dtype,
-                space.call_function(space.gettypefor(interp_dtype.W_Dtype),
+            dtype = space.interp_w(descriptor.W_Dtype,
+                space.call_function(space.gettypefor(descriptor.W_Dtype),
                                                                    w_dtype))
         else:
             dtype = self.get_dtype()
@@ -813,7 +802,7 @@
 
     def _unaryop_impl(ufunc_name):
         def impl(self, space, w_out=None):
-            return getattr(interp_ufuncs.get(space), ufunc_name).call(space,
+            return getattr(ufuncs.get(space), ufunc_name).call(space,
                                                                 [self, w_out])
         return func_with_new_name(impl, "unaryop_%s_impl" % ufunc_name)
 
@@ -833,7 +822,7 @@
 
     def _binop_impl(ufunc_name):
         def impl(self, space, w_other, w_out=None):
-            return getattr(interp_ufuncs.get(space), ufunc_name).call(space,
+            return getattr(ufuncs.get(space), ufunc_name).call(space,
                                                         [self, w_other, w_out])
         return func_with_new_name(impl, "binop_%s_impl" % ufunc_name)
 
@@ -877,7 +866,7 @@
     def _binop_inplace_impl(ufunc_name):
         def impl(self, space, w_other):
             w_out = self
-            ufunc = getattr(interp_ufuncs.get(space), ufunc_name)
+            ufunc = getattr(ufuncs.get(space), ufunc_name)
             return ufunc.call(space, [self, w_other, w_out])
         return func_with_new_name(impl, "binop_inplace_%s_impl" % ufunc_name)
 
@@ -898,7 +887,7 @@
     def _binop_right_impl(ufunc_name):
         def impl(self, space, w_other, w_out=None):
             w_other = convert_to_array(space, w_other)
-            return getattr(interp_ufuncs.get(space), ufunc_name).call(space, [w_other, self, w_out])
+            return getattr(ufuncs.get(space), ufunc_name).call(space, [w_other, self, w_out])
         return func_with_new_name(impl, "binop_right_%s_impl" % ufunc_name)
 
     descr_radd = _binop_right_impl("add")
@@ -936,7 +925,7 @@
             w_res = self.descr_mul(space, other)
             assert isinstance(w_res, W_NDimArray)
             return w_res.descr_sum(space, space.wrap(-1), out)
-        dtype = interp_ufuncs.find_binop_result_dtype(space, self.get_dtype(),
+        dtype = ufuncs.find_binop_result_dtype(space, self.get_dtype(),
                                                              other.get_dtype())
         if self.get_size() < 1 and other.get_size() < 1:
             # numpy compatability
@@ -992,7 +981,7 @@
                         'output must be an array'))
             else:
                 out = w_out
-            return getattr(interp_ufuncs.get(space), ufunc_name).reduce(
+            return getattr(ufuncs.get(space), ufunc_name).reduce(
                 space, self, w_axis, keepdims, out, w_dtype, cumulative=cumulative)
         return func_with_new_name(impl, "reduce_%s_impl_%d" % (ufunc_name, cumulative))
 
@@ -1067,7 +1056,7 @@
                 "only integer arrays with one element "
                 "can be converted to an index"))
         value = self.get_scalar_value()
-        assert isinstance(value, interp_boxes.W_GenericBox)
+        assert isinstance(value, boxes.W_GenericBox)
         return value.item(space)
 
     def descr_reduce(self, space):
@@ -1117,7 +1106,7 @@
         dtype = space.getitem(w_state, space.wrap(base_index+1))
         #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):
+        if not isinstance(dtype, descriptor.W_Dtype):
             raise OperationError(space.w_ValueError, space.wrap(
                  "__setstate__(self, (shape, dtype, .. called with improper dtype '%r'" % dtype))
         self.implementation = W_NDimArray.from_shape_and_storage(space,
@@ -1140,9 +1129,9 @@
                     offset=0, w_strides=None, w_order=None):
     from pypy.module.micronumpy.concrete import ConcreteArray
     from pypy.module.micronumpy.support import calc_strides
-    dtype = space.interp_w(interp_dtype.W_Dtype,
-          space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
-    shape = _find_shape(space, w_shape, dtype)
+    dtype = space.interp_w(descriptor.W_Dtype,
+          space.call_function(space.gettypefor(descriptor.W_Dtype), w_dtype))
+    shape = shape_converter(space, w_shape, dtype)
 
     if not space.is_none(w_buffer):
         if (not space.is_none(w_strides)):
@@ -1192,10 +1181,10 @@
     PyPy-only implementation detail.
     """
     storage = rffi.cast(RAW_STORAGE_PTR, addr)
-    dtype = space.interp_w(interp_dtype.W_Dtype,
-                     space.call_function(space.gettypefor(interp_dtype.W_Dtype),
+    dtype = space.interp_w(descriptor.W_Dtype,
+                     space.call_function(space.gettypefor(descriptor.W_Dtype),
                              w_dtype))
-    shape = _find_shape(space, w_shape, dtype)
+    shape = shape_converter(space, w_shape, dtype)
     if w_subtype:
         if not space.isinstance_w(w_subtype, space.w_type):
             raise OperationError(space.w_ValueError, space.wrap(
@@ -1396,107 +1385,6 @@
     __array__         = interp2app(W_NDimArray.descr___array__),
 )
 
- at unwrap_spec(ndmin=int, copy=bool, subok=bool)
-def array(space, w_object, w_dtype=None, copy=True, w_order=None, subok=False,
-          ndmin=0):
-    # for anything that isn't already an array, try __array__ method first
-    if not isinstance(w_object, W_NDimArray):
-        w___array__ = space.lookup(w_object, "__array__")
-        if w___array__ is not None:
-            if space.is_none(w_dtype):
-                w_dtype = space.w_None
-            w_array = space.get_and_call_function(w___array__, w_object, w_dtype)
-            if isinstance(w_array, W_NDimArray):
-                # feed w_array back into array() for other properties
-                return array(space, w_array, w_dtype, False, w_order, subok, ndmin)
-            else:
-                raise oefmt(space.w_ValueError,
-                            "object __array__ method not producing an array")
-
-    dtype = interp_dtype.decode_w_dtype(space, w_dtype)
-
-    if space.is_none(w_order):
-        order = 'C'
-    else:
-        order = space.str_w(w_order)
-        if order != 'C':  # or order != 'F':
-            raise oefmt(space.w_ValueError, "Unknown order: %s", order)
-
-    # arrays with correct dtype
-    if isinstance(w_object, W_NDimArray) and \
-            (space.is_none(w_dtype) or w_object.get_dtype() is dtype):
-        shape = w_object.get_shape()
-        if copy:
-            w_ret = w_object.descr_copy(space)
-        else:
-            if ndmin <= len(shape):
-                return w_object
-            new_impl = w_object.implementation.set_shape(space, w_object, shape)
-            w_ret = W_NDimArray(new_impl)
-        if ndmin > len(shape):
-            shape = [1] * (ndmin - len(shape)) + shape
-            w_ret.implementation = w_ret.implementation.set_shape(space,
-                                                                  w_ret, shape)
-        return w_ret
-
-    # not an array or incorrect dtype
-    shape, elems_w = find_shape_and_elems(space, w_object, dtype)
-    if dtype is None or (dtype.is_str_or_unicode() and dtype.elsize < 1):
-        for w_elem in elems_w:
-            if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar():
-                w_elem = w_elem.get_scalar_value()
-            dtype = interp_ufuncs.find_dtype_for_scalar(space, w_elem, dtype)
-        if dtype is None:
-            dtype = interp_dtype.get_dtype_cache(space).w_float64dtype
-        elif dtype.is_str_or_unicode() and dtype.elsize < 1:
-            # promote S0 -> S1, U0 -> U1
-            dtype = interp_dtype.variable_dtype(space, dtype.char + '1')
-
-    if ndmin > len(shape):
-        shape = [1] * (ndmin - len(shape)) + shape
-    w_arr = W_NDimArray.from_shape(space, shape, dtype, order=order)
-    arr_iter = w_arr.create_iter()
-    for w_elem in elems_w:
-        arr_iter.setitem(dtype.coerce(space, w_elem))
-        arr_iter.next()
-    return w_arr
-
-def zeros(space, w_shape, w_dtype=None, w_order=None):
-    dtype = space.interp_w(interp_dtype.W_Dtype,
-        space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
-    if dtype.is_str_or_unicode() and dtype.elsize < 1:
-        dtype = interp_dtype.variable_dtype(space, dtype.char + '1')
-    shape = _find_shape(space, w_shape, dtype)
-    return W_NDimArray.from_shape(space, shape, dtype=dtype)
-
- at unwrap_spec(subok=bool)
-def empty_like(space, w_a, w_dtype=None, w_order=None, subok=True):
-    w_a = convert_to_array(space, w_a)
-    if w_dtype is None:
-        dtype = w_a.get_dtype()
-    else:
-        dtype = space.interp_w(interp_dtype.W_Dtype,
-            space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
-        if dtype.is_str_or_unicode() and dtype.elsize < 1:
-            dtype = interp_dtype.variable_dtype(space, dtype.char + '1')
-    return W_NDimArray.from_shape(space, w_a.get_shape(), dtype=dtype,
-                                  w_instance=w_a if subok else None)
-
-def build_scalar(space, w_dtype, w_state):
-    from rpython.rtyper.lltypesystem import rffi, lltype
-    if not isinstance(w_dtype, interp_dtype.W_Dtype):
-        raise oefmt(space.w_TypeError,
-                    "argument 1 must be numpy.dtype, not %T", w_dtype)
-    if w_dtype.elsize == 0:
-        raise oefmt(space.w_ValueError, "itemsize cannot be zero")
-    if not space.isinstance_w(w_state, space.w_str):
-        raise oefmt(space.w_TypeError, "initializing object must be a string")
-    if space.len_w(w_state) != w_dtype.elsize:
-        raise oefmt(space.w_ValueError, "initialization string is too small")
-    state = rffi.str2charp(space.str_w(w_state))
-    box = w_dtype.itemtype.box_raw_data(state)
-    lltype.free(state, flavor="raw")
-    return box
 
 def _reconstruct(space, w_subtype, w_shape, w_dtype):
     return descr_new_array(space, w_subtype, w_shape, w_dtype)
diff --git a/pypy/module/micronumpy/sort.py b/pypy/module/micronumpy/sort.py
--- a/pypy/module/micronumpy/sort.py
+++ b/pypy/module/micronumpy/sort.py
@@ -12,7 +12,7 @@
 from rpython.rlib.objectmodel import specialize
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.module.micronumpy.base import W_NDimArray
-from pypy.module.micronumpy import interp_dtype, types, constants as NPY
+from pypy.module.micronumpy import descriptor, types, constants as NPY
 from pypy.module.micronumpy.iter import AxisIterator
 
 INT_SIZE = rffi.sizeof(lltype.Signed)
@@ -71,7 +71,7 @@
     class ArgArrayRepWithStorage(Repr):
         def __init__(self, index_stride_size, stride_size, size):
             start = 0
-            dtype = interp_dtype.get_dtype_cache(space).w_longdtype
+            dtype = descriptor.get_dtype_cache(space).w_longdtype
             indexes = dtype.itemtype.malloc(size * dtype.elsize)
             values = alloc_raw_storage(size * stride_size,
                                             track_allocation=False)
@@ -132,7 +132,7 @@
         else:
             axis = space.int_w(w_axis)
         # create array of indexes
-        dtype = interp_dtype.get_dtype_cache(space).w_longdtype
+        dtype = descriptor.get_dtype_cache(space).w_longdtype
         index_arr = W_NDimArray.from_shape(space, arr.get_shape(), dtype)
         storage = index_arr.implementation.get_storage()
         if len(arr.get_shape()) == 1:
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_ndarray.py
rename from pypy/module/micronumpy/test/test_numarray.py
rename to pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -4,7 +4,7 @@
 from pypy.conftest import option
 from pypy.module.micronumpy.appbridge import get_appbridge_cache
 from pypy.module.micronumpy.strides import Chunk, Chunks
-from pypy.module.micronumpy.interp_numarray import W_NDimArray
+from pypy.module.micronumpy.ndarray import W_NDimArray
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
 
 
@@ -197,7 +197,7 @@
     def test_from_shape_and_storage(self):
         from rpython.rlib.rawstorage import alloc_raw_storage, raw_storage_setitem
         from rpython.rtyper.lltypesystem import rffi
-        from pypy.module.micronumpy.interp_dtype import get_dtype_cache
+        from pypy.module.micronumpy.descriptor import get_dtype_cache
         storage = alloc_raw_storage(4, track_allocation=False, zero=True)
         for i in range(4):
             raw_storage_setitem(storage, i, rffi.cast(rffi.UCHAR, i))
@@ -2303,8 +2303,12 @@
         import numpy as np
         a = np.array(1.5)
         assert a[...] is a
+        #a[...] = 2.5
+        #assert a == 2.5
         a = np.array([1, 2, 3])
         assert a[...] is a
+        #a[...] = 4
+        #assert (a == [4, 4, 4]).all()
 
 
 class AppTestNumArrayFromBuffer(BaseNumpyAppTest):
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -1,7 +1,7 @@
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
-from pypy.module.micronumpy.interp_ufuncs import (find_binop_result_dtype,
+from pypy.module.micronumpy.ufuncs import (find_binop_result_dtype,
         find_unaryop_result_dtype)
-from pypy.module.micronumpy.interp_dtype import get_dtype_cache
+from pypy.module.micronumpy.descriptor import get_dtype_cache
 
 
 class TestUfuncCoercion(object):
@@ -763,8 +763,17 @@
         assert add.reduce(1) == 1
 
         assert list(maximum.reduce(zeros((2, 0)), axis=0)) == []
-        raises(ValueError, maximum.reduce, zeros((2, 0)), axis=None)
-        raises(ValueError, maximum.reduce, zeros((2, 0)), axis=1)
+        exc = raises(ValueError, maximum.reduce, zeros((2, 0)), axis=None)
+        assert exc.value[0] == ('zero-size array to reduction operation '
+                                'maximum which has no identity')
+        exc = raises(ValueError, maximum.reduce, zeros((2, 0)), axis=1)
+        assert exc.value[0] == ('zero-size array to reduction operation '
+                                'maximum which has no identity')
+
+        a = zeros((2, 2)) + 1
+        assert (add.reduce(a, axis=1) == [2, 2]).all()
+        exc = raises(ValueError, add.reduce, a, axis=2)
+        assert exc.value[0] == "'axis' entry is out of bounds"
 
     def test_reduce_1d(self):
         from numpypy import array, add, maximum, less, float16, complex64
diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -5,7 +5,7 @@
 import py
 from rpython.jit.metainterp.test.support import LLJitMixin
 from rpython.jit.metainterp.warmspot import reset_jit, get_stats
-from pypy.module.micronumpy import interp_boxes
+from pypy.module.micronumpy import boxes
 from pypy.module.micronumpy.compile import FakeSpace, Parser, InterpreterState
 from pypy.module.micronumpy.base import W_NDimArray
 
@@ -48,11 +48,11 @@
             w_res = interp.results[-1]
             if isinstance(w_res, W_NDimArray):
                 w_res = w_res.create_iter().getitem()
-            if isinstance(w_res, interp_boxes.W_Float64Box):
+            if isinstance(w_res, boxes.W_Float64Box):
                 return w_res.value
-            if isinstance(w_res, interp_boxes.W_Int64Box):
+            if isinstance(w_res, boxes.W_Int64Box):
                 return float(w_res.value)
-            elif isinstance(w_res, interp_boxes.W_BoolBox):
+            elif isinstance(w_res, boxes.W_BoolBox):
                 return float(w_res.value)
             raise TypeError(w_res)
 
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
@@ -2,7 +2,7 @@
 import math
 
 from pypy.interpreter.error import OperationError, oefmt
-from pypy.module.micronumpy import interp_boxes
+from pypy.module.micronumpy import boxes
 from pypy.module.micronumpy import support
 from pypy.module.micronumpy.concrete import SliceArray, VoidBoxStorage
 from pypy.objspace.std.floatobject import float2string
@@ -110,8 +110,6 @@
     return dispatcher
 
 class BaseType(object):
-    SortRepr = None # placeholders for sorting classes, overloaded in sort.py
-    Sort = None
     _immutable_fields_ = ['native']
 
     def __init__(self, native=True):
@@ -123,7 +121,6 @@
     def malloc(self, size):
         return alloc_raw_storage(size, track_allocation=False, zero=True)
 
-
 class Primitive(object):
     _mixin_ = True
 
@@ -306,7 +303,7 @@
 
 class Bool(BaseType, Primitive):
     T = lltype.Bool
-    BoxType = interp_boxes.W_BoolBox
+    BoxType = boxes.W_BoolBox
     format_code = "?"
 
     True = BoxType(True)
@@ -540,32 +537,32 @@
 
 class Int8(BaseType, Integer):
     T = rffi.SIGNEDCHAR
-    BoxType = interp_boxes.W_Int8Box
+    BoxType = boxes.W_Int8Box
     format_code = "b"
 
 class UInt8(BaseType, Integer):
     T = rffi.UCHAR
-    BoxType = interp_boxes.W_UInt8Box
+    BoxType = boxes.W_UInt8Box
     format_code = "B"
 
 class Int16(BaseType, Integer):
     T = rffi.SHORT
-    BoxType = interp_boxes.W_Int16Box
+    BoxType = boxes.W_Int16Box
     format_code = "h"
 
 class UInt16(BaseType, Integer):
     T = rffi.USHORT
-    BoxType = interp_boxes.W_UInt16Box
+    BoxType = boxes.W_UInt16Box
     format_code = "H"
 
 class Int32(BaseType, Integer):
     T = rffi.INT
-    BoxType = interp_boxes.W_Int32Box
+    BoxType = boxes.W_Int32Box
     format_code = "i"
 
 class UInt32(BaseType, Integer):
     T = rffi.UINT
-    BoxType = interp_boxes.W_UInt32Box
+    BoxType = boxes.W_UInt32Box
     format_code = "I"
 
 def _int64_coerce(self, space, w_item):
@@ -583,7 +580,7 @@
 
 class Int64(BaseType, Integer):
     T = rffi.LONGLONG
-    BoxType = interp_boxes.W_Int64Box
+    BoxType = boxes.W_Int64Box
     format_code = "q"
 
     if LONG_BIT == 32:
@@ -604,14 +601,14 @@
 
 class UInt64(BaseType, Integer):
     T = rffi.ULONGLONG
-    BoxType = interp_boxes.W_UInt64Box
+    BoxType = boxes.W_UInt64Box
     format_code = "Q"
 
     _coerce = func_with_new_name(_uint64_coerce, '_coerce')
 
 class Long(BaseType, Integer):
     T = rffi.LONG
-    BoxType = interp_boxes.W_LongBox
+    BoxType = boxes.W_LongBox
     format_code = "l"
 
 def _ulong_coerce(self, space, w_item):
@@ -629,7 +626,7 @@
 
 class ULong(BaseType, Integer):
     T = rffi.ULONG
-    BoxType = interp_boxes.W_ULongBox
+    BoxType = boxes.W_ULongBox
     format_code = "L"
 
     _coerce = func_with_new_name(_ulong_coerce, '_coerce')
@@ -963,7 +960,7 @@
 class Float16(BaseType, Float):
     _STORAGE_T = rffi.USHORT
     T = rffi.SHORT
-    BoxType = interp_boxes.W_Float16Box
+    BoxType = boxes.W_Float16Box
 
     @specialize.argtype(1)
     def box(self, value):
@@ -1003,12 +1000,12 @@
 
 class Float32(BaseType, Float):
     T = rffi.FLOAT
-    BoxType = interp_boxes.W_Float32Box
+    BoxType = boxes.W_Float32Box
     format_code = "f"
 
 class Float64(BaseType, Float):
     T = rffi.DOUBLE
-    BoxType = interp_boxes.W_Float64Box
+    BoxType = boxes.W_Float64Box
     format_code = "d"
 
 class ComplexFloating(object):
@@ -1572,32 +1569,32 @@
 
 class Complex64(ComplexFloating, BaseType):
     T = rffi.FLOAT
-    BoxType = interp_boxes.W_Complex64Box
-    ComponentBoxType = interp_boxes.W_Float32Box
+    BoxType = boxes.W_Complex64Box
+    ComponentBoxType = boxes.W_Float32Box
 
 class Complex128(ComplexFloating, BaseType):
     T = rffi.DOUBLE
-    BoxType = interp_boxes.W_Complex128Box
-    ComponentBoxType = interp_boxes.W_Float64Box
+    BoxType = boxes.W_Complex128Box
+    ComponentBoxType = boxes.W_Float64Box
 
-if interp_boxes.long_double_size == 8:
+if boxes.long_double_size == 8:
     class FloatLong(BaseType, Float):
         T = rffi.DOUBLE
-        BoxType = interp_boxes.W_FloatLongBox
+        BoxType = boxes.W_FloatLongBox
         format_code = "d"
 
     class ComplexLong(ComplexFloating, BaseType):
         T = rffi.DOUBLE
-        BoxType = interp_boxes.W_ComplexLongBox
-        ComponentBoxType = interp_boxes.W_FloatLongBox
+        BoxType = boxes.W_ComplexLongBox
+        ComponentBoxType = boxes.W_FloatLongBox
 
-elif interp_boxes.long_double_size in (12, 16):
+elif boxes.long_double_size in (12, 16):
     class FloatLong(BaseType, Float):
         T = rffi.LONGDOUBLE
-        BoxType = interp_boxes.W_FloatLongBox
+        BoxType = boxes.W_FloatLongBox
 
         def runpack_str(self, space, s):
-            assert len(s) == interp_boxes.long_double_size
+            assert len(s) == boxes.long_double_size
             fval = self.box(unpack_float80(s, native_is_bigendian))
             if not self.native:
                 fval = self.byteswap(fval)
@@ -1611,8 +1608,8 @@
 
     class ComplexLong(ComplexFloating, BaseType):
         T = rffi.LONGDOUBLE
-        BoxType = interp_boxes.W_ComplexLongBox
-        ComponentBoxType = interp_boxes.W_FloatLongBox
+        BoxType = boxes.W_ComplexLongBox
+        ComponentBoxType = boxes.W_FloatLongBox
 
 class FlexibleType(BaseType):
     def get_element_size(self):
@@ -1621,7 +1618,7 @@
     @jit.unroll_safe
     def to_str(self, item):
         builder = StringBuilder()
-        assert isinstance(item, interp_boxes.W_FlexibleBox)
+        assert isinstance(item, boxes.W_FlexibleBox)
         i = item.ofs
         end = i + item.dtype.elsize
         while i < end:
@@ -1654,7 +1651,7 @@
 
     @jit.unroll_safe
     def coerce(self, space, dtype, w_item):
-        if isinstance(w_item, interp_boxes.W_StringBox):
+        if isinstance(w_item, boxes.W_StringBox):
             return w_item
         if w_item is None:
             w_item = space.wrap('')
@@ -1665,23 +1662,23 @@
             arr.storage[i] = arg[i]
         for j in range(j, dtype.elsize):
             arr.storage[j] = '\x00'
-        return interp_boxes.W_StringBox(arr,  0, arr.dtype)
+        return boxes.W_StringBox(arr,  0, arr.dtype)
 
     def store(self, arr, i, offset, box):
-        assert isinstance(box, interp_boxes.W_StringBox)
+        assert isinstance(box, boxes.W_StringBox)
         size = min(arr.dtype.elsize - offset, box.arr.size - box.ofs)
         return self._store(arr.storage, i, offset, box, size)
 
     @jit.unroll_safe
     def _store(self, storage, i, offset, box, size):
-        assert isinstance(box, interp_boxes.W_StringBox)
+        assert isinstance(box, boxes.W_StringBox)
         for k in range(size):
             storage[k + offset + i] = box.arr.storage[k + box.ofs]
 
     def read(self, arr, i, offset, dtype=None):
         if dtype is None:
             dtype = arr.dtype
-        return interp_boxes.W_StringBox(arr, i + offset, dtype)
+        return boxes.W_StringBox(arr, i + offset, dtype)
 
     def str_format(self, item):
         builder = StringBuilder()
@@ -1746,7 +1743,7 @@
 
     @jit.unroll_safe
     def coerce(self, space, dtype, w_item):
-        if isinstance(w_item, interp_boxes.W_UnicodeBox):
+        if isinstance(w_item, boxes.W_UnicodeBox):
             return w_item
         raise OperationError(space.w_NotImplementedError, space.wrap(
             "coerce (probably from set_item) not implemented for unicode type"))
@@ -1756,7 +1753,7 @@
 
     def _coerce(self, space, arr, ofs, dtype, w_items, shape):
         # TODO: Make sure the shape and the array match
-        from interp_dtype import W_Dtype
+        from pypy.module.micronumpy.descriptor import W_Dtype
         if w_items is not None:
             items_w = space.fixedview(w_items)
         else:
@@ -1781,12 +1778,12 @@
     def coerce(self, space, dtype, w_items):
         arr = VoidBoxStorage(dtype.elsize, dtype)
         self._coerce(space, arr, 0, dtype, w_items, dtype.shape)
-        return interp_boxes.W_VoidBox(arr, 0, dtype)
+        return boxes.W_VoidBox(arr, 0, dtype)
 
     @jit.unroll_safe
     def store(self, arr, i, ofs, box):
         assert i == 0
-        assert isinstance(box, interp_boxes.W_VoidBox)
+        assert isinstance(box, boxes.W_VoidBox)
         assert box.dtype is box.arr.dtype
         for k in range(box.arr.dtype.elsize):
             arr.storage[k + ofs] = box.arr.storage[k + box.ofs]
@@ -1805,11 +1802,11 @@
     def read(self, arr, i, offset, dtype=None):
         if dtype is None:
             dtype = arr.dtype
-        return interp_boxes.W_VoidBox(arr, i + offset, dtype)
+        return boxes.W_VoidBox(arr, i + offset, dtype)
 
     @jit.unroll_safe
     def str_format(self, box):
-        assert isinstance(box, interp_boxes.W_VoidBox)
+        assert isinstance(box, boxes.W_VoidBox)
         arr = self.readarray(box.arr, box.ofs, 0, box.dtype)
         return arr.dump_data(prefix='', suffix='')
 
@@ -1818,7 +1815,7 @@
         "Void arrays return a buffer object for item(),
          unless fields are defined, in which case a tuple is returned."
         '''
-        assert isinstance(item, interp_boxes.W_VoidBox)
+        assert isinstance(item, boxes.W_VoidBox)
         dt = item.arr.dtype
         ret_unwrapped = []
         for name in dt.names:
@@ -1827,7 +1824,7 @@
                 read_val = dtype.itemtype.readarray(item.arr, ofs, 0, dtype)
             else:
                 read_val = dtype.itemtype.read(item.arr, ofs, 0, dtype)
-            if isinstance (read_val, interp_boxes.W_StringBox):
+            if isinstance (read_val, boxes.W_StringBox):
                 # StringType returns a str
                 read_val = space.wrap(dtype.itemtype.to_str(read_val))
             ret_unwrapped = ret_unwrapped + [read_val,]
@@ -1842,12 +1839,12 @@
     def read(self, arr, i, offset, dtype=None):
         if dtype is None:
             dtype = arr.dtype
-        return interp_boxes.W_VoidBox(arr, i + offset, dtype)
+        return boxes.W_VoidBox(arr, i + offset, dtype)
 
     @jit.unroll_safe
     def coerce(self, space, dtype, w_item):
         from pypy.module.micronumpy.base import W_NDimArray
-        if isinstance(w_item, interp_boxes.W_VoidBox):
+        if isinstance(w_item, boxes.W_VoidBox):
             return w_item
         if w_item is not None:
             if space.isinstance_w(w_item, space.w_tuple):
@@ -1871,14 +1868,14 @@
             except IndexError:
                 w_box = itemtype.coerce(space, subdtype, None)
             itemtype.store(arr, 0, ofs, w_box)
-        return interp_boxes.W_VoidBox(arr, 0, dtype)
+        return boxes.W_VoidBox(arr, 0, dtype)
 
     def runpack_str(self, space, s):
         raise oefmt(space.w_NotImplementedError,
                     "fromstring not implemented for record types")
 
     def store(self, arr, i, ofs, box):
-        assert isinstance(box, interp_boxes.W_VoidBox)
+        assert isinstance(box, boxes.W_VoidBox)
         self._store(arr.storage, i, ofs, box, box.dtype.elsize)
 
     @jit.unroll_safe
@@ -1887,7 +1884,7 @@
             storage[k + i + ofs] = box.arr.storage[k + box.ofs]
 
     def fill(self, storage, width, box, start, stop, offset):
-        assert isinstance(box, interp_boxes.W_VoidBox)
+        assert isinstance(box, boxes.W_VoidBox)
         assert width == box.dtype.elsize
         for i in xrange(start, stop, width):
             self._store(storage, i, offset, box, width)
@@ -1897,7 +1894,7 @@
         return w_v
 
     def to_builtin_type(self, space, box):
-        assert isinstance(box, interp_boxes.W_VoidBox)
+        assert isinstance(box, boxes.W_VoidBox)
         items = []
         dtype = box.dtype
         for name in dtype.names:
@@ -1909,7 +1906,7 @@
 
     @jit.unroll_safe
     def str_format(self, box):
-        assert isinstance(box, interp_boxes.W_VoidBox)
+        assert isinstance(box, boxes.W_VoidBox)
         pieces = ["("]
         first = True
         for name in box.dtype.names:
@@ -1925,8 +1922,8 @@
         return "".join(pieces)
 
     def eq(self, v1, v2):
-        assert isinstance(v1, interp_boxes.W_VoidBox)
-        assert isinstance(v2, interp_boxes.W_VoidBox)
+        assert isinstance(v1, boxes.W_VoidBox)
+        assert isinstance(v2, boxes.W_VoidBox)
         s1 = v1.dtype.elsize
         s2 = v2.dtype.elsize
         assert s1 == s2
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/ufuncs.py
rename from pypy/module/micronumpy/interp_ufuncs.py
rename to pypy/module/micronumpy/ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -2,11 +2,10 @@
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, GetSetProperty, interp_attrproperty
-from pypy.module.micronumpy import interp_boxes, interp_dtype, loop
+from pypy.module.micronumpy import boxes, descriptor, loop
 from rpython.rlib import jit
-from rpython.rlib.rarithmetic import LONG_BIT
+from rpython.rlib.rarithmetic import LONG_BIT, maxint
 from rpython.tool.sourcetools import func_with_new_name
-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 import constants as NPY
@@ -149,7 +148,7 @@
         array([[ 1,  5],
                [ 9, 13]])
         """
-        from pypy.module.micronumpy.interp_numarray import W_NDimArray
+        from pypy.module.micronumpy.ndarray import W_NDimArray
         if w_axis is None:
             w_axis = space.wrap(0)
         if space.is_none(w_out):
@@ -175,12 +174,19 @@
         if obj.is_scalar():
             return obj.get_scalar_value()
         shapelen = len(obj_shape)
-        axis = unwrap_axis_arg(space, shapelen, w_axis)
+        if space.is_none(w_axis):
+            axis = maxint
+        else:
+            axis = space.int_w(w_axis)
+            if axis < -shapelen or axis >= shapelen:
+                raise oefmt(space.w_ValueError, "'axis' entry is out of bounds")
+            if axis < 0:
+                axis += shapelen
         assert axis >= 0
-        dtype = interp_dtype.decode_w_dtype(space, dtype)
+        dtype = descriptor.decode_w_dtype(space, dtype)
         if dtype is None:
             if self.comparison_func:
-                dtype = interp_dtype.get_dtype_cache(space).w_booldtype
+                dtype = descriptor.get_dtype_cache(space).w_booldtype
             else:
                 dtype = find_unaryop_result_dtype(
                     space, obj.get_dtype(),
@@ -192,8 +198,9 @@
             for i in range(shapelen):
                 if space.is_none(w_axis) or i == axis:
                     if obj_shape[i] == 0:
-                        raise oefmt(space.w_ValueError, "zero-size array to "
-                                    "%s.reduce without identity", self.name)
+                        raise oefmt(space.w_ValueError,
+                            "zero-size array to reduction operation %s "
+                            "which has no identity", self.name)
         if shapelen > 1 and axis < shapelen:
             temp = None
             if cumulative:
@@ -308,14 +315,14 @@
             #    raise oefmt(space.w_TypeError,
             #        "Cannot cast ufunc %s output from dtype('%s') to dtype('%s') with casting rule 'same_kind'", self.name, w_obj.get_dtype().name, res_dtype.name)
         elif self.bool_result:
-            res_dtype = interp_dtype.get_dtype_cache(space).w_booldtype
+            res_dtype = descriptor.get_dtype_cache(space).w_booldtype
         else:
             res_dtype = calc_dtype
             if self.complex_to_float and calc_dtype.is_complex():
                 if calc_dtype.num == NPY.CFLOAT:
-                    res_dtype = interp_dtype.get_dtype_cache(space).w_float32dtype
+                    res_dtype = descriptor.get_dtype_cache(space).w_float32dtype
                 else:
-                    res_dtype = interp_dtype.get_dtype_cache(space).w_float64dtype
+                    res_dtype = descriptor.get_dtype_cache(space).w_float64dtype
         if w_obj.is_scalar():
             w_val = self.func(calc_dtype,
                               w_obj.get_scalar_value().convert_to(space, calc_dtype))
@@ -418,7 +425,7 @@
             out = w_out
             calc_dtype = out.get_dtype()
         if self.comparison_func:
-            res_dtype = interp_dtype.get_dtype_cache(space).w_booldtype
+            res_dtype = descriptor.get_dtype_cache(space).w_booldtype
         else:
             res_dtype = calc_dtype
         if w_lhs.is_scalar() and w_rhs.is_scalar():
@@ -465,7 +472,7 @@
         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):
-        return interp_dtype.get_dtype_cache(space).w_int8dtype
+        return descriptor.get_dtype_cache(space).w_int8dtype
 
     # Everything numeric promotes to complex
     if dt2.is_complex() or dt1.is_complex():
@@ -473,16 +480,16 @@
             dt1, dt2 = dt2, dt1
         if dt2.num == NPY.CFLOAT:
             if dt1.num == NPY.DOUBLE:
-                return interp_dtype.get_dtype_cache(space).w_complex128dtype
+                return descriptor.get_dtype_cache(space).w_complex128dtype
             elif dt1.num == NPY.LONGDOUBLE:
-                return interp_dtype.get_dtype_cache(space).w_complexlongdtype
-            return interp_dtype.get_dtype_cache(space).w_complex64dtype
+                return descriptor.get_dtype_cache(space).w_complexlongdtype
+            return descriptor.get_dtype_cache(space).w_complex64dtype
         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
+                return descriptor.get_dtype_cache(space).w_complexlongdtype
+            return descriptor.get_dtype_cache(space).w_complex128dtype
         elif dt2.num == NPY.CLONGDOUBLE:
-            return interp_dtype.get_dtype_cache(space).w_complexlongdtype
+            return descriptor.get_dtype_cache(space).w_complexlongdtype
         else:
             raise OperationError(space.w_TypeError, space.wrap("Unsupported types"))
 
@@ -497,11 +504,11 @@
     # 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:
-            return interp_dtype.get_dtype_cache(space).w_float32dtype
+            return descriptor.get_dtype_cache(space).w_float32dtype
         if dt2.num == NPY.HALF and dt1.itemtype.get_element_size() >= 4:
-            return interp_dtype.get_dtype_cache(space).w_float64dtype
+            return descriptor.get_dtype_cache(space).w_float64dtype
         if dt2.num == NPY.FLOAT and dt1.itemtype.get_element_size() >= 4:
-            return interp_dtype.get_dtype_cache(space).w_float64dtype
+            return descriptor.get_dtype_cache(space).w_float64dtype
         return dt2
 
     # for now this means mixing signed and unsigned
@@ -527,7 +534,7 @@
     else:
         # increase to the next signed type
         dtypenum = dt2.num + 1
-    newdtype = interp_dtype.get_dtype_cache(space).dtypes_by_num[dtypenum]
+    newdtype = descriptor.get_dtype_cache(space).dtypes_by_num[dtypenum]
 
     if (newdtype.itemtype.get_element_size() > dt2.itemtype.get_element_size() or
             newdtype.kind == NPY.FLOATINGLTR):
@@ -536,7 +543,7 @@
         # we only promoted to long on 32-bit or to longlong on 64-bit
         # this is really for dealing with the Long and Ulong dtypes
         dtypenum += 2
-        return interp_dtype.get_dtype_cache(space).dtypes_by_num[dtypenum]
+        return descriptor.get_dtype_cache(space).dtypes_by_num[dtypenum]
 
 @jit.unroll_safe
 def find_unaryop_result_dtype(space, dt, promote_to_float=False,
@@ -544,34 +551,34 @@
     if promote_to_largest:
         if dt.kind == NPY.GENBOOLLTR or dt.kind == NPY.SIGNEDLTR:
             if dt.elsize * 8 < LONG_BIT:
-                return interp_dtype.get_dtype_cache(space).w_longdtype
+                return descriptor.get_dtype_cache(space).w_longdtype
         elif dt.kind == NPY.UNSIGNEDLTR:
             if dt.elsize * 8 < LONG_BIT:
-                return interp_dtype.get_dtype_cache(space).w_ulongdtype
+                return descriptor.get_dtype_cache(space).w_ulongdtype
         else:
             assert dt.kind == NPY.FLOATINGLTR or dt.kind == NPY.COMPLEXLTR
         return dt
     if promote_bools and (dt.kind == NPY.GENBOOLLTR):
-        return interp_dtype.get_dtype_cache(space).w_int8dtype
+        return descriptor.get_dtype_cache(space).w_int8dtype
     if promote_to_float:
         if dt.kind == NPY.FLOATINGLTR or dt.kind == NPY.COMPLEXLTR:
             return dt
         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:
+            return descriptor.get_dtype_cache(space).w_float64dtype
+        for bytes, dtype in descriptor.get_dtype_cache(space).float_dtypes_by_num_bytes:
             if (dtype.kind == NPY.FLOATINGLTR and
                 dtype.itemtype.get_element_size() > dt.itemtype.get_element_size()):
                 return dtype
     return dt
 
 def find_dtype_for_scalar(space, w_obj, current_guess=None):
-    bool_dtype = interp_dtype.get_dtype_cache(space).w_booldtype
-    long_dtype = interp_dtype.get_dtype_cache(space).w_longdtype
-    int64_dtype = interp_dtype.get_dtype_cache(space).w_int64dtype
-    uint64_dtype = interp_dtype.get_dtype_cache(space).w_uint64dtype
-    complex_dtype = interp_dtype.get_dtype_cache(space).w_complex128dtype
-    float_dtype = interp_dtype.get_dtype_cache(space).w_float64dtype
-    if isinstance(w_obj, interp_boxes.W_GenericBox):
+    bool_dtype = descriptor.get_dtype_cache(space).w_booldtype
+    long_dtype = descriptor.get_dtype_cache(space).w_longdtype
+    int64_dtype = descriptor.get_dtype_cache(space).w_int64dtype
+    uint64_dtype = descriptor.get_dtype_cache(space).w_uint64dtype
+    complex_dtype = descriptor.get_dtype_cache(space).w_complex128dtype
+    float_dtype = descriptor.get_dtype_cache(space).w_float64dtype
+    if isinstance(w_obj, boxes.W_GenericBox):
         dtype = w_obj.get_dtype(space)
         return find_binop_result_dtype(space, dtype, current_guess)
 
@@ -594,11 +601,11 @@
         return complex_dtype
     elif space.isinstance_w(w_obj, space.w_str):
         if current_guess is None:
-            return interp_dtype.variable_dtype(space,
+            return descriptor.variable_dtype(space,
                                                'S%d' % space.len_w(w_obj))
         elif current_guess.num == NPY.STRING:
             if current_guess.elsize < space.len_w(w_obj):
-                return interp_dtype.variable_dtype(space,
+                return descriptor.variable_dtype(space,
                                                    'S%d' % space.len_w(w_obj))
         return current_guess
     raise oefmt(space.w_NotImplementedError,
@@ -607,7 +614,7 @@
 
 def ufunc_dtype_caller(space, ufunc_name, op_name, argcount, comparison_func,
                        bool_result):
-    dtype_cache = interp_dtype.get_dtype_cache(space)
+    dtype_cache = descriptor.get_dtype_cache(space)
     def get_op(dtype):
         try:
             return getattr(dtype.itemtype, op_name)
@@ -743,7 +750,7 @@
         identity = extra_kwargs.get("identity")
         if identity is not None:
             identity = \
-                 interp_dtype.get_dtype_cache(space).w_longdtype.box(identity)
+                 descriptor.get_dtype_cache(space).w_longdtype.box(identity)
         extra_kwargs["identity"] = identity
 
         func = ufunc_dtype_caller(space, ufunc_name, op_name, argcount,


More information about the pypy-commit mailing list