Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r51365:5e43d79c76a7 Date: 2012-01-16 22:15 +0200 http://bitbucket.org/pypy/pypy/changeset/5e43d79c76a7/
Log: mere diff --git a/pypy/module/micronumpy/interp_iter.py b/pypy/module/micronumpy/interp_iter.py --- a/pypy/module/micronumpy/interp_iter.py +++ b/pypy/module/micronumpy/interp_iter.py @@ -157,6 +157,8 @@ offset += self.strides[i] break else: + if i == self.dim: + first_line = True indices[i] = 0 offset -= self.backstrides[i] else: 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 @@ -287,11 +287,11 @@ descr_rmod = _binop_right_impl("mod") def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False): - def impl(self, space, w_dim=None): - if space.is_w(w_dim, space.w_None): - w_dim = space.wrap(-1) + def impl(self, space, w_axis=None): + if space.is_w(w_axis, space.w_None): + w_axis = space.wrap(-1) return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space, - self, True, promote_to_largest, w_dim) + self, True, promote_to_largest, w_axis) return func_with_new_name(impl, "reduce_%s_impl" % ufunc_name) descr_sum = _reduce_ufunc_impl("add") @@ -569,14 +569,14 @@ ) return w_result - def descr_mean(self, space, w_dim=None): - if space.is_w(w_dim, space.w_None): - w_dim = space.wrap(-1) + def descr_mean(self, space, w_axis=None): + if space.is_w(w_axis, space.w_None): + w_axis = space.wrap(-1) w_denom = space.wrap(self.size) else: - dim = space.int_w(w_dim) + dim = space.int_w(w_axis) w_denom = space.wrap(self.shape[dim]) - return space.div(self.descr_sum_promote(space, w_dim), w_denom) + return space.div(self.descr_sum_promote(space, w_axis), w_denom) def descr_var(self, space): # var = mean((values - mean(values)) ** 2) diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -733,6 +733,7 @@ a = array(range(105)).reshape(3, 5, 7) b = mean(a, axis=0) b[0,0]==35. + assert a.mean(axis=0)[0, 0] == 35 assert (b == array(range(35, 70), dtype=float).reshape(5, 7)).all() assert (mean(a, 2) == array(range(0, 15), dtype=float).reshape(3, 5) * 7 + 3).all() @@ -755,6 +756,7 @@ assert array([]).sum() == 0.0 raises(ValueError, 'array([]).max()') assert (a.sum(0) == [30, 35, 40]).all() + assert (a.sum(axis=0) == [30, 35, 40]).all() assert (a.sum(1) == [3, 12, 21, 30, 39]).all() assert (a.max(0) == [12, 13, 14]).all() assert (a.max(1) == [2, 5, 8, 11, 14]).all() @@ -769,6 +771,8 @@ assert ((a + a).T.sum(2).T == (a + a).sum(0)).all() assert (a.reshape(1,-1).sum(0) == range(105)).all() assert (a.reshape(1,-1).sum(1) == 5460) + assert (array([[1,2],[3,4]]).prod(0) == [3, 8]).all() + assert (array([[1,2],[3,4]]).prod(1) == [2, 12]).all() def test_identity(self): from _numpypy import identity, array diff --git a/pypy/module/pypyjit/policy.py b/pypy/module/pypyjit/policy.py --- a/pypy/module/pypyjit/policy.py +++ b/pypy/module/pypyjit/policy.py @@ -127,7 +127,7 @@ 'imp', 'sys', 'array', '_ffi', 'itertools', 'operator', 'posix', '_socket', '_sre', '_lsprof', '_weakref', '__pypy__', 'cStringIO', '_collections', 'struct', - 'mmap', 'marshal']: + 'mmap', 'marshal', '_codecs']: if modname == 'pypyjit' and 'interp_resop' in rest: return False return True diff --git a/pypy/rpython/lltypesystem/rclass.py b/pypy/rpython/lltypesystem/rclass.py --- a/pypy/rpython/lltypesystem/rclass.py +++ b/pypy/rpython/lltypesystem/rclass.py @@ -510,7 +510,13 @@ ctype = inputconst(Void, self.object_type) cflags = inputconst(Void, flags) vlist = [ctype, cflags] - vptr = llops.genop('malloc', vlist, + cnonmovable = self.classdef.classdesc.read_attribute( + '_alloc_nonmovable_', Constant(False)) + if cnonmovable.value: + opname = 'malloc_nonmovable' + else: + opname = 'malloc' + vptr = llops.genop(opname, vlist, resulttype = Ptr(self.object_type)) ctypeptr = inputconst(CLASSTYPE, self.rclass.getvtable()) self.setfield(vptr, '__class__', ctypeptr, llops) diff --git a/pypy/rpython/test/test_rclass.py b/pypy/rpython/test/test_rclass.py --- a/pypy/rpython/test/test_rclass.py +++ b/pypy/rpython/test/test_rclass.py @@ -1130,6 +1130,18 @@ assert sorted([u]) == [6] # 32-bit types assert sorted([i, r, d, l]) == [2, 3, 4, 5] # 64-bit types + def test_nonmovable(self): + for (nonmovable, opname) in [(True, 'malloc_nonmovable'), + (False, 'malloc')]: + class A(object): + _alloc_nonmovable_ = nonmovable + def f(): + return A() + t, typer, graph = self.gengraph(f, []) + assert summary(graph) == {opname: 1, + 'cast_pointer': 1, + 'setfield': 1} + class TestOOtype(BaseTestRclass, OORtypeMixin): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit