[pypy-commit] pypy cpyext-int: merge default into branch

mattip noreply at buildbot.pypy.org
Mon Nov 4 22:12:02 CET 2013


Author: Matti Picus <matti.picus at gmail.com>
Branch: cpyext-int
Changeset: r67837:152c025075fa
Date: 2013-10-22 21:32 +0300
http://bitbucket.org/pypy/pypy/changeset/152c025075fa/

Log:	merge default into branch

diff too long, truncating to 2000 out of 4446 lines

diff --git a/lib_pypy/numpypy/core/arrayprint.py b/lib_pypy/numpypy/core/arrayprint.py
--- a/lib_pypy/numpypy/core/arrayprint.py
+++ b/lib_pypy/numpypy/core/arrayprint.py
@@ -247,10 +247,11 @@
     formatdict = {'bool' : _boolFormatter,
                   'int' : IntegerFormat(data),
                   'float' : FloatFormat(data, precision, suppress_small),
-                  'longfloat' : LongFloatFormat(precision),
+                  'longfloat' : FloatFormat(data, precision, suppress_small),
                   'complexfloat' : ComplexFormat(data, precision,
                                                  suppress_small),
-                  'longcomplexfloat' : LongComplexFormat(precision),
+                  'longcomplexfloat' : ComplexFormat(data, precision,
+                                                     suppress_small),
                   'datetime' : DatetimeFormat(data),
                   'timedelta' : TimedeltaFormat(data),
                   'numpystr' : repr_format,
diff --git a/lib_pypy/numpypy/core/numerictypes.py b/lib_pypy/numpypy/core/numerictypes.py
--- a/lib_pypy/numpypy/core/numerictypes.py
+++ b/lib_pypy/numpypy/core/numerictypes.py
@@ -395,6 +395,9 @@
                   ('int_', 'long'),
                   ('uint', 'ulong'),
                   ('cfloat', 'cdouble'),
+                  ('longfloat', 'longdouble'),
+                  ('clongfloat', 'clongdouble'),
+                  ('longcomplex', 'clongdouble'),
                   ('bool_', 'bool'),
                   ('unicode_', 'unicode'),
                   ]
diff --git a/lib_pypy/numpypy/lib/__init__.py b/lib_pypy/numpypy/lib/__init__.py
--- a/lib_pypy/numpypy/lib/__init__.py
+++ b/lib_pypy/numpypy/lib/__init__.py
@@ -5,10 +5,12 @@
 from .function_base import *
 from .shape_base import *
 from .twodim_base import *
+from .ufunclike import *
 from .utils import *
 
 __all__ = ['math']
 __all__ += function_base.__all__
 __all__ += shape_base.__all__
 __all__ += twodim_base.__all__
+__all__ += ufunclike.__all__
 __all__ += utils.__all__
diff --git a/lib_pypy/numpypy/lib/ufunclike.py b/lib_pypy/numpypy/lib/ufunclike.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/lib/ufunclike.py
@@ -0,0 +1,177 @@
+"""
+Module of functions that are like ufuncs in acting on arrays and optionally
+storing results in an output array.
+
+"""
+from __future__ import division, absolute_import, print_function
+
+__all__ = ['fix', 'isneginf', 'isposinf']
+
+from ..core import numeric as nx
+
+def fix(x, y=None):
+    """
+    Round to nearest integer towards zero.
+
+    Round an array of floats element-wise to nearest integer towards zero.
+    The rounded values are returned as floats.
+
+    Parameters
+    ----------
+    x : array_like
+        An array of floats to be rounded
+    y : ndarray, optional
+        Output array
+
+    Returns
+    -------
+    out : ndarray of floats
+        The array of rounded numbers
+
+    See Also
+    --------
+    trunc, floor, ceil
+    around : Round to given number of decimals
+
+    Examples
+    --------
+    >>> np.fix(3.14)
+    3.0
+    >>> np.fix(3)
+    3.0
+    >>> np.fix([2.1, 2.9, -2.1, -2.9])
+    array([ 2.,  2., -2., -2.])
+
+    """
+    x = nx.asanyarray(x)
+    y1 = nx.floor(x)
+    y2 = nx.ceil(x)
+    if y is None:
+        y = nx.asanyarray(y1)
+    y[...] = nx.where(x >= 0, y1, y2)
+    return y
+
+def isposinf(x, y=None):
+    """
+    Test element-wise for positive infinity, return result as bool array.
+
+    Parameters
+    ----------
+    x : array_like
+        The input array.
+    y : array_like, optional
+        A boolean array with the same shape as `x` to store the result.
+
+    Returns
+    -------
+    y : ndarray
+        A boolean array with the same dimensions as the input.
+        If second argument is not supplied then a boolean array is returned
+        with values True where the corresponding element of the input is
+        positive infinity and values False where the element of the input is
+        not positive infinity.
+
+        If a second argument is supplied the result is stored there. If the
+        type of that array is a numeric type the result is represented as zeros
+        and ones, if the type is boolean then as False and True.
+        The return value `y` is then a reference to that array.
+
+    See Also
+    --------
+    isinf, isneginf, isfinite, isnan
+
+    Notes
+    -----
+    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
+    (IEEE 754).
+
+    Errors result if the second argument is also supplied when `x` is a
+    scalar input, or if first and second arguments have different shapes.
+
+    Examples
+    --------
+    >>> np.isposinf(np.PINF)
+    array(True, dtype=bool)
+    >>> np.isposinf(np.inf)
+    array(True, dtype=bool)
+    >>> np.isposinf(np.NINF)
+    array(False, dtype=bool)
+    >>> np.isposinf([-np.inf, 0., np.inf])
+    array([False, False,  True], dtype=bool)
+
+    >>> x = np.array([-np.inf, 0., np.inf])
+    >>> y = np.array([2, 2, 2])
+    >>> np.isposinf(x, y)
+    array([0, 0, 1])
+    >>> y
+    array([0, 0, 1])
+
+    """
+    if y is None:
+        x = nx.asarray(x)
+        y = nx.empty(x.shape, dtype=nx.bool_)
+    nx.logical_and(nx.isinf(x), ~nx.signbit(x), y)
+    return y
+
+def isneginf(x, y=None):
+    """
+    Test element-wise for negative infinity, return result as bool array.
+
+    Parameters
+    ----------
+    x : array_like
+        The input array.
+    y : array_like, optional
+        A boolean array with the same shape and type as `x` to store the
+        result.
+
+    Returns
+    -------
+    y : ndarray
+        A boolean array with the same dimensions as the input.
+        If second argument is not supplied then a numpy boolean array is
+        returned with values True where the corresponding element of the
+        input is negative infinity and values False where the element of
+        the input is not negative infinity.
+
+        If a second argument is supplied the result is stored there. If the
+        type of that array is a numeric type the result is represented as
+        zeros and ones, if the type is boolean then as False and True. The
+        return value `y` is then a reference to that array.
+
+    See Also
+    --------
+    isinf, isposinf, isnan, isfinite
+
+    Notes
+    -----
+    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
+    (IEEE 754).
+
+    Errors result if the second argument is also supplied when x is a scalar
+    input, or if first and second arguments have different shapes.
+
+    Examples
+    --------
+    >>> np.isneginf(np.NINF)
+    array(True, dtype=bool)
+    >>> np.isneginf(np.inf)
+    array(False, dtype=bool)
+    >>> np.isneginf(np.PINF)
+    array(False, dtype=bool)
+    >>> np.isneginf([-np.inf, 0., np.inf])
+    array([ True, False, False], dtype=bool)
+
+    >>> x = np.array([-np.inf, 0., np.inf])
+    >>> y = np.array([2, 2, 2])
+    >>> np.isneginf(x, y)
+    array([1, 0, 0])
+    >>> y
+    array([1, 0, 0])
+
+    """
+    if y is None:
+        x = nx.asarray(x)
+        y = nx.empty(x.shape, dtype=nx.bool_)
+    nx.logical_and(nx.isinf(x), nx.signbit(x), y)
+    return y
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -109,4 +109,5 @@
 .. branch: file-support-in-rpython
 make open() and friends rpython
 
-
+.. branch: incremental-gc
+Added the new incminimark GC which performs GC in incremental steps
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -239,6 +239,18 @@
         # _____ this code is here to support testing only _____
         return self
 
+    def unpackiterable_int(self, space):
+        lst = space.listview_int(self)
+        if lst:
+            return lst[:]
+        return None
+
+    def unpackiterable_float(self, space):
+        lst = space.listview_float(self)
+        if lst:
+            return lst[:]
+        return None
+
 
 class W_InterpIterable(W_Root):
     def __init__(self, space, w_iterable):
@@ -838,6 +850,22 @@
         return self._unpackiterable_known_length_jitlook(w_iterator,
                                                          expected_length)
 
+
+    def unpackiterable_int(self, w_obj):
+        """
+        Return a RPython list of unwrapped ints out of w_obj. The list is
+        guaranteed to be acopy of the actual data contained in w_obj, so you
+        can freely modify it. It might return None if not supported.
+        """
+        return w_obj.unpackiterable_int(self)
+
+    def unpackiterable_float(self, w_obj):
+        """
+        Same as unpackiterable_int, but for floats.
+        """
+        return w_obj.unpackiterable_float(self)
+
+
     def length_hint(self, w_obj, default):
         """Return the length of an object, consulting its __length_hint__
         method if necessary.
@@ -895,6 +923,20 @@
         """
         return None
 
+    def listview_int(self, w_list):
+        """ Return a list of unwrapped int out of a list of int. If the
+        argument is not a list or does not contain only int, return None.
+        May return None anyway.
+        """
+        return None
+
+    def listview_float(self, w_list):
+        """ Return a list of unwrapped float out of a list of float. If the
+        argument is not a list or does not contain only float, return None.
+        May return None anyway.
+        """
+        return None
+
     def view_as_kwargs(self, w_dict):
         """ if w_dict is a kwargs-dict, return two lists, one of unwrapped
         strings and one of wrapped values. otherwise return (None, None)
diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -282,6 +282,12 @@
     def iter(self):
         return self.ctype.iter(self)
 
+    def unpackiterable_int(self, space):
+        return self.ctype.aslist_int(self)
+
+    def unpackiterable_float(self, space):
+        return self.ctype.aslist_float(self)
+
     @specialize.argtype(1)
     def write_raw_signed_data(self, source):
         misc.write_raw_signed_data(self._cdata, source, self.ctype.size)
diff --git a/pypy/module/_cffi_backend/ctypearray.py b/pypy/module/_cffi_backend/ctypearray.py
--- a/pypy/module/_cffi_backend/ctypearray.py
+++ b/pypy/module/_cffi_backend/ctypearray.py
@@ -105,6 +105,26 @@
     def iter(self, cdata):
         return W_CDataIter(self.space, self.ctitem, cdata)
 
+    def aslist_int(self, cdata):
+        from rpython.rlib.rarray import populate_list_from_raw_array
+        if self.ctitem.is_long():
+            res = []
+            buf = rffi.cast(rffi.LONGP, cdata._cdata)
+            length = cdata.get_array_length()
+            populate_list_from_raw_array(res, buf, length)
+            return res
+        return None
+
+    def aslist_float(self, cdata):
+        from rpython.rlib.rarray import populate_list_from_raw_array
+        if self.ctitem.is_double():
+            res = []
+            buf = rffi.cast(rffi.DOUBLEP, cdata._cdata)
+            length = cdata.get_array_length()
+            populate_list_from_raw_array(res, buf, length)
+            return res
+        return None
+
     def get_vararg_type(self):
         return self.ctptr
 
diff --git a/pypy/module/_cffi_backend/ctypeobj.py b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -43,6 +43,12 @@
     def is_unichar_ptr_or_array(self):
         return False
 
+    def is_long(self):
+        return False
+
+    def is_double(self):
+        return False
+
     def newp(self, w_init):
         space = self.space
         raise operationerrfmt(space.w_TypeError,
@@ -163,6 +169,9 @@
                               "cdata '%s' does not support iteration",
                               self.name)
 
+    def unpackiterable_int(self, cdata):
+        return None
+
     def get_vararg_type(self):
         return self
 
diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -85,7 +85,6 @@
             return self.space.wrap(s)
         return W_CType.string(self, cdataobj, maxlen)
 
-
 class W_CTypePrimitiveCharOrUniChar(W_CTypePrimitive):
     _attrs_ = []
     is_primitive_integer = True
@@ -171,6 +170,9 @@
             self.vmin = r_uint(-1) << (sh - 1)
             self.vrangemax = (r_uint(1) << sh) - 1
 
+    def is_long(self):
+        return self.size == rffi.sizeof(lltype.Signed)
+
     def cast_to_int(self, cdata):
         return self.convert_to_object(cdata)
 
@@ -274,6 +276,9 @@
 class W_CTypePrimitiveFloat(W_CTypePrimitive):
     _attrs_ = []
 
+    def is_double(self):
+        return self.size == rffi.sizeof(lltype.Float)
+
     def cast(self, w_ob):
         space = self.space
         if isinstance(w_ob, cdataobj.W_CData):
diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -42,6 +42,12 @@
     def is_char_or_unichar_ptr_or_array(self):
         return isinstance(self.ctitem, ctypeprim.W_CTypePrimitiveCharOrUniChar)
 
+    def aslist_int(self, cdata):
+        return None
+
+    def aslist_float(self, cdata):
+        return None
+
     def cast(self, w_ob):
         # cast to a pointer, to a funcptr, or to an array.
         # Note that casting to an array is an extension to the C language,
@@ -58,19 +64,45 @@
             value = rffi.cast(rffi.CCHARP, value)
         return cdataobj.W_CData(space, value, self)
 
+    def _convert_array_from_list_strategy_maybe(self, cdata, w_ob):
+        from rpython.rlib.rarray import copy_list_to_raw_array
+        int_list = self.space.listview_int(w_ob)
+        float_list = self.space.listview_float(w_ob)
+        #
+        if self.ctitem.is_long() and int_list is not None:
+            cdata = rffi.cast(rffi.LONGP, cdata)
+            copy_list_to_raw_array(int_list, cdata)
+            return True
+        #
+        if self.ctitem.is_double() and float_list is not None:
+            cdata = rffi.cast(rffi.DOUBLEP, cdata)
+            copy_list_to_raw_array(float_list, cdata)
+            return True
+        #
+        return False
+
+    def _convert_array_from_listview(self, cdata, w_ob):
+        space = self.space
+        lst_w = space.listview(w_ob)
+        if self.length >= 0 and len(lst_w) > self.length:
+            raise operationerrfmt(space.w_IndexError,
+                "too many initializers for '%s' (got %d)",
+                                  self.name, len(lst_w))
+        ctitem = self.ctitem
+        for i in range(len(lst_w)):
+            ctitem.convert_from_object(cdata, lst_w[i])
+            cdata = rffi.ptradd(cdata, ctitem.size)
+
     def convert_array_from_object(self, cdata, w_ob):
         space = self.space
+        if self._convert_array_from_list_strategy_maybe(cdata, w_ob):
+            # the fast path worked, we are done now
+            return
+        #
+        # continue with the slow path
         if (space.isinstance_w(w_ob, space.w_list) or
             space.isinstance_w(w_ob, space.w_tuple)):
-            lst_w = space.listview(w_ob)
-            if self.length >= 0 and len(lst_w) > self.length:
-                raise operationerrfmt(space.w_IndexError,
-                    "too many initializers for '%s' (got %d)",
-                                      self.name, len(lst_w))
-            ctitem = self.ctitem
-            for i in range(len(lst_w)):
-                ctitem.convert_from_object(cdata, lst_w[i])
-                cdata = rffi.ptradd(cdata, ctitem.size)
+            self._convert_array_from_listview(cdata, w_ob)
         elif (self.can_cast_anything or
               (self.ctitem.is_primitive_integer and
                self.ctitem.size == rffi.sizeof(lltype.Char))):
diff --git a/pypy/module/_cffi_backend/test/test_fastpath.py b/pypy/module/_cffi_backend/test/test_fastpath.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_cffi_backend/test/test_fastpath.py
@@ -0,0 +1,100 @@
+# side-effect: FORMAT_LONGDOUBLE must be built before test_checkmodule()
+from pypy.module._cffi_backend import misc
+from pypy.module._cffi_backend.ctypeptr import W_CTypePtrOrArray
+
+class AppTest_fast_path_from_list(object):
+    spaceconfig = dict(usemodules=('_cffi_backend', 'cStringIO'))
+
+    def setup_method(self, meth):
+        def forbidden(self, *args):
+            assert False, 'The slow path is forbidden'
+        self._original = W_CTypePtrOrArray._convert_array_from_listview.im_func
+        W_CTypePtrOrArray._convert_array_from_listview = forbidden
+
+    def teardown_method(self, meth):
+        W_CTypePtrOrArray._convert_array_from_listview = self._original
+
+    def test_fast_init_from_list(self):
+        import _cffi_backend
+        LONG = _cffi_backend.new_primitive_type('long')
+        P_LONG = _cffi_backend.new_pointer_type(LONG)
+        LONG_ARRAY = _cffi_backend.new_array_type(P_LONG, None)
+        buf = _cffi_backend.newp(LONG_ARRAY, [1, 2, 3])
+        assert buf[0] == 1
+        assert buf[1] == 2
+        assert buf[2] == 3
+
+    def test_fast_init_from_list_float(self):
+        import _cffi_backend
+        DOUBLE = _cffi_backend.new_primitive_type('double')
+        P_DOUBLE = _cffi_backend.new_pointer_type(DOUBLE)
+        DOUBLE_ARRAY = _cffi_backend.new_array_type(P_DOUBLE, None)
+        buf = _cffi_backend.newp(DOUBLE_ARRAY, [1.1, 2.2, 3.3])
+        assert buf[0] == 1.1
+        assert buf[1] == 2.2
+        assert buf[2] == 3.3
+
+
+class AppTest_fast_path_to_list(object):
+    spaceconfig = dict(usemodules=('_cffi_backend', 'cStringIO'))
+
+    def setup_method(self, meth):
+        from pypy.interpreter import gateway
+        from rpython.rlib import rarray
+        #
+        self.count = 0
+        def get_count(*args):
+            return self.space.wrap(self.count)
+        self.w_get_count = self.space.wrap(gateway.interp2app(get_count))
+        #
+        original = rarray.populate_list_from_raw_array
+        def populate_list_from_raw_array(*args):
+            self.count += 1
+            return original(*args)
+        self._original = original
+        rarray.populate_list_from_raw_array = populate_list_from_raw_array
+        #
+        self.w_runappdirect = self.space.wrap(self.runappdirect)
+
+
+    def teardown_method(self, meth):
+        from rpython.rlib import rarray
+        rarray.populate_list_from_raw_array = self._original
+
+    def test_list_int(self):
+        import _cffi_backend
+        LONG = _cffi_backend.new_primitive_type('long')
+        P_LONG = _cffi_backend.new_pointer_type(LONG)
+        LONG_ARRAY = _cffi_backend.new_array_type(P_LONG, 3)
+        buf = _cffi_backend.newp(LONG_ARRAY)
+        buf[0] = 1
+        buf[1] = 2
+        buf[2] = 3
+        lst = list(buf)
+        assert lst == [1, 2, 3]
+        if not self.runappdirect:
+            assert self.get_count() == 1
+
+    def test_TypeError_if_no_length(self):
+        import _cffi_backend
+        LONG = _cffi_backend.new_primitive_type('long')
+        P_LONG = _cffi_backend.new_pointer_type(LONG)
+        LONG_ARRAY = _cffi_backend.new_array_type(P_LONG, 3)
+        buf = _cffi_backend.newp(LONG_ARRAY)
+        pbuf = _cffi_backend.cast(P_LONG, buf)
+        raises(TypeError, "list(pbuf)")
+
+
+    def test_list_float(self):
+        import _cffi_backend
+        DOUBLE = _cffi_backend.new_primitive_type('double')
+        P_DOUBLE = _cffi_backend.new_pointer_type(DOUBLE)
+        DOUBLE_ARRAY = _cffi_backend.new_array_type(P_DOUBLE, 3)
+        buf = _cffi_backend.newp(DOUBLE_ARRAY)
+        buf[0] = 1.1
+        buf[1] = 2.2
+        buf[2] = 3.3
+        lst = list(buf)
+        assert lst == [1.1, 2.2, 3.3]
+        if not self.runappdirect:
+            assert self.get_count() == 1
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
@@ -1,5 +1,4 @@
 from pypy.interpreter.mixedmodule import MixedModule
-from pypy.module.micronumpy.interp_boxes import long_double_size, ENABLED_LONG_DOUBLE
 
 
 class MultiArrayModule(MixedModule):
@@ -64,6 +63,7 @@
         ("less_equal", "less_equal"),
         ("maximum", "maximum"),
         ("minimum", "minimum"),
+        ("mod", "mod"),
         ("multiply", "multiply"),
         ("negative", "negative"),
         ("not_equal", "not_equal"),
@@ -91,8 +91,6 @@
         ('invert', 'invert'),
         ('isnan', 'isnan'),
         ('isinf', 'isinf'),
-        ('isneginf', 'isneginf'),
-        ('isposinf', 'isposinf'),
         ('isfinite', 'isfinite'),
         ('logical_and', 'logical_and'),
         ('logical_xor', 'logical_xor'),
diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -102,13 +102,10 @@
             dtype =  self.dtype.float_type
             return SliceArray(self.start + dtype.get_size(), strides,
                     backstrides, self.get_shape(), self, orig_array, dtype=dtype)
-        if self.dtype.is_flexible_type():
-            # numpy returns self for self.imag
-            return SliceArray(self.start, strides, backstrides,
-                    self.get_shape(), self, orig_array)
         impl = NonWritableArray(self.get_shape(), self.dtype, self.order, strides,
                              backstrides)
-        impl.fill(self.dtype.box(0))
+        if not self.dtype.is_flexible_type():
+            impl.fill(self.dtype.box(0))
         return impl
 
     def set_imag(self, space, orig_array, w_value):
@@ -129,7 +126,8 @@
                 idx = self.get_shape()[i] + idx
             if idx < 0 or idx >= self.get_shape()[i]:
                 raise operationerrfmt(space.w_IndexError,
-                      "index (%d) out of range (0<=index<%d", i, self.get_shape()[i],
+                      "index %d is out of bounds for axis %d with size %d",
+                      idx, i, self.get_shape()[i],
                 )
             item += idx * strides[i]
         return item
@@ -145,7 +143,8 @@
                 idx = shape[i] + idx
             if idx < 0 or idx >= shape[i]:
                 raise operationerrfmt(space.w_IndexError,
-                      "index (%d) out of range (0<=index<%d", i, shape[i],
+                      "index %d is out of bounds for axis %d with size %d",
+                      idx, i, self.get_shape()[i],
                 )
             item += idx * strides[i]
         return item
@@ -380,8 +379,8 @@
 
 class NonWritableArray(ConcreteArray):
     def descr_setitem(self, space, orig_array, w_index, w_value):
-        raise OperationError(space.w_RuntimeError, space.wrap(
-            "array is not writable"))
+        raise OperationError(space.w_ValueError, space.wrap(
+            "assignment destination is read-only"))
 
 
 class SliceArray(BaseConcreteArray):
diff --git a/pypy/module/micronumpy/arrayimpl/sort.py b/pypy/module/micronumpy/arrayimpl/sort.py
--- a/pypy/module/micronumpy/arrayimpl/sort.py
+++ b/pypy/module/micronumpy/arrayimpl/sort.py
@@ -8,7 +8,7 @@
 from rpython.rlib.rawstorage import raw_storage_getitem, raw_storage_setitem, \
         free_raw_storage, alloc_raw_storage
 from rpython.rlib.unroll import unrolling_iterable
-from rpython.rlib.rarithmetic import intmask
+from rpython.rlib.rarithmetic import widen
 from rpython.rlib.objectmodel import specialize
 from pypy.interpreter.error import OperationError
 from pypy.module.micronumpy.base import W_NDimArray
@@ -43,7 +43,7 @@
                                     + self.start + step * i)
                     v.append(_v)
             if comp_type == 'int':
-                v = intmask(v)
+                v = widen(v)
             elif comp_type == 'float':
                 v = float(v)
             elif comp_type == 'complex':
@@ -100,10 +100,15 @@
     if count < 2:
         def arg_lt(a, b):
             # Does numpy do <= ?
-            return a[0] < b[0]
+            return a[0] < b[0] or b[0] != b[0] and a[0] == a[0]
     else:
         def arg_lt(a, b):
             for i in range(count):
+                if b[0][i] != b[0][i] and a[0][i] == a[0][i]:
+                    return True
+                elif b[0][i] == b[0][i] and a[0][i] != a[0][i]:
+                    return False
+            for i in range(count):
                 if a[0][i] < b[0][i]:
                     return True
                 elif a[0][i] > b[0][i]:
@@ -200,7 +205,7 @@
                                     + self.start + step * i)
                     v.append(_v)
             if comp_type == 'int':
-                v = intmask(v)
+                v = widen(v)
             elif comp_type == 'float':
                 v = float(v)
             elif comp_type == 'complex':
@@ -318,7 +323,8 @@
 
 all_types = (types.all_float_types + types.all_complex_types +
              types.all_int_types)
-all_types = [i for i in all_types if not '_mixin_' in i[0].__dict__]
+all_types = [i for i in all_types if not '_mixin_' in i[0].__dict__ and
+                                     not issubclass(i[0], types.BaseFloat16)]
 all_types = unrolling_iterable(all_types)
 
 class ArgSortCache(object):
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,4 +1,21 @@
+from pypy.interpreter.error import OperationError
 
-MODE_WRAP, MODE_RAISE, MODE_CLIP = range(3)
+MODE_CLIP, MODE_WRAP, MODE_RAISE = range(3)
 
-MODES = {'wrap': MODE_WRAP, 'raise': MODE_RAISE, 'clip': MODE_CLIP}
+def clipmode_converter(space, w_mode):
+    if space.is_none(w_mode):
+        return MODE_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 MODE_CLIP
+        if mode.startswith('W') or mode.startswith('w'):
+            return MODE_WRAP
+        if mode.startswith('R') or mode.startswith('r'):
+            return MODE_RAISE
+    elif space.isinstance_w(w_mode, space.w_int):
+        mode = space.int_w(w_mode)
+        if MODE_CLIP <= mode <= MODE_RAISE:
+            return mode
+    raise OperationError(space.w_TypeError,
+                         space.wrap("clipmode 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
@@ -1,10 +1,9 @@
-
 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, interp_dtype, interp_ufuncs, constants
 from pypy.module.micronumpy.iter import Chunk, Chunks
 from pypy.module.micronumpy.strides import shape_agreement,\
      shape_agreement_multiple
-from pypy.module.micronumpy.constants import MODES
+from pypy.module.micronumpy.constants import clipmode_converter
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.gateway import unwrap_spec
 
@@ -118,12 +117,12 @@
                 shape[i] += axis_size
         a_dt = arr.get_dtype()
         if dtype.is_record_type() and a_dt.is_record_type():
-            #Record types must match
+            # Record types must match
             for f in dtype.fields:
                 if f not in a_dt.fields or \
                              dtype.fields[f] != a_dt.fields[f]:
                     raise OperationError(space.w_TypeError,
-                               space.wrap("record type mismatch"))
+                               space.wrap("invalid type promotion"))
         elif dtype.is_record_type() or a_dt.is_record_type():
             raise OperationError(space.w_TypeError,
                         space.wrap("invalid type promotion"))
@@ -171,8 +170,7 @@
 def count_nonzero(space, w_obj):
     return space.wrap(loop.count_all_true(convert_to_array(space, w_obj)))
 
- at unwrap_spec(mode=str)
-def choose(space, w_arr, w_choices, w_out, mode):
+def choose(space, w_arr, w_choices, w_out, w_mode):
     arr = convert_to_array(space, w_arr)
     choices = [convert_to_array(space, w_item) for w_item
                in space.listview(w_choices)]
@@ -187,23 +185,16 @@
     shape = shape_agreement_multiple(space, choices + [w_out])
     out = interp_dtype.dtype_agreement(space, choices, shape, w_out)
     dtype = out.get_dtype()
-    if mode not in MODES:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("mode %s not known" % (mode,)))
-    loop.choose(space, arr, choices, shape, dtype, out, MODES[mode])
+    mode = clipmode_converter(space, w_mode)
+    loop.choose(space, arr, choices, shape, dtype, out, mode)
     return out
 
-
- at unwrap_spec(mode=str)
-def put(space, w_arr, w_indices, w_values, mode='raise'):
-    from pypy.module.micronumpy import constants
+def put(space, w_arr, w_indices, w_values, w_mode):
     from pypy.module.micronumpy.support import int_w
 
     arr = convert_to_array(space, w_arr)
+    mode = clipmode_converter(space, w_mode)
 
-    if mode not in constants.MODES:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("mode %s not known" % (mode,)))
     if not w_indices:
         raise OperationError(space.w_ValueError,
                              space.wrap("indice list cannot be empty"))
@@ -228,13 +219,13 @@
         index = int_w(space, idx)
 
         if index < 0 or index >= arr.get_size():
-            if constants.MODES[mode] == constants.MODE_RAISE:
-                raise OperationError(space.w_ValueError, space.wrap(
-                    "invalid entry in choice array"))
-            elif constants.MODES[mode] == constants.MODE_WRAP:
+            if mode == constants.MODE_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 == constants.MODE_WRAP:
                 index = index % arr.get_size()
             else:
-                assert constants.MODES[mode] == constants.MODE_CLIP
+                assert mode == constants.MODE_CLIP
                 if index < 0:
                     index = 0
                 else:
@@ -247,7 +238,6 @@
 
         arr.setitem(space, [index], dtype.coerce(space, value))
 
-
 def diagonal(space, arr, offset, axis1, axis2):
     shape = arr.get_shape()
     shapelen = len(shape)
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
@@ -20,14 +20,14 @@
 MIXIN_32 = (int_typedef,) if LONG_BIT == 32 else ()
 MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else ()
 
-# Is this the proper place for this?
-ENABLED_LONG_DOUBLE = False
-long_double_size = rffi.sizeof_c_type('long double', ignore_errors=True)
+#long_double_size = rffi.sizeof_c_type('long double', ignore_errors=True)
+#import os
+#if long_double_size == 8 and os.name == 'nt':
+#    # this is a lie, or maybe a wish, MS fakes longdouble math with double
+#    long_double_size = 12
 
-import os
-if long_double_size == 8 and os.name == 'nt':
-    # this is a lie, or maybe a wish, MS fakes longdouble math with double
-    long_double_size = 12
+# hardcode to 8 for now (simulate using normal double) until long double works
+long_double_size = 8
 
 
 def new_dtype_getter(name):
@@ -63,6 +63,7 @@
 
 class PrimitiveBox(Box):
     _mixin_ = True
+    _immutable_fields_ = ['value']
 
     def __init__(self, value):
         self.value = value
@@ -82,11 +83,11 @@
         ret = builder.build()
 
         lltype.free(value, flavor="raw")
-
         return ret
 
 class ComplexBox(Box):
     _mixin_ = True
+    _immutable_fields_ = ['real', 'imag']
 
     def __init__(self, real, imag=0.):
         self.real = real
@@ -111,11 +112,11 @@
         ret = builder.build()
 
         lltype.free(value, flavor="raw")
-
         return ret
 
+
 class W_GenericBox(W_Root):
-    _attrs_ = ()
+    _attrs_ = []
 
     def descr__new__(space, w_subtype, __args__):
         raise operationerrfmt(space.w_TypeError,
@@ -125,12 +126,21 @@
     def get_dtype(self, space):
         return self._get_dtype(space)
 
+    def item(self, space):
+        return self.get_dtype(space).itemtype.to_builtin_type(space, self)
+
     def descr_str(self, space):
         return space.wrap(self.get_dtype(space).itemtype.str_format(self))
 
     def descr_format(self, space, w_spec):
         return space.format(self.item(space), w_spec)
 
+    def descr_hash(self, space):
+        return space.hash(self.item(space))
+
+    def descr_index(self, space):
+        return space.index(self.item(space))
+
     def descr_int(self, space):
         box = self.convert_to(W_LongBox._get_dtype(space))
         assert isinstance(box, W_LongBox)
@@ -222,19 +232,13 @@
         w_remainder = self.descr_rmod(space, w_other)
         return space.newtuple([w_quotient, w_remainder])
 
-    def descr_hash(self, space):
-        return space.hash(self.item(space))
-
-    def item(self, space):
-        return self.get_dtype(space).itemtype.to_builtin_type(space, self)
-
     def descr_any(self, space):
         value = space.is_true(self)
-        return space.wrap(W_BoolBox(value))
+        return self.get_dtype(space).box(value)
 
     def descr_all(self, space):
         value = space.is_true(self)
-        return space.wrap(W_BoolBox(value))
+        return self.get_dtype(space).box(value)
 
     def descr_ravel(self, space):
         from pypy.module.micronumpy.base import convert_to_array
@@ -260,7 +264,7 @@
     descr__new__, _get_dtype, descr_reduce = new_dtype_getter("bool")
 
 class W_NumberBox(W_GenericBox):
-    _attrs_ = ()
+    pass
 
 class W_IntegerBox(W_NumberBox):
     def int_w(self, space):
@@ -309,10 +313,10 @@
     descr__new__, _get_dtype, descr_reduce = new_dtype_getter('ulonglong')
 
 class W_InexactBox(W_NumberBox):
-    _attrs_ = ()
+    pass
 
 class W_FloatingBox(W_InexactBox):
-    _attrs_ = ()
+    pass
 
 class W_Float16Box(W_FloatingBox, PrimitiveBox):
     descr__new__, _get_dtype, descr_reduce = new_dtype_getter("float16")
@@ -323,9 +327,43 @@
 class W_Float64Box(W_FloatingBox, PrimitiveBox):
     descr__new__, _get_dtype, descr_reduce = new_dtype_getter("float64")
 
+class W_ComplexFloatingBox(W_InexactBox):
+    def descr_get_real(self, space):
+        dtype = self._COMPONENTS_BOX._get_dtype(space)
+        box = self.convert_real_to(dtype)
+        assert isinstance(box, self._COMPONENTS_BOX)
+        return space.wrap(box)
+
+    def descr_get_imag(self, space):
+        dtype = self._COMPONENTS_BOX._get_dtype(space)
+        box = self.convert_imag_to(dtype)
+        assert isinstance(box, self._COMPONENTS_BOX)
+        return space.wrap(box)
+
+class W_Complex64Box(ComplexBox, W_ComplexFloatingBox):
+    descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex64")
+    _COMPONENTS_BOX = W_Float32Box
+
+class W_Complex128Box(ComplexBox, W_ComplexFloatingBox):
+    descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex128")
+    _COMPONENTS_BOX = W_Float64Box
+
+if long_double_size == 8:
+    W_FloatLongBox = W_Float64Box
+    W_ComplexLongBox = W_Complex128Box
+
+elif long_double_size in (12, 16):
+    class W_FloatLongBox(W_FloatingBox, PrimitiveBox):
+        descr__new__, _get_dtype, descr_reduce = new_dtype_getter("float%d" % (long_double_size * 8))
+
+    class W_ComplexLongBox(ComplexBox, W_ComplexFloatingBox):
+        descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex%d" % (long_double_size * 16))
+        _COMPONENTS_BOX = W_FloatLongBox
+
 class W_FlexibleBox(W_GenericBox):
-    _attrs_ = ['ofs', 'dtype', 'arr']
-    _immutable_fields_ = ['ofs']
+    _attrs_ = ['arr', 'ofs', 'dtype']
+    _immutable_fields_ = ['arr', 'ofs', 'dtype']
+
     def __init__(self, arr, ofs, dtype):
         self.arr = arr # we have to keep array alive
         self.ofs = ofs
@@ -334,11 +372,6 @@
     def get_dtype(self, space):
         return self.arr.dtype
 
- at unwrap_spec(self=W_GenericBox)
-def descr_index(space, self):
-    return space.index(self.item(space))
-
-
 class W_VoidBox(W_FlexibleBox):
     def descr_getitem(self, space, w_item):
         from pypy.module.micronumpy.types import VoidType
@@ -388,7 +421,6 @@
         # XXX assert dtype is str type
         return self
 
-
 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
@@ -398,7 +430,6 @@
             arr.storage[i] = arg[i]
         return W_StringBox(arr, 0, arr.dtype)
 
-
 class W_UnicodeBox(W_CharacterBox):
     def descr__new__unicode_box(space, w_subtype, w_arg):
         raise OperationError(space.w_NotImplementedError, space.wrap("Unicode is not supported yet"))
@@ -413,59 +444,6 @@
         #    arr.storage[i] = arg[i]
         return W_UnicodeBox(arr, 0, arr.dtype)
 
-
-class W_ComplexFloatingBox(W_InexactBox):
-    _attrs_ = ()
-    def descr_get_real(self, space):
-        dtype = self._COMPONENTS_BOX._get_dtype(space)
-        box = self.convert_real_to(dtype)
-        assert isinstance(box, self._COMPONENTS_BOX)
-        return space.wrap(box)
-
-    def descr_get_imag(self, space):
-        dtype = self._COMPONENTS_BOX._get_dtype(space)
-        box = self.convert_imag_to(dtype)
-        assert isinstance(box, self._COMPONENTS_BOX)
-        return space.wrap(box)
-
-
-class W_Complex64Box(ComplexBox, W_ComplexFloatingBox):
-    descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex64")
-    _COMPONENTS_BOX = W_Float32Box
-
-
-class W_Complex128Box(ComplexBox, W_ComplexFloatingBox):
-    descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex128")
-    _COMPONENTS_BOX = W_Float64Box
-
-if ENABLED_LONG_DOUBLE and long_double_size == 12:
-    class W_Float96Box(W_FloatingBox, PrimitiveBox):
-        descr__new__, _get_dtype, descr_reduce = new_dtype_getter("float96")
-
-    W_LongDoubleBox = W_Float96Box
-
-    class W_Complex192Box(ComplexBox, W_ComplexFloatingBox):
-        descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex192")
-        _COMPONENTS_BOX = W_Float96Box
-
-    W_CLongDoubleBox = W_Complex192Box
-
-elif ENABLED_LONG_DOUBLE and long_double_size == 16:
-    class W_Float128Box(W_FloatingBox, PrimitiveBox):
-        descr__new__, _get_dtype, descr_reduce = new_dtype_getter("float128")
-    W_LongDoubleBox = W_Float128Box
-
-    class W_Complex256Box(ComplexBox, W_ComplexFloatingBox):
-        descr__new__, _get_dtype, descr_reduce = new_dtype_getter("complex256")
-        _COMPONENTS_BOX = W_Float128Box
-
-    W_CLongDoubleBox = W_Complex256Box
-
-elif ENABLED_LONG_DOUBLE:
-    W_LongDoubleBox = W_Float64Box
-    W_CLongDoubleBox = W_Complex64Box
-
-
 W_GenericBox.typedef = TypeDef("generic",
     __module__ = "numpypy",
 
@@ -535,7 +513,7 @@
 W_BoolBox.typedef = TypeDef("bool_", W_GenericBox.typedef,
     __module__ = "numpypy",
     __new__ = interp2app(W_BoolBox.descr__new__.im_func),
-    __index__ = interp2app(descr_index),
+    __index__ = interp2app(W_BoolBox.descr_index),
     __reduce__ = interp2app(W_BoolBox.descr_reduce),
 )
 
@@ -558,49 +536,49 @@
 W_Int8Box.typedef = TypeDef("int8", W_SignedIntegerBox.typedef,
     __module__ = "numpypy",
     __new__ = interp2app(W_Int8Box.descr__new__.im_func),
-    __index__ = interp2app(descr_index),
+    __index__ = interp2app(W_Int8Box.descr_index),
     __reduce__ = interp2app(W_Int8Box.descr_reduce),
 )
 
 W_UInt8Box.typedef = TypeDef("uint8", W_UnsignedIntegerBox.typedef,
     __module__ = "numpypy",
     __new__ = interp2app(W_UInt8Box.descr__new__.im_func),
-    __index__ = interp2app(descr_index),
+    __index__ = interp2app(W_UInt8Box.descr_index),
     __reduce__ = interp2app(W_UInt8Box.descr_reduce),
 )
 
 W_Int16Box.typedef = TypeDef("int16", W_SignedIntegerBox.typedef,
     __module__ = "numpypy",
     __new__ = interp2app(W_Int16Box.descr__new__.im_func),
-    __index__ = interp2app(descr_index),
+    __index__ = interp2app(W_Int16Box.descr_index),
     __reduce__ = interp2app(W_Int16Box.descr_reduce),
 )
 
 W_UInt16Box.typedef = TypeDef("uint16", W_UnsignedIntegerBox.typedef,
     __module__ = "numpypy",
     __new__ = interp2app(W_UInt16Box.descr__new__.im_func),
-    __index__ = interp2app(descr_index),
+    __index__ = interp2app(W_UInt16Box.descr_index),
     __reduce__ = interp2app(W_UInt16Box.descr_reduce),
 )
 
 W_Int32Box.typedef = TypeDef("int32", (W_SignedIntegerBox.typedef,) + MIXIN_32,
     __module__ = "numpypy",
     __new__ = interp2app(W_Int32Box.descr__new__.im_func),
-    __index__ = interp2app(descr_index),
+    __index__ = interp2app(W_Int32Box.descr_index),
     __reduce__ = interp2app(W_Int32Box.descr_reduce),
 )
 
 W_UInt32Box.typedef = TypeDef("uint32", W_UnsignedIntegerBox.typedef,
     __module__ = "numpypy",
     __new__ = interp2app(W_UInt32Box.descr__new__.im_func),
-    __index__ = interp2app(descr_index),
+    __index__ = interp2app(W_UInt32Box.descr_index),
     __reduce__ = interp2app(W_UInt32Box.descr_reduce),
 )
 
 W_Int64Box.typedef = TypeDef("int64", (W_SignedIntegerBox.typedef,) + MIXIN_64,
     __module__ = "numpypy",
     __new__ = interp2app(W_Int64Box.descr__new__.im_func),
-    __index__ = interp2app(descr_index),
+    __index__ = interp2app(W_Int64Box.descr_index),
     __reduce__ = interp2app(W_Int64Box.descr_reduce),
 )
 
@@ -614,7 +592,7 @@
 W_UInt64Box.typedef = TypeDef("uint64", W_UnsignedIntegerBox.typedef,
     __module__ = "numpypy",
     __new__ = interp2app(W_UInt64Box.descr__new__.im_func),
-    __index__ = interp2app(descr_index),
+    __index__ = interp2app(W_UInt64Box.descr_index),
     __reduce__ = interp2app(W_UInt64Box.descr_reduce),
 )
 
@@ -628,53 +606,53 @@
 
 W_Float16Box.typedef = TypeDef("float16", W_FloatingBox.typedef,
     __module__ = "numpypy",
-
     __new__ = interp2app(W_Float16Box.descr__new__.im_func),
     __reduce__ = interp2app(W_Float16Box.descr_reduce),
 )
 
 W_Float32Box.typedef = TypeDef("float32", W_FloatingBox.typedef,
     __module__ = "numpypy",
-
     __new__ = interp2app(W_Float32Box.descr__new__.im_func),
     __reduce__ = interp2app(W_Float32Box.descr_reduce),
 )
 
 W_Float64Box.typedef = TypeDef("float64", (W_FloatingBox.typedef, float_typedef),
     __module__ = "numpypy",
-
     __new__ = interp2app(W_Float64Box.descr__new__.im_func),
     __reduce__ = interp2app(W_Float64Box.descr_reduce),
 )
 
-if ENABLED_LONG_DOUBLE and long_double_size == 12:
-    W_Float96Box.typedef = TypeDef("float96", (W_FloatingBox.typedef),
+W_ComplexFloatingBox.typedef = TypeDef("complexfloating", W_InexactBox.typedef,
+    __module__ = "numpypy",
+)
+
+W_Complex64Box.typedef = TypeDef("complex64", (W_ComplexFloatingBox.typedef),
+    __module__ = "numpypy",
+    __new__ = interp2app(W_Complex64Box.descr__new__.im_func),
+    __reduce__ = interp2app(W_Complex64Box.descr_reduce),
+    real = GetSetProperty(W_ComplexFloatingBox .descr_get_real),
+    imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
+)
+
+W_Complex128Box.typedef = TypeDef("complex128", (W_ComplexFloatingBox.typedef, complex_typedef),
+    __module__ = "numpypy",
+    __new__ = interp2app(W_Complex128Box.descr__new__.im_func),
+    __reduce__ = interp2app(W_Complex128Box.descr_reduce),
+    real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
+    imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
+)
+
+if long_double_size in (12, 16):
+    W_FloatLongBox.typedef = TypeDef("float%d" % (long_double_size * 8), (W_FloatingBox.typedef),
         __module__ = "numpypy",
-        __reduce__ = interp2app(W_Float96Box.descr_reduce),
-
-        __new__ = interp2app(W_Float96Box.descr__new__.im_func),
+        __new__ = interp2app(W_FloatLongBox.descr__new__.im_func),
+        __reduce__ = interp2app(W_FloatLongBox.descr_reduce),
     )
 
-    W_Complex192Box.typedef = TypeDef("complex192", (W_ComplexFloatingBox.typedef, complex_typedef),
+    W_ComplexLongBox.typedef = TypeDef("complex%d" % (long_double_size * 16), (W_ComplexFloatingBox.typedef, complex_typedef),
         __module__ = "numpypy",
-        __new__ = interp2app(W_Complex192Box.descr__new__.im_func),
-        __reduce__ = interp2app(W_Complex192Box.descr_reduce),
-        real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
-        imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
-    )
-
-elif ENABLED_LONG_DOUBLE and long_double_size == 16:
-    W_Float128Box.typedef = TypeDef("float128", (W_FloatingBox.typedef),
-        __module__ = "numpypy",
-
-        __new__ = interp2app(W_Float128Box.descr__new__.im_func),
-        __reduce__ = interp2app(W_Float128Box.descr_reduce),
-    )
-
-    W_Complex256Box.typedef = TypeDef("complex256", (W_ComplexFloatingBox.typedef, complex_typedef),
-        __module__ = "numpypy",
-        __new__ = interp2app(W_Complex256Box.descr__new__.im_func),
-        __reduce__ = interp2app(W_Complex256Box.descr_reduce),
+        __new__ = interp2app(W_ComplexLongBox.descr__new__.im_func),
+        __reduce__ = interp2app(W_ComplexLongBox.descr_reduce),
         real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
         imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
     )
@@ -703,24 +681,3 @@
     __module__ = "numpypy",
     __new__ = interp2app(W_UnicodeBox.descr__new__unicode_box.im_func),
 )
-
-W_ComplexFloatingBox.typedef = TypeDef("complexfloating", W_InexactBox.typedef,
-    __module__ = "numpypy",
-)
-
-
-W_Complex128Box.typedef = TypeDef("complex128", (W_ComplexFloatingBox.typedef, complex_typedef),
-    __module__ = "numpypy",
-    __new__ = interp2app(W_Complex128Box.descr__new__.im_func),
-    __reduce__ = interp2app(W_Complex128Box.descr_reduce),
-    real = GetSetProperty(W_ComplexFloatingBox.descr_get_real),
-    imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
-)
-
-W_Complex64Box.typedef = TypeDef("complex64", (W_ComplexFloatingBox.typedef),
-    __module__ = "numpypy",
-    __new__ = interp2app(W_Complex64Box.descr__new__.im_func),
-    __reduce__ = interp2app(W_Complex64Box.descr_reduce),
-    real = GetSetProperty(W_ComplexFloatingBox .descr_get_real),
-    imag = GetSetProperty(W_ComplexFloatingBox.descr_get_imag),
-)
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
@@ -1,4 +1,3 @@
-
 import sys
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, operationerrfmt
@@ -11,6 +10,12 @@
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rlib import jit
 
+if sys.byteorder == 'little':
+    byteorder_prefix = '<'
+    nonnative_byteorder_prefix = '>'
+else:
+    byteorder_prefix = '>'
+    nonnative_byteorder_prefix = '<'
 
 UNSIGNEDLTR = "u"
 SIGNEDLTR = "i"
@@ -44,12 +49,11 @@
     out = base.W_NDimArray.from_shape(space, shape, dtype)
     return out
 
-
 class W_Dtype(W_Root):
     _immutable_fields_ = ["itemtype", "num", "kind", "shape"]
 
     def __init__(self, itemtype, num, kind, name, char, w_box_type,
-                 alternate_constructors=[], aliases=[],
+                 alternate_constructors=[], aliases=[], float_type=None,
                  fields=None, fieldnames=None, native=True, shape=[], subdtype=None):
         self.itemtype = itemtype
         self.num = num
@@ -59,10 +63,10 @@
         self.w_box_type = w_box_type
         self.alternate_constructors = alternate_constructors
         self.aliases = aliases
+        self.float_type = float_type
         self.fields = fields
         self.fieldnames = fieldnames
         self.native = native
-        self.float_type = None
         self.shape = list(shape)
         self.subdtype = subdtype
         if not subdtype:
@@ -148,7 +152,11 @@
 
     def eq(self, space, w_other):
         w_other = space.call_function(space.gettypefor(W_Dtype), w_other)
-        return space.is_w(self, w_other)
+        if space.is_w(self, w_other):
+            return True
+        if isinstance(w_other, W_Dtype):
+            return space.eq_w(self.descr_reduce(space), w_other.descr_reduce(space))
+        return False
 
     def descr_eq(self, space, w_other):
         return space.wrap(self.eq(space, w_other))
@@ -223,7 +231,7 @@
         return self.kind == SIGNEDLTR
 
     def is_complex_type(self):
-        return False
+        return self.kind == COMPLEXLTR
 
     def is_float_type(self):
         return (self.kind == FLOATINGLTR or self.float_type is not None)
@@ -259,21 +267,22 @@
         builder_args = space.newtuple([space.wrap("%s%d" % (kind, elemsize)), space.wrap(0), space.wrap(1)])
 
         version = space.wrap(3)
-        order = space.wrap(byteorder_prefix if self.native else nonnative_byteorder_prefix)
         names = self.descr_get_names(space)
         values = self.descr_get_fields(space)
         if self.fields:
+            order = space.wrap('|')
             #TODO: Implement this when subarrays are implemented
             subdescr = space.w_None
-            #TODO: Change this when alignment is implemented :
             size = 0
             for key in self.fields:
                 dtype = self.fields[key][1]
                 assert isinstance(dtype, W_Dtype)
                 size += dtype.get_size()
             w_size = space.wrap(size)
+            #TODO: Change this when alignment is implemented
             alignment = space.wrap(1)
         else:
+            order = space.wrap(byteorder_prefix if self.native else nonnative_byteorder_prefix)
             subdescr = space.w_None
             w_size = space.wrap(-1)
             alignment = space.wrap(-1)
@@ -295,18 +304,6 @@
         fields = space.getitem(w_data, space.wrap(4))
         self.set_fields(space, fields)
 
-class W_ComplexDtype(W_Dtype):
-    def __init__(self, itemtype, num, kind, name, char, w_box_type,
-                 alternate_constructors=[], aliases=[],
-                 fields=None, fieldnames=None, native=True, float_type=None):
-        W_Dtype.__init__(self, itemtype, num, kind, name, char, w_box_type,
-                 alternate_constructors=alternate_constructors, aliases=aliases,
-                 fields=fields, fieldnames=fieldnames, native=native)
-        self.float_type = float_type
-
-    def is_complex_type(self):
-        return True
-
 def dtype_from_list(space, w_lst):
     lst_w = space.listview(w_lst)
     fields = {}
@@ -340,38 +337,6 @@
     raise OperationError(space.w_NotImplementedError, space.wrap(
         "dtype from dict"))
 
-def variable_dtype(space, name):
-    if name[0] in '<>=':
-        name = name[1:]
-    char = name[0]
-    if len(name) == 1:
-        size = 0
-    else:
-        try:
-            size = int(name[1:])
-        except ValueError:
-            raise OperationError(space.w_TypeError, space.wrap("data type not understood"))
-    if char == 'S' or char == 'c':
-        itemtype = types.StringType(size)
-        basename = 'string'
-        num = 18
-        w_box_type = space.gettypefor(interp_boxes.W_StringBox)
-    elif char == 'V':
-        num = 20
-        basename = 'void'
-        itemtype = types.VoidType(size)
-        return W_Dtype(itemtype, 20, VOIDLTR, "void" + str(size),
-                    "V", space.gettypefor(interp_boxes.W_VoidBox))
-    else:
-        assert char == 'U'
-        basename = 'unicode'
-        itemtype = types.UnicodeType(size)
-        num = 19
-        w_box_type = space.gettypefor(interp_boxes.W_UnicodeBox)
-    return W_Dtype(itemtype, num, char,
-                   basename + str(8 * itemtype.get_element_size()),
-                   char, w_box_type)
-
 def dtype_from_spec(space, name):
         raise OperationError(space.w_NotImplementedError, space.wrap(
             "dtype from spec"))
@@ -455,30 +420,61 @@
 )
 W_Dtype.typedef.acceptable_as_base_class = False
 
-if sys.byteorder == 'little':
-    byteorder_prefix = '<'
-    nonnative_byteorder_prefix = '>'
-else:
-    byteorder_prefix = '>'
-    nonnative_byteorder_prefix = '<'
+
+def variable_dtype(space, name):
+    if name[0] in '<>=':
+        name = name[1:]
+    char = name[0]
+    if len(name) == 1:
+        size = 0
+    else:
+        try:
+            size = int(name[1:])
+        except ValueError:
+            raise OperationError(space.w_TypeError, space.wrap("data type not understood"))
+    if char == 'c':
+        char = 'S'
+        size = 1
+    if char == 'S':
+        itemtype = types.StringType(size)
+        basename = 'string'
+        num = 18
+        w_box_type = space.gettypefor(interp_boxes.W_StringBox)
+    elif char == 'V':
+        num = 20
+        basename = 'void'
+        itemtype = types.VoidType(size)
+        return W_Dtype(itemtype, 20, VOIDLTR, "void" + str(size),
+                    "V", space.gettypefor(interp_boxes.W_VoidBox))
+    else:
+        assert char == 'U'
+        basename = 'unicode'
+        itemtype = types.UnicodeType(size)
+        num = 19
+        w_box_type = space.gettypefor(interp_boxes.W_UnicodeBox)
+    return W_Dtype(itemtype, num, char,
+                   basename + str(8 * itemtype.get_element_size()),
+                   char, w_box_type)
 
 def new_string_dtype(space, size):
+    itemtype = types.StringType(size)
     return W_Dtype(
-        types.StringType(size),
+        itemtype,
         num=18,
         kind=STRINGLTR,
-        name='string',
-        char='S' + str(size),
+        name='string' + str(8 * itemtype.get_element_size()),
+        char='S',
         w_box_type = space.gettypefor(interp_boxes.W_StringBox),
     )
 
 def new_unicode_dtype(space, size):
+    itemtype = types.UnicodeType(size)
     return W_Dtype(
-        types.UnicodeType(size),
+        itemtype,
         num=19,
         kind=UNICODELTR,
-        name='unicode',
-        char='U' + str(size),
+        name='unicode' + str(8 * itemtype.get_element_size()),
+        char='U',
         w_box_type = space.gettypefor(interp_boxes.W_UnicodeBox),
     )
 
@@ -542,15 +538,11 @@
             char="I",
             w_box_type=space.gettypefor(interp_boxes.W_UInt32Box),
         )
-        if LONG_BIT == 32:
-            name = "int32"
-        elif LONG_BIT == 64:
-            name = "int64"
         self.w_longdtype = W_Dtype(
             types.Long(),
             num=7,
             kind=SIGNEDLTR,
-            name=name,
+            name="int%d" % LONG_BIT,
             char="l",
             w_box_type=space.gettypefor(interp_boxes.W_LongBox),
             alternate_constructors=[space.w_int,
@@ -563,7 +555,7 @@
             types.ULong(),
             num=8,
             kind=UNSIGNEDLTR,
-            name="u" + name,
+            name="uint%d" % LONG_BIT,
             char="L",
             w_box_type=space.gettypefor(interp_boxes.W_ULongBox),
             alternate_constructors=[ space.gettypefor(interp_boxes.W_UnsignedIntegerBox),
@@ -607,7 +599,16 @@
                                    ],
             aliases=["float", "double"],
         )
-        self.w_complex64dtype = W_ComplexDtype(
+        self.w_floatlongdtype = W_Dtype(
+            types.FloatLong(),
+            num=13,
+            kind=FLOATINGLTR,
+            name="float%d" % (interp_boxes.long_double_size * 8),
+            char="g",
+            w_box_type=space.gettypefor(interp_boxes.W_FloatLongBox),
+            aliases=["longdouble", "longfloat"],
+        )
+        self.w_complex64dtype = W_Dtype(
             types.Complex64(),
             num=14,
             kind=COMPLEXLTR,
@@ -616,7 +617,7 @@
             w_box_type = space.gettypefor(interp_boxes.W_Complex64Box),
             float_type = self.w_float32dtype,
         )
-        self.w_complex128dtype = W_ComplexDtype(
+        self.w_complex128dtype = W_Dtype(
             types.Complex128(),
             num=15,
             kind=COMPLEXLTR,
@@ -627,57 +628,16 @@
             aliases=["complex"],
             float_type = self.w_float64dtype,
         )
-        if interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size == 12:
-            self.w_float96dtype = W_Dtype(
-                types.Float96(),
-                num=13,
-                kind=FLOATINGLTR,
-                name="float96",
-                char="g",
-                w_box_type=space.gettypefor(interp_boxes.W_Float96Box),
-                aliases=["longdouble", "longfloat"],
-            )
-            self.w_complex192dtype = W_ComplexDtype(
-                types.Complex192(),
-                num=16,
-                kind=COMPLEXLTR,
-                name="complex192",
-                char="G",
-                w_box_type = space.gettypefor(interp_boxes.W_Complex192Box),
-                alternate_constructors=[space.w_complex],
-                aliases=["clongdouble", "clongfloat"],
-                float_type = self.w_float96dtype,
-            )
-            self.w_longdouble = self.w_float96dtype
-            self.w_clongdouble = self.w_complex192dtype
-        elif interp_boxes.ENABLED_LONG_DOUBLE and interp_boxes.long_double_size == 16:
-            self.w_float128dtype = W_Dtype(
-                types.Float128(),
-                num=13,
-                kind=FLOATINGLTR,
-                name="float128",
-                char="g",
-                w_box_type=space.gettypefor(interp_boxes.W_Float128Box),
-                aliases=["longdouble", "longfloat"],
-            )
-            self.w_complex256dtype = W_ComplexDtype(
-                types.Complex256(),
-                num=16,
-                kind=COMPLEXLTR,
-                name="complex256",
-                char="G",
-                w_box_type = space.gettypefor(interp_boxes.W_Complex256Box),
-                alternate_constructors=[space.w_complex],
-                aliases=["clongdouble", "clongfloat"],
-                float_type = self.w_float128dtype,
-            )
-            self.w_longdouble = self.w_float128dtype
-            self.w_clongdouble = self.w_complex256dtype
-        elif interp_boxes.ENABLED_LONG_DOUBLE:
-            self.w_float64dtype.aliases += ["longdouble", "longfloat"]
-            self.w_complex128dtype.aliases += ["clongdouble", "clongfloat"]
-            self.w_longdouble = self.w_float64dtype
-            self.w_clongdouble = self.w_complex128dtype
+        self.w_complexlongdtype = W_Dtype(
+            types.ComplexLong(),
+            num=16,
+            kind=COMPLEXLTR,
+            name="complex%d" % (interp_boxes.long_double_size * 16),
+            char="G",
+            w_box_type = space.gettypefor(interp_boxes.W_ComplexLongBox),
+            aliases=["clongdouble", "clongfloat"],
+            float_type = self.w_floatlongdtype,
+        )
         self.w_stringdtype = W_Dtype(
             types.StringType(0),
             num=18,
@@ -750,21 +710,18 @@
             char=UINTPLTR,
             w_box_type = space.gettypefor(uintp_box),
         )
-        float_dtypes = [self.w_float16dtype,
-                self.w_float32dtype, self.w_float64dtype,
-                ]
-        complex_dtypes =  [self.w_complex64dtype, self.w_complex128dtype]
-        if interp_boxes.ENABLED_LONG_DOUBLE:
-            float_dtypes.append(self.w_longdouble)
-            complex_dtypes.append(self.w_clongdouble)
+        float_dtypes = [self.w_float16dtype, self.w_float32dtype,
+                        self.w_float64dtype, self.w_floatlongdtype]
+        complex_dtypes = [self.w_complex64dtype, self.w_complex128dtype,
+                          self.w_complexlongdtype]
         self.builtin_dtypes = [
             self.w_booldtype,
             self.w_int8dtype, self.w_uint8dtype,
             self.w_int16dtype, self.w_uint16dtype,
             self.w_longdtype, self.w_ulongdtype,
             self.w_int32dtype, self.w_uint32dtype,
-            self.w_int64dtype, self.w_uint64dtype] + \
-            float_dtypes + complex_dtypes + [
+            self.w_int64dtype, self.w_uint64dtype,
+            ] + float_dtypes + complex_dtypes + [
             self.w_stringdtype, self.w_unicodedtype, self.w_voiddtype,
             self.w_intpdtype, self.w_uintpdtype,
         ]
@@ -818,6 +775,7 @@
             'STRING': self.w_stringdtype,
             'CFLOAT': self.w_complex64dtype,
             'CDOUBLE': self.w_complex128dtype,
+            'CLONGDOUBLE': self.w_complexlongdtype,
             #'DATETIME',
             'UINT': self.w_uint32dtype,
             'INTP': self.w_intpdtype,
@@ -827,13 +785,11 @@
             #'TIMEDELTA',
             'INT': self.w_int32dtype,
             'DOUBLE': self.w_float64dtype,
+            'LONGDOUBLE': self.w_floatlongdtype,
             'USHORT': self.w_uint16dtype,
             'FLOAT': self.w_float32dtype,
             'BOOL': self.w_booldtype,
         }
-        if interp_boxes.ENABLED_LONG_DOUBLE:
-            typeinfo_full['LONGDOUBLE'] = self.w_longdouble
-            typeinfo_full['CLONGDOUBLE'] = self.w_clongdouble
 
         typeinfo_partial = {
             'Generic': interp_boxes.W_GenericBox,
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
@@ -1,4 +1,3 @@
-
 from pypy.interpreter.error import operationerrfmt, OperationError
 from pypy.interpreter.typedef import TypeDef, GetSetProperty, make_weakref_descr
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
@@ -14,7 +13,7 @@
 from pypy.module.micronumpy.appbridge import get_appbridge_cache
 from pypy.module.micronumpy import loop
 from pypy.module.micronumpy.dot import match_dot_shapes
-from pypy.module.micronumpy.interp_arrayops import repeat, choose
+from pypy.module.micronumpy.interp_arrayops import repeat, choose, put
 from pypy.module.micronumpy.arrayimpl import scalar
 from rpython.tool.sourcetools import func_with_new_name
 from rpython.rlib import jit
@@ -421,8 +420,8 @@
                                      [0] * len(self.get_shape()))
                 assert isinstance(w_obj, interp_boxes.W_GenericBox)
                 return w_obj.item(space)
-            raise OperationError(space.w_IndexError,
-                                 space.wrap("index out of bounds"))
+            raise OperationError(space.w_ValueError,
+                                 space.wrap("can only convert an array of size 1 to a Python scalar"))
         if space.isinstance_w(w_arg, space.w_int):
             if self.is_scalar():
                 raise OperationError(space.w_IndexError,
@@ -509,9 +508,8 @@
             loop.byteswap(self.implementation, w_res.implementation)
             return w_res
 
-    @unwrap_spec(mode=str)
-    def descr_choose(self, space, w_choices, w_out=None, mode='raise'):
-        return choose(space, self, w_choices, w_out, mode)
+    def descr_choose(self, space, w_choices, w_out=None, w_mode=None):
+        return choose(space, self, w_choices, w_out, w_mode)
 
     def descr_clip(self, space, w_min, w_max, w_out=None):
         if space.is_none(w_out):
@@ -550,6 +548,12 @@
         return interp_arrayops.diagonal(space, self.implementation, offset,
                                         axis1, axis2)
 
+    @unwrap_spec(offset=int, axis1=int, axis2=int)
+    def descr_trace(self, space, offset=0, axis1=0, axis2=1,
+                    w_dtype=None, w_out=None):
+        diag = self.descr_diagonal(space, offset, axis1, axis2)
+        return diag.descr_sum(space, w_axis=space.wrap(-1), w_dtype=w_dtype, w_out=w_out)
+
     def descr_dump(self, space, w_file):
         raise OperationError(space.w_NotImplementedError, space.wrap(
             "dump not implemented yet"))
@@ -584,10 +588,8 @@
         raise OperationError(space.w_NotImplementedError, space.wrap(
             "ptp (peak to peak) not implemented yet"))
 
-    @unwrap_spec(mode=str)
-    def descr_put(self, space, w_indices, w_values, mode='raise'):
-        from pypy.module.micronumpy.interp_arrayops import put
-        put(space, self, w_indices, w_values, mode)
+    def descr_put(self, space, w_indices, w_values, w_mode=None):
+        put(space, self, w_indices, w_values, w_mode)
 
     def descr_resize(self, space, w_new_shape, w_refcheck=True):
         raise OperationError(space.w_NotImplementedError, space.wrap(
@@ -653,11 +655,6 @@
         raise OperationError(space.w_NotImplementedError, space.wrap(
             "tofile not implemented yet"))
 
-    def descr_trace(self, space, w_offset=0, w_axis1=0, w_axis2=1,
-                    w_dtype=None, w_out=None):
-        raise OperationError(space.w_NotImplementedError, space.wrap(
-            "trace not implemented yet"))
-
     def descr_view(self, space, w_dtype=None, w_type=None) :
         if not w_type and w_dtype:
             try:
@@ -845,7 +842,7 @@
 
     def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False,
                            cumultative=False):
-        def impl(self, space, w_axis=None, w_out=None, w_dtype=None):
+        def impl(self, space, w_axis=None, w_dtype=None, w_out=None):
             if space.is_none(w_out):
                 out = None
             elif not isinstance(w_out, W_NDimArray):
@@ -1153,6 +1150,7 @@
     round    = interp2app(W_NDimArray.descr_round),
     data     = GetSetProperty(W_NDimArray.descr_get_data),
     diagonal = interp2app(W_NDimArray.descr_diagonal),
+    trace = interp2app(W_NDimArray.descr_trace),
     view = interp2app(W_NDimArray.descr_view),
 
     ctypes = GetSetProperty(W_NDimArray.descr_get_ctypes), # XXX unimplemented
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
@@ -16,23 +16,22 @@
 def done_if_false(dtype, val):
     return not dtype.itemtype.bool(val)
 
+
 class W_Ufunc(W_Root):
-    _attrs_ = ["name", "promote_to_float", "promote_bools", "identity",
-               "allow_complex", "complex_to_float"]
-    _immutable_fields_ = ["promote_to_float", "promote_bools", "name",
-            "allow_complex", "complex_to_float"]
+    _immutable_fields_ = ["name", "promote_to_float", "promote_bools", "identity",
+            "int_only", "allow_bool", "allow_complex", "complex_to_float"]
 
     def __init__(self, name, promote_to_float, promote_bools, identity,
-                 int_only, allow_complex, complex_to_float):
+                 int_only, allow_bool, allow_complex, complex_to_float):
         self.name = name
         self.promote_to_float = promote_to_float
         self.promote_bools = promote_bools
+        self.identity = identity
+        self.int_only = int_only
+        self.allow_bool = allow_bool
         self.allow_complex = allow_complex
         self.complex_to_float = complex_to_float
 
-        self.identity = identity
-        self.int_only = int_only
-
     def descr_repr(self, space):
         return space.wrap("<ufunc '%s'>" % self.name)
 
@@ -253,16 +252,14 @@
         return res
 
 class W_Ufunc1(W_Ufunc):
+    _immutable_fields_ = ["func", "bool_result"]
     argcount = 1
 
-    _immutable_fields_ = ["func", "name"]
-
     def __init__(self, func, name, promote_to_float=False, promote_bools=False,
-        identity=None, bool_result=False, int_only=False,
-        allow_complex=True, complex_to_float=False):
-
+            identity=None, bool_result=False, int_only=False,
+            allow_bool=True, allow_complex=True, complex_to_float=False):
         W_Ufunc.__init__(self, name, promote_to_float, promote_bools, identity,
-                         int_only, allow_complex, complex_to_float)
+                         int_only, allow_bool, allow_complex, complex_to_float)
         self.func = func
         self.bool_result = bool_result
 
@@ -274,17 +271,19 @@
             if space.is_w(out, space.w_None):
                 out = None
         w_obj = convert_to_array(space, w_obj)
-        if w_obj.get_dtype().is_flexible_type():
+        dtype = w_obj.get_dtype()
+        if dtype.is_flexible_type():
             raise OperationError(space.w_TypeError,
                       space.wrap('Not implemented for this type'))
-        if self.int_only and not w_obj.get_dtype().is_int_type():
+        if (self.int_only and not dtype.is_int_type() or
+                not self.allow_bool and dtype.is_bool_type() or
+                not self.allow_complex and dtype.is_complex_type()):
             raise OperationError(space.w_TypeError, space.wrap(
                 "ufunc %s not supported for the input type" % self.name))
         calc_dtype = find_unaryop_result_dtype(space,
                                   w_obj.get_dtype(),
                                   promote_to_float=self.promote_to_float,
-                                  promote_bools=self.promote_bools,
-                                  allow_complex=self.allow_complex)
+                                  promote_bools=self.promote_bools)
         if out is not None:
             if not isinstance(out, W_NDimArray):
                 raise OperationError(space.w_TypeError, space.wrap(
@@ -319,15 +318,14 @@
 
 
 class W_Ufunc2(W_Ufunc):
-    _immutable_fields_ = ["comparison_func", "func", "name", "int_only"]
+    _immutable_fields_ = ["func", "comparison_func", "done_func"]
     argcount = 2
 
     def __init__(self, func, name, promote_to_float=False, promote_bools=False,
-        identity=None, comparison_func=False, int_only=False,
-        allow_complex=True, complex_to_float=False):
-
+            identity=None, comparison_func=False, int_only=False,
+            allow_bool=True, allow_complex=True, complex_to_float=False):
         W_Ufunc.__init__(self, name, promote_to_float, promote_bools, identity,
-                         int_only, allow_complex, complex_to_float)
+                         int_only, allow_bool, allow_complex, complex_to_float)
         self.func = func
         self.comparison_func = comparison_func
         if name == 'logical_and':
@@ -375,16 +373,14 @@
                 w_rdtype = w_ldtype
             elif w_lhs.is_scalar() and not w_rhs.is_scalar():
                 w_ldtype = w_rdtype
+        if (self.int_only and (not w_ldtype.is_int_type() or not w_rdtype.is_int_type()) or
+                not self.allow_bool and (w_ldtype.is_bool_type() or w_rdtype.is_bool_type()) or
+                not self.allow_complex and (w_ldtype.is_complex_type() or w_rdtype.is_complex_type())):
+            raise OperationError(space.w_TypeError, space.wrap("Unsupported types"))
         calc_dtype = find_binop_result_dtype(space,
             w_ldtype, w_rdtype,
-            int_only=self.int_only,
             promote_to_float=self.promote_to_float,
-            promote_bools=self.promote_bools,
-            allow_complex=self.allow_complex,
-            )
-        if self.int_only and not calc_dtype.is_int_type():
-            raise OperationError(space.w_TypeError, space.wrap(
-                "ufunc '%s' not supported for the input types" % self.name))
+            promote_bools=self.promote_bools)
         if space.is_none(w_out):
             out = None
         elif not isinstance(w_out, W_NDimArray):
@@ -431,14 +427,10 @@
 
 
 def find_binop_result_dtype(space, dt1, dt2, promote_to_float=False,
-    promote_bools=False, int_only=False, allow_complex=True):
+        promote_bools=False):
     # dt1.num should be <= dt2.num
     if dt1.num > dt2.num:
         dt1, dt2 = dt2, dt1
-    if int_only and (not dt1.is_int_type() or not dt2.is_int_type()):
-        raise OperationError(space.w_TypeError, space.wrap("Unsupported types"))
-    if not allow_complex and (dt1.is_complex_type() or dt2.is_complex_type()):
-        raise OperationError(space.w_TypeError, space.wrap("Unsupported types"))
     # Some operations promote op(bool, bool) to return int8, rather than bool
     if promote_bools and (dt1.kind == dt2.kind == interp_dtype.BOOLLTR):
         return interp_dtype.get_dtype_cache(space).w_int8dtype
@@ -449,8 +441,8 @@
             return interp_dtype.get_dtype_cache(space).w_complex64dtype
         elif dt2.num == 15:
             return interp_dtype.get_dtype_cache(space).w_complex128dtype
-        elif interp_boxes.ENABLED_LONG_DOUBLE and dt2.num == 16:
-            return interp_dtype.get_dtype_cache(space).w_clongdouble
+        elif dt2.num == 16:
+            return interp_dtype.get_dtype_cache(space).w_complexlongdtype
         else:
             raise OperationError(space.w_TypeError, space.wrap("Unsupported types"))
 
@@ -507,14 +499,11 @@
         dtypenum += 2
         return interp_dtype.get_dtype_cache(space).dtypes_by_num[dtypenum]
 
-
 @jit.unroll_safe
 def find_unaryop_result_dtype(space, dt, promote_to_float=False,
-    promote_bools=False, promote_to_largest=False, allow_complex=True):
+        promote_bools=False, promote_to_largest=False):
     if promote_bools and (dt.kind == interp_dtype.BOOLLTR):
         return interp_dtype.get_dtype_cache(space).w_int8dtype
-    if not allow_complex and (dt.is_complex_type()):
-        raise OperationError(space.w_TypeError, space.wrap("Unsupported types"))
     if promote_to_float:
         if dt.kind == interp_dtype.FLOATINGLTR or dt.kind==interp_dtype.COMPLEXLTR:
             return dt
@@ -535,7 +524,6 @@
             assert False
     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
@@ -588,7 +576,6 @@
         'unable to create dtype from objects, ' '"%T" instance not supported',
         w_obj)
 
-
 def ufunc_dtype_caller(space, ufunc_name, op_name, argcount, comparison_func,
                        bool_result):
     dtype_cache = interp_dtype.get_dtype_cache(space)
@@ -606,6 +593,7 @@
             return res
     return func_with_new_name(impl, ufunc_name)
 
+
 class UfuncState(object):
     def __init__(self, space):
         "NOT_RPYTHON"
@@ -635,10 +623,6 @@
             ("greater_equal", "ge", 2, {"comparison_func": True}),
             ("isnan", "isnan", 1, {"bool_result": True}),
             ("isinf", "isinf", 1, {"bool_result": True}),
-            ("isneginf", "isneginf", 1, {"bool_result": True,
-                                         "allow_complex": False}),
-            ("isposinf", "isposinf", 1, {"bool_result": True,
-                                         "allow_complex": False}),
             ("isfinite", "isfinite", 1, {"bool_result": True}),
 
             ('logical_and', 'logical_and', 2, {'comparison_func': True,
@@ -658,7 +642,7 @@
             ("negative", "neg", 1),
             ("absolute", "abs", 1, {"complex_to_float": True}),
             ("rint", "rint", 1),
-            ("sign", "sign", 1, {"promote_bools": True}),
+            ("sign", "sign", 1, {"allow_bool": False}),
             ("signbit", "signbit", 1, {"bool_result": True,
                                        "allow_complex": False}),
             ("reciprocal", "reciprocal", 1),
@@ -713,6 +697,7 @@
                                        "allow_complex": False}),
             ("logaddexp2", "logaddexp2", 2, {"promote_to_float": True,
                                        "allow_complex": False}),
+
             ("ones_like", "ones_like", 1),
             ("zeros_like", "zeros_like", 1),
         ]:
diff --git a/pypy/module/micronumpy/test/test_arrayops.py b/pypy/module/micronumpy/test/test_arrayops.py
--- a/pypy/module/micronumpy/test/test_arrayops.py
+++ b/pypy/module/micronumpy/test/test_arrayops.py
@@ -153,5 +153,12 @@
         a = arange(5)
         a.put(22, -5, mode='wrap')
         assert (a == array([0, 1, -5, 3, 4])).all()
-        raises(ValueError, "arange(5).put(22, -5, mode='raise')")
-        raises(ValueError, "arange(5).put(22, -5, mode='wrongmode')")
+        raises(IndexError, "arange(5).put(22, -5, mode='raise')")
+        raises(IndexError, "arange(5).put(22, -5, mode=2)")  # raise


More information about the pypy-commit mailing list