Commits

Maciej Fijalkowski committed 88e4282

progress on cleanups

Comments (0)

Files changed (6)

pypy/module/_numpypy/+strides.py

+from pypy.rlib import jit
+from pypy.interpreter.error import OperationError
+
+@jit.look_inside_iff(lambda chunks: jit.isconstant(len(chunks)))
+def enumerate_chunks(chunks):
+    result = []
+    i = -1
+    for chunk in chunks:
+        i += chunk.axis_step
+        result.append((i, chunk))
+    return result
+
+@jit.look_inside_iff(lambda shape, start, strides, backstrides, chunks:
+    jit.isconstant(len(chunks))
+)
+def calculate_slice_strides(shape, start, strides, backstrides, chunks):
+    rstrides = []
+    rbackstrides = []
+    rstart = start
+    rshape = []
+    i = -1
+    for i, chunk in enumerate_chunks(chunks):
+        if chunk.step != 0:
+            rstrides.append(strides[i] * chunk.step)
+            rbackstrides.append(strides[i] * (chunk.lgt - 1) * chunk.step)
+            rshape.append(chunk.lgt)
+        rstart += strides[i] * chunk.start
+    # add a reminder
+    s = i + 1
+    assert s >= 0
+    rstrides += strides[s:]
+    rbackstrides += backstrides[s:]
+    rshape += shape[s:]
+    return rshape, rstart, rstrides, rbackstrides
+
+def calculate_broadcast_strides(strides, backstrides, orig_shape, res_shape):
+    rstrides = []
+    rbackstrides = []
+    for i in range(len(orig_shape)):
+        if orig_shape[i] == 1:
+            rstrides.append(0)
+            rbackstrides.append(0)
+        else:
+            rstrides.append(strides[i])
+            rbackstrides.append(backstrides[i])
+    rstrides = [0] * (len(res_shape) - len(orig_shape)) + rstrides
+    rbackstrides = [0] * (len(res_shape) - len(orig_shape)) + rbackstrides
+    return rstrides, rbackstrides
+
+def is_single_elem(space, w_elem, is_rec_type):
+    if (is_rec_type and space.isinstance_w(w_elem, space.w_tuple)):
+        return True
+    if space.issequence_w(w_elem):
+        return False
+    return True
+
+def find_shape_and_elems(space, w_iterable, dtype):
+    shape = [space.len_w(w_iterable)]
+    batch = space.listview(w_iterable)
+    is_rec_type = dtype is not None and dtype.is_record_type()
+    while True:
+        new_batch = []
+        if not batch:
+            return shape, []
+        if is_single_elem(space, batch[0], is_rec_type):
+            for w_elem in batch:
+                if not is_single_elem(space, w_elem, is_rec_type):
+                    raise OperationError(space.w_ValueError, space.wrap(
+                        "setting an array element with a sequence"))
+            return shape, batch
+        size = space.len_w(batch[0])
+        for w_elem in batch:
+            if (is_single_elem(space, w_elem, is_rec_type) or
+                space.len_w(w_elem) != size):
+                raise OperationError(space.w_ValueError, space.wrap(
+                    "setting an array element with a sequence"))
+            new_batch += space.listview(w_elem)
+        shape.append(size)
+        batch = new_batch
+
+def to_coords(space, shape, size, order, w_item_or_slice):
+    '''Returns a start coord, step, and length.
+    '''
+    start = lngth = step = 0
+    if not (space.isinstance_w(w_item_or_slice, space.w_int) or
+        space.isinstance_w(w_item_or_slice, space.w_slice)):
+        raise OperationError(space.w_IndexError,
+                             space.wrap('unsupported iterator index'))
+
+    start, stop, step, lngth = space.decode_index4(w_item_or_slice, size)
+
+    coords = [0] * len(shape)
+    i = start
+    if order == 'C':
+        for s in range(len(shape) -1, -1, -1):
+            coords[s] = i % shape[s]
+            i //= shape[s]
+    else:
+        for s in range(len(shape)):
+            coords[s] = i % shape[s]
+            i //= shape[s]
+    return coords, step, lngth
+
+def shape_agreement(space, shape1, shape2):
+    ret = _shape_agreement(shape1, shape2)
+    if len(ret) < max(len(shape1), len(shape2)):
+        raise OperationError(space.w_ValueError,
+            space.wrap("operands could not be broadcast together with shapes (%s) (%s)" % (
+                ",".join([str(x) for x in shape1]),
+                ",".join([str(x) for x in shape2]),
+            ))
+        )
+    return ret
+
+def _shape_agreement(shape1, shape2):
+    """ Checks agreement about two shapes with respect to broadcasting. Returns
+    the resulting shape.
+    """
+    lshift = 0
+    rshift = 0
+    if len(shape1) > len(shape2):
+        m = len(shape1)
+        n = len(shape2)
+        rshift = len(shape2) - len(shape1)
+        remainder = shape1
+    else:
+        m = len(shape2)
+        n = len(shape1)
+        lshift = len(shape1) - len(shape2)
+        remainder = shape2
+    endshape = [0] * m
+    indices1 = [True] * m
+    indices2 = [True] * m
+    for i in range(m - 1, m - n - 1, -1):
+        left = shape1[i + lshift]
+        right = shape2[i + rshift]
+        if left == right:
+            endshape[i] = left
+        elif left == 1:
+            endshape[i] = right
+            indices1[i + lshift] = False
+        elif right == 1:
+            endshape[i] = left
+            indices2[i + rshift] = False
+        else:
+            return []
+            #raise OperationError(space.w_ValueError, space.wrap(
+            #    "frames are not aligned"))
+    for i in range(m - n):
+        endshape[i] = remainder[i]
+    return endshape
+
+def get_shape_from_iterable(space, old_size, w_iterable):
+    new_size = 0
+    new_shape = []
+    if space.isinstance_w(w_iterable, space.w_int):
+        new_size = space.int_w(w_iterable)
+        if new_size < 0:
+            new_size = old_size
+        new_shape = [new_size]
+    else:
+        neg_dim = -1
+        batch = space.listview(w_iterable)
+        new_size = 1
+        if len(batch) < 1:
+            if old_size == 1:
+                # Scalars can have an empty size.
+                new_size = 1
+            else:
+                new_size = 0
+        new_shape = []
+        i = 0
+        for elem in batch:
+            s = space.int_w(elem)
+            if s < 0:
+                if neg_dim >= 0:
+                    raise OperationError(space.w_ValueError, space.wrap(
+                             "can only specify one unknown dimension"))
+                s = 1
+                neg_dim = i
+            new_size *= s
+            new_shape.append(s)
+            i += 1
+        if neg_dim >= 0:
+            new_shape[neg_dim] = old_size / new_size
+            new_size *= new_shape[neg_dim]
+    if new_size != old_size:
+        raise OperationError(space.w_ValueError,
+                space.wrap("total size of new array must be unchanged"))
+    return new_shape
+
+# Recalculating strides. Find the steps that the iteration does for each
+# dimension, given the stride and shape. Then try to create a new stride that
+# fits the new shape, using those steps. If there is a shape/step mismatch
+# (meaning that the realignment of elements crosses from one step into another)
+# return None so that the caller can raise an exception.
+def calc_new_strides(new_shape, old_shape, old_strides, order):
+    # Return the proper strides for new_shape, or None if the mapping crosses
+    # stepping boundaries
+
+    # Assumes that prod(old_shape) == prod(new_shape), len(old_shape) > 1, and
+    # len(new_shape) > 0
+    steps = []
+    last_step = 1
+    oldI = 0
+    new_strides = []
+    if order == 'F':
+        for i in range(len(old_shape)):
+            steps.append(old_strides[i] / last_step)
+            last_step *= old_shape[i]
+        cur_step = steps[0]
+        n_new_elems_used = 1
+        n_old_elems_to_use = old_shape[0]
+        for s in new_shape:
+            new_strides.append(cur_step * n_new_elems_used)
+            n_new_elems_used *= s
+            while n_new_elems_used > n_old_elems_to_use:
+                oldI += 1
+                if steps[oldI] != steps[oldI - 1]:
+                    return None
+                n_old_elems_to_use *= old_shape[oldI]
+            if n_new_elems_used == n_old_elems_to_use:
+                oldI += 1
+                if oldI < len(old_shape):
+                    cur_step = steps[oldI]
+                    n_old_elems_to_use *= old_shape[oldI]
+    elif order == 'C':
+        for i in range(len(old_shape) - 1, -1, -1):
+            steps.insert(0, old_strides[i] / last_step)
+            last_step *= old_shape[i]
+        cur_step = steps[-1]
+        n_new_elems_used = 1
+        oldI = -1
+        n_old_elems_to_use = old_shape[-1]
+        for i in range(len(new_shape) - 1, -1, -1):
+            s = new_shape[i]
+            new_strides.insert(0, cur_step * n_new_elems_used)
+            n_new_elems_used *= s
+            while n_new_elems_used > n_old_elems_to_use:
+                oldI -= 1
+                if steps[oldI] != steps[oldI + 1]:
+                    return None
+                n_old_elems_to_use *= old_shape[oldI]
+            if n_new_elems_used == n_old_elems_to_use:
+                oldI -= 1
+                if oldI >= -len(old_shape):
+                    cur_step = steps[oldI]
+                    n_old_elems_to_use *= old_shape[oldI]
+    assert len(new_strides) == len(new_shape)
+    return new_strides
+
+
+def calculate_dot_strides(strides, backstrides, res_shape, skip_dims):
+    rstrides = []
+    rbackstrides = []
+    j=0
+    for i in range(len(res_shape)):
+        if i in skip_dims:
+            rstrides.append(0)
+            rbackstrides.append(0)
+        else:
+            rstrides.append(strides[j])
+            rbackstrides.append(backstrides[j])
+            j += 1
+    return rstrides, rbackstrides

pypy/module/_numpypy/__init__.py

     interpleveldefs = {
         'ndarray': 'interp_numarray.W_NDArray',
         'array':   'interp_numarray.descr_array',
+        'dtype':   'interp_dtype.W_Dtype',
     }
     appleveldefs = {}
 

pypy/module/_numpypy/interp_numarray.py

 
 from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.gateway import unwrap_spec
+from pypy.interpreter.typedef import TypeDef, GetSetProperty
+from pypy.interpreter.gateway import unwrap_spec, interp2app
 from pypy.interpreter.error import operationerrfmt
 
+from pypy.module._numpypy import interp_dtype, strides, interp_ufuncs
+from pypy.tool.sourcetools import func_with_new_name
+
 class W_NDArray(Wrappable):
-    def __init__(self, impl):
+    def __init__(self, impl, dtype):
         self.impl = impl
+        self.dtype = dtype
+
+    def descr_get_shape(self, space):
+        return space.newtuple([space.wrap(i) for i in self.impl.getshape()])
+
+    def descr_get_dtype(self, space):
+        return self.dtype
+
+    def _binop_impl(ufunc_name):
+        def impl(self, space, w_other, w_out=None):
+            return getattr(interp_ufuncs.get(space), ufunc_name).call(space,
+                                                        [self, w_other, w_out])
+        return func_with_new_name(impl, "binop_%s_impl" % ufunc_name)
+
+    descr_add = _binop_impl("add")
+    descr_sub = _binop_impl("subtract")
+    descr_mul = _binop_impl("multiply")
+    descr_div = _binop_impl("divide")
+    descr_truediv = _binop_impl("true_divide")
+    descr_floordiv = _binop_impl("floor_divide")
+    descr_mod = _binop_impl("mod")
+    descr_pow = _binop_impl("power")
+    descr_lshift = _binop_impl("left_shift")
+    descr_rshift = _binop_impl("right_shift")
+    descr_and = _binop_impl("bitwise_and")
+    descr_or = _binop_impl("bitwise_or")
+    descr_xor = _binop_impl("bitwise_xor")
+
+    def descr_divmod(self, space, w_other):
+        w_quotient = self.descr_div(space, w_other)
+        w_remainder = self.descr_mod(space, w_other)
+        return space.newtuple([w_quotient, w_remainder])
+
+    descr_eq = _binop_impl("equal")
+    descr_ne = _binop_impl("not_equal")
+    descr_lt = _binop_impl("less")
+    descr_le = _binop_impl("less_equal")
+    descr_gt = _binop_impl("greater")
+    descr_ge = _binop_impl("greater_equal")
 
 class BaseArrayImpl(object):
     pass
 
 class Scalar(BaseArrayImpl):
-    pass
+    def getshape(self):
+        return []
 
 class ConcreteArray(BaseArrayImpl):
     def __init__(self, shape):
         self.shape = shape
 
+    def getshape(self):
+        return self.shape
+
+def descr_new_array(space, w_subtype, w_size, w_dtype=None):
+    dtype = space.interp_w(interp_dtype.W_Dtype,
+              space.call_function(space.gettypefor(interp_dtype.W_Dtype),
+                                  w_dtype))
+    shape = strides.find_shape_from_scalar(space, w_size)
+    return space.wrap(W_NDArray(ConcreteArray(shape), dtype=dtype))
+
 W_NDArray.typedef = TypeDef('ndarray',
     __module__ = 'numpypy',
+    __new__ = interp2app(descr_new_array),
+    shape = GetSetProperty(W_NDArray.descr_get_shape),
+    dtype = GetSetProperty(W_NDArray.descr_get_dtype),
+
+    __add__ = interp2app(W_NDArray.descr_add),
+    __sub__ = interp2app(W_NDArray.descr_sub),
+    __mul__ = interp2app(W_NDArray.descr_mul),
+    __div__ = interp2app(W_NDArray.descr_div),
+    __truediv__ = interp2app(W_NDArray.descr_truediv),
+    __floordiv__ = interp2app(W_NDArray.descr_floordiv),
+    __mod__ = interp2app(W_NDArray.descr_mod),
+    __divmod__ = interp2app(W_NDArray.descr_divmod),
+    __pow__ = interp2app(W_NDArray.descr_pow),
+    __lshift__ = interp2app(W_NDArray.descr_lshift),
+    __rshift__ = interp2app(W_NDArray.descr_rshift),
+    __and__ = interp2app(W_NDArray.descr_and),
+    __or__ = interp2app(W_NDArray.descr_or),
+    __xor__ = interp2app(W_NDArray.descr_xor),
 )
 
 @unwrap_spec(subok=bool, copy=bool, ownmaskna=bool)
 def descr_array(space, w_item_or_iterable, w_dtype=None, copy=True,
-                w_order=None, subok=False, ndmin=0, w_maskna=None,
+                w_order=None, subok=False, w_ndmin=None, w_maskna=None,
                 ownmaskna=False):
     # find scalar
     if w_maskna is None:
     if subok or not space.is_w(w_maskna, space.w_None) or ownmaskna:
         raise operationerrfmt(space.w_NotImplementedError,
                               "Unsupported args")
