Author: Brian Kearns <[email protected]>
Branch:
Changeset: r67466:8596a76f1fd7
Date: 2013-10-17 16:59 -0400
http://bitbucket.org/pypy/pypy/changeset/8596a76f1fd7/
Log: fix sorting of unsigned arrays
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':
@@ -200,7 +200,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':
diff --git a/pypy/module/micronumpy/test/test_sorting.py
b/pypy/module/micronumpy/test/test_sorting.py
--- a/pypy/module/micronumpy/test/test_sorting.py
+++ b/pypy/module/micronumpy/test/test_sorting.py
@@ -16,14 +16,17 @@
assert array(2.0).argsort() == 0
nnp = self.non_native_prefix
for dtype in ['int', 'float', 'int16', 'float32', 'uint64',
- nnp + 'i2', complex]:
+ nnp + 'i2', complex]:
a = array([6, 4, -1, 3, 8, 3, 256+20, 100, 101], dtype=dtype)
+ exp = list(a)
+ exp = sorted(range(len(exp)), key=exp.__getitem__)
c = a.copy()
res = a.argsort()
- assert (res == [2, 3, 5, 1, 0, 4, 7, 8, 6]).all(), \
+ assert (res == exp).all(), \
'a,res,dtype %r,%r,%r' % (a,res,dtype)
assert (a == c).all() # not modified
- a = arange(100)
+
+ a = arange(100, dtype=dtype)
assert (a.argsort() == a).all()
raises(NotImplementedError, 'arange(10,dtype="float16").argsort()')
@@ -63,17 +66,18 @@
def test_sort_dtypes(self):
from numpypy import array, arange
for dtype in ['int', 'float', 'int16', 'float32', 'uint64',
- 'i2', complex]:
+ 'i2', complex]:
a = array([6, 4, -1, 3, 8, 3, 256+20, 100, 101], dtype=dtype)
- b = array([-1, 3, 3, 4, 6, 8, 100, 101, 256+20], dtype=dtype)
+ b = sorted(list(a))
c = a.copy()
a.sort()
assert (a == b).all(), \
'a,orig,dtype %r,%r,%r' % (a,c,dtype)
- a = arange(100)
- c = a.copy()
- a.sort()
- assert (a == c).all()
+
+ a = arange(100, dtype=dtype)
+ c = a.copy()
+ a.sort()
+ assert (a == c).all()
def test_sort_dtypesi_nonnative(self):
from numpypy import array
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit