Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r73860:eb0014921290
Date: 2014-10-09 02:02 -0400
http://bitbucket.org/pypy/pypy/changeset/eb0014921290/

Log:    shuffle some things for clarity

diff --git a/pypy/module/micronumpy/concrete.py 
b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -358,11 +358,11 @@
         self.dtype = dtype
 
     def argsort(self, space, w_axis):
-        from pypy.module.micronumpy.sort import argsort_array
+        from .selection import argsort_array
         return argsort_array(self, space, w_axis)
 
     def sort(self, space, w_axis, w_order):
-        from pypy.module.micronumpy.sort import sort_array
+        from .selection import sort_array
         return sort_array(self, space, w_axis, w_order)
 
     def base(self):
diff --git a/pypy/module/micronumpy/ndarray.py 
b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -21,6 +21,7 @@
 from pypy.module.micronumpy.flatiter import W_FlatIterator
 from pypy.module.micronumpy.strides import get_shape_from_iterable, \
     shape_agreement, shape_agreement_multiple
+from .selection import app_searchsort
 
 
 def _match_dot_shapes(space, left, right):
@@ -1299,31 +1300,6 @@
         return res
 """, filename=__file__).interphook('ptp')
 
-app_searchsort = applevel(r"""
-    def searchsort(arr, v, side, result):
-        import operator
-        def func(a, op, val):
-            imin = 0
-            imax = a.size
-            while imin < imax:
-                imid = imin + ((imax - imin) >> 1)
-                if op(a[imid], val):
-                    imin = imid +1
-                else:
-                    imax = imid
-            return imin
-        if side == 0:
-            op = operator.lt
-        else:
-            op = operator.le
-        if v.size < 2:
-            result[...] = func(arr, op, v)
-        else:
-            for i in range(v.size):
-                result[i] = func(arr, op, v[i])
-        return result
-""", filename=__file__).interphook('searchsort')
-
 W_NDimArray.typedef = TypeDef("numpy.ndarray",
     __new__ = interp2app(descr_new_array),
 
diff --git a/pypy/module/micronumpy/sort.py 
b/pypy/module/micronumpy/selection.py
rename from pypy/module/micronumpy/sort.py
rename to pypy/module/micronumpy/selection.py
--- a/pypy/module/micronumpy/sort.py
+++ b/pypy/module/micronumpy/selection.py
@@ -1,4 +1,5 @@
 from pypy.interpreter.error import oefmt
+from pypy.interpreter.gateway import applevel
 from rpython.rlib.listsort import make_timsort_class
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.rarithmetic import widen
@@ -353,3 +354,29 @@
                 cache[cls] = make_sort_function(space, cls, it)
         self.cache = cache
         self._lookup = specialize.memo()(lambda tp: cache[tp[0]])
+
+
+app_searchsort = applevel(r"""
+    def searchsort(arr, v, side, result):
+        import operator
+        def func(a, op, val):
+            imin = 0
+            imax = a.size
+            while imin < imax:
+                imid = imin + ((imax - imin) >> 1)
+                if op(a[imid], val):
+                    imin = imid +1
+                else:
+                    imax = imid
+            return imin
+        if side == 0:
+            op = operator.lt
+        else:
+            op = operator.le
+        if v.size < 2:
+            result[...] = func(arr, op, v)
+        else:
+            for i in range(v.size):
+                result[i] = func(arr, op, v[i])
+        return result
+""", filename=__file__).interphook('searchsort')
diff --git a/pypy/module/micronumpy/test/test_sorting.py 
b/pypy/module/micronumpy/test/test_selection.py
rename from pypy/module/micronumpy/test/test_sorting.py
rename to pypy/module/micronumpy/test/test_selection.py
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to