-    xxx
-
-    
-    if not space.issequence_w(w_item_or_iterable):
+    if not strides.is_list_or_tuple(space, w_item_or_iterable):
         if w_dtype is None or space.is_w(w_dtype, space.w_None):
             w_dtype = interp_ufuncs.find_dtype_for_scalar(space,
                                                           w_item_or_iterable)
         if order != 'C':  # or order != 'F':
             raise operationerrfmt(space.w_ValueError, "Unknown order: %s",
                                   order)
-    if isinstance(w_item_or_iterable, BaseArray):
+    if isinstance(w_item_or_iterable, W_NDArray):
         if (not space.is_w(w_dtype, space.w_None) and
             w_item_or_iterable.find_dtype() is not w_dtype):
             raise OperationError(space.w_NotImplementedError, space.wrap(
     else:
         dtype = space.interp_w(interp_dtype.W_Dtype,
            space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
-    shape, elems_w = find_shape_and_elems(space, w_item_or_iterable, dtype)
+    shape, elems_w = strides.find_shape_and_elems(space, w_item_or_iterable,
+                                                  dtype)
     # they come back in C order
     if dtype is None:
         for w_elem in elems_w:
         if ndmin > shapelen:
             shape = [1] * (ndmin - shapelen) + shape
             shapelen = ndmin
-    arr = W_NDimArray(shape[:], dtype=dtype, order=order)
-    arr_iter = arr.create_iter()
+    arr = W_NDArray(ConcreteArray(shape), dtype=dtype)
+    #arr_iter = arr.create_iter()
     # XXX we might want to have a jitdriver here
-    for i in range(len(elems_w)):
-        w_elem = elems_w[i]
-        dtype.setitem(arr, arr_iter.offset,
-                      dtype.coerce(space, w_elem))
-        arr_iter = arr_iter.next(shapelen)
+    #for i in range(len(elems_w)):
+    #    w_elem = elems_w[i]
+    #    dtype.setitem(arr, arr_iter.offset,
+    #                  dtype.coerce(space, w_elem))
+    #    arr_iter = arr_iter.next(shapelen)
     return arr

pypy/module/_numpypy/interp_ufuncs.py

 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec, NoneNotWrapped
 from pypy.interpreter.typedef import TypeDef, GetSetProperty, interp_attrproperty
-from pypy.module._numpypy import interp_boxes, interp_dtype, loop
+from pypy.module._numpypy import interp_boxes, interp_dtype
 from pypy.rlib import jit
 from pypy.rlib.rarithmetic import LONG_BIT
 from pypy.tool.sourcetools import func_with_new_name
                     ",".join([str(x) for x in w_obj.shape]),
                     ",".join([str(x) for x in out.shape]),
                     )
-            w_res = Call1(self.func, self.name, out.shape, calc_dtype,
-                                         res_dtype, w_obj, out)
+        xxx
+        #compute(w_res, self.func, )
+        #    w_res = Call1(self.func, self.name, out.shape, calc_dtype,
+        #                                 res_dtype, w_obj, out)
             #Force it immediately
-            w_res.get_concrete()
-        else:
-            w_res = Call1(self.func, self.name, w_obj.shape, calc_dtype,
-                                         res_dtype, w_obj)
-        w_obj.add_invalidates(space, w_res)
-        return w_res
+        #    w_res.get_concrete()
+        #else:
+        #    w_res = Call1(self.func, self.name, w_obj.shape, calc_dtype,
+        #                                 res_dtype, w_obj)
+        #return w_res
 
 
 class W_Ufunc2(W_Ufunc):
 
     @jit.unroll_safe
     def call(self, space, args_w):
-        from pypy.module._numpypy.interp_numarray import (Call2,
-            convert_to_array, Scalar, shape_agreement, BaseArray)
         if len(args_w) > 2:
             [w_lhs, w_rhs, w_out] = args_w
         else:

pypy/module/_numpypy/strides.py

-from pypy.rlib import jit
-from pypy.interpreter.error import OperationError
-
-@jit.look_inside_iff(lambda chunks: jit.isconstant(len(chunks)))
-def enumerate_chunks(chunks):
-    result = []
-    i = -1
-    for chunk in chunks:
-        i += chunk.axis_step
-        result.append((i, chunk))
-    return result
-
-@jit.look_inside_iff(lambda shape, start, strides, backstrides, chunks:
-    jit.isconstant(len(chunks))
-)
-def calculate_slice_strides(shape, start, strides, backstrides, chunks):
-    rstrides = []
-    rbackstrides = []
-    rstart = start
-    rshape = []
-    i = -1
-    for i, chunk in enumerate_chunks(chunks):
-        if chunk.step != 0:
-            rstrides.append(strides[i] * chunk.step)
-            rbackstrides.append(strides[i] * (chunk.lgt - 1) * chunk.step)
-            rshape.append(chunk.lgt)
-        rstart += strides[i] * chunk.start
-    # add a reminder
-    s = i + 1
-    assert s >= 0
-    rstrides += strides[s:]
-    rbackstrides += backstrides[s:]
-    rshape += shape[s:]
-    return rshape, rstart, rstrides, rbackstrides
-
-def calculate_broadcast_strides(strides, backstrides, orig_shape, res_shape):
-    rstrides = []
-    rbackstrides = []
-    for i in range(len(orig_shape)):
-        if orig_shape[i] == 1:
-            rstrides.append(0)
-            rbackstrides.append(0)
-        else:
-            rstrides.append(strides[i])
-            rbackstrides.append(backstrides[i])
-    rstrides = [0] * (len(res_shape) - len(orig_shape)) + rstrides
-    rbackstrides = [0] * (len(res_shape) - len(orig_shape)) + rbackstrides
-    return rstrides, rbackstrides
-
-def is_single_elem(space, w_elem, is_rec_type):
-    if (is_rec_type and space.isinstance_w(w_elem, space.w_tuple)):
-        return True
-    if space.issequence_w(w_elem):
-        return False
-    return True
-
-def find_shape_and_elems(space, w_iterable, dtype):
-    shape = [space.len_w(w_iterable)]
-    batch = space.listview(w_iterable)
-    is_rec_type = dtype is not None and dtype.is_record_type()
-    while True:
-        new_batch = []
-        if not batch:
-            return shape, []
-        if is_single_elem(space, batch[0], is_rec_type):
-            for w_elem in batch:
-                if not is_single_elem(space, w_elem, is_rec_type):
-                    raise OperationError(space.w_ValueError, space.wrap(
-                        "setting an array element with a sequence"))
-            return shape, batch
-        size = space.len_w(batch[0])
-        for w_elem in batch:
-            if (is_single_elem(space, w_elem, is_rec_type) or
-                space.len_w(w_elem) != size):
-                raise OperationError(space.w_ValueError, space.wrap(
-                    "setting an array element with a sequence"))
-            new_batch += space.listview(w_elem)
-        shape.append(size)
-        batch = new_batch
-
-def to_coords(space, shape, size, order, w_item_or_slice):
-    '''Returns a start coord, step, and length.
-    '''
-    start = lngth = step = 0
-    if not (space.isinstance_w(w_item_or_slice, space.w_int) or
-        space.isinstance_w(w_item_or_slice, space.w_slice)):
-        raise OperationError(space.w_IndexError,
-                             space.wrap('unsupported iterator index'))
-
-    start, stop, step, lngth = space.decode_index4(w_item_or_slice, size)
-
-    coords = [0] * len(shape)
-    i = start
-    if order == 'C':
-        for s in range(len(shape) -1, -1, -1):
-            coords[s] = i % shape[s]
-            i //= shape[s]
-    else:
-        for s in range(len(shape)):
-            coords[s] = i % shape[s]
-            i //= shape[s]
-    return coords, step, lngth
-
-def shape_agreement(space, shape1, shape2):
-    ret = _shape_agreement(shape1, shape2)
-    if len(ret) < max(len(shape1), len(shape2)):
-        raise OperationError(space.w_ValueError,
-            space.wrap("operands could not be broadcast together with shapes (%s) (%s)" % (
-                ",".join([str(x) for x in shape1]),
-                ",".join([str(x) for x in shape2]),
-            ))
-        )
-    return ret
-
-def _shape_agreement(shape1, shape2):
-    """ Checks agreement about two shapes with respect to broadcasting. Returns
-    the resulting shape.
-    """
-    lshift = 0
-    rshift = 0
-    if len(shape1) > len(shape2):
-        m = len(shape1)
-        n = len(shape2)
-        rshift = len(shape2) - len(shape1)
-        remainder = shape1
-    else:
-        m = len(shape2)
-        n = len(shape1)
-        lshift = len(shape1) - len(shape2)
-        remainder = shape2
-    endshape = [0] * m
-    indices1 = [True] * m
-    indices2 = [True] * m
-    for i in range(m - 1, m - n - 1, -1):
-        left = shape1[i + lshift]
-        right = shape2[i + rshift]
-        if left == right:
-            endshape[i] = left
-        elif left == 1:
-            endshape[i] = right
-            indices1[i + lshift] = False
-        elif right == 1:
-            endshape[i] = left
-            indices2[i + rshift] = False
-        else:
-            return []
-            #raise OperationError(space.w_ValueError, space.wrap(
-            #    "frames are not aligned"))
-    for i in range(m - n):
-        endshape[i] = remainder[i]
-    return endshape
-
-def get_shape_from_iterable(space, old_size, w_iterable):
-    new_size = 0
-    new_shape = []
-    if space.isinstance_w(w_iterable, space.w_int):
-        new_size = space.int_w(w_iterable)
-        if new_size < 0:
-            new_size = old_size
-        new_shape = [new_size]
-    else:
-        neg_dim = -1
-        batch = space.listview(w_iterable)
-        new_size = 1
-        if len(batch) < 1:
-            if old_size == 1:
-                # Scalars can have an empty size.
-                new_size = 1
-            else:
-                new_size = 0
-        new_shape = []
-        i = 0
-        for elem in batch:
-            s = space.int_w(elem)
-            if s < 0:
-                if neg_dim >= 0:
-                    raise OperationError(space.w_ValueError, space.wrap(
-                             "can only specify one unknown dimension"))
-                s = 1
-                neg_dim = i
-            new_size *= s
-            new_shape.append(s)
-            i += 1
-        if neg_dim >= 0:
-            new_shape[neg_dim] = old_size / new_size
-            new_size *= new_shape[neg_dim]
-    if new_size != old_size:
-        raise OperationError(space.w_ValueError,
-                space.wrap("total size of new array must be unchanged"))
-    return new_shape
-
-# Recalculating strides. Find the steps that the iteration does for each
-# dimension, given the stride and shape. Then try to create a new stride that
-# fits the new shape, using those steps. If there is a shape/step mismatch
-# (meaning that the realignment of elements crosses from one step into another)
-# return None so that the caller can raise an exception.
-def calc_new_strides(new_shape, old_shape, old_strides, order):
-    # Return the proper strides for new_shape, or None if the mapping crosses
-    # stepping boundaries
-
-    # Assumes that prod(old_shape) == prod(new_shape), len(old_shape) > 1, and
-    # len(new_shape) > 0
-    steps = []
-    last_step = 1
-    oldI = 0
-    new_strides = []
-    if order == 'F':
-        for i in range(len(old_shape)):
-            steps.append(old_strides[i] / last_step)
-            last_step *= old_shape[i]
-        cur_step = steps[0]
-        n_new_elems_used = 1
-        n_old_elems_to_use = old_shape[0]
-        for s in new_shape:
-            new_strides.append(cur_step * n_new_elems_used)
-            n_new_elems_used *= s
-            while n_new_elems_used > n_old_elems_to_use:
-                oldI += 1
-                if steps[oldI] != steps[oldI - 1]:
-                    return None
-                n_old_elems_to_use *= old_shape[oldI]
-            if n_new_elems_used == n_old_elems_to_use:
-                oldI += 1
-                if oldI < len(old_shape):
-                    cur_step = steps[oldI]
-                    n_old_elems_to_use *= old_shape[oldI]
-    elif order == 'C':
-        for i in range(len(old_shape) - 1, -1, -1):
-            steps.insert(0, old_strides[i] / last_step)
-            last_step *= old_shape[i]
-        cur_step = steps[-1]
-        n_new_elems_used = 1
-        oldI = -1
-        n_old_elems_to_use = old_shape[-1]
-        for i in range(len(new_shape) - 1, -1, -1):
-            s = new_shape[i]
-            new_strides.insert(0, cur_step * n_new_elems_used)
-            n_new_elems_used *= s
-            while n_new_elems_used > n_old_elems_to_use:
-                oldI -= 1
-                if steps[oldI] != steps[oldI + 1]:
-                    return None
-                n_old_elems_to_use *= old_shape[oldI]
-            if n_new_elems_used == n_old_elems_to_use:
-                oldI -= 1
-                if oldI >= -len(old_shape):
-                    cur_step = steps[oldI]
-                    n_old_elems_to_use *= old_shape[oldI]
-    assert len(new_strides) == len(new_shape)
-    return new_strides
-
-
-def calculate_dot_strides(strides, backstrides, res_shape, skip_dims):
-    rstrides = []
-    rbackstrides = []
-    j=0
-    for i in range(len(res_shape)):
-        if i in skip_dims:
-            rstrides.append(0)
-            rbackstrides.append(0)
-        else:
-            rstrides.append(strides[j])
-            rbackstrides.append(backstrides[j])
-            j += 1
-    return rstrides, rbackstrides

pypy/module/_numpypy/test/test_numarray.py

 from pypy.conftest import option
 from pypy.interpreter.error import OperationError
 from pypy.module._numpypy.appbridge import get_appbridge_cache
-from pypy.module._numpypy.interp_iter import Chunk, Chunks
+#from pypy.module._numpypy.interp_iter import Chunk, Chunks
 #from pypy.module._numpypy.interp_numarray import W_NDimArray, shape_agreement
 from pypy.module._numpypy.test.test_base import BaseNumpyAppTest
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.