[pypy-commit] pypy numpypy-axisops: cleanup but no real progress
mattip
noreply at buildbot.pypy.org
Sun Jan 8 23:22:03 CET 2012
Author: mattip
Branch: numpypy-axisops
Changeset: r51151:de99533d42d0
Date: 2012-01-09 00:20 +0200
http://bitbucket.org/pypy/pypy/changeset/de99533d42d0/
Log: cleanup but no real progress
diff --git a/pypy/module/micronumpy/app_numpy.py b/pypy/module/micronumpy/app_numpy.py
--- a/pypy/module/micronumpy/app_numpy.py
+++ b/pypy/module/micronumpy/app_numpy.py
@@ -58,10 +58,10 @@
a = numpypy.array(a)
return a.min()
-def max(a):
+def max(a, axis=None):
if not hasattr(a, "max"):
a = numpypy.array(a)
- return a.max()
+ return a.max(axis)
def arange(start, stop=None, step=1, dtype=None):
'''arange([start], stop[, step], dtype=None)
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
@@ -39,8 +39,8 @@
axisreduce_driver = jit.JitDriver(
greens=['shapelen', 'sig'],
virtualizables=['frame'],
- reds=['self','result', 'ri', 'frame', 'nextval', 'dtype', 'value'],
- get_printable_location=signature.new_printable_location('reduce'),
+ reds=['identity', 'self','result', 'ri', 'frame', 'nextval', 'dtype', 'value'],
+ get_printable_location=signature.new_printable_location('axisreduce'),
)
@@ -692,6 +692,7 @@
# to allow garbage-collecting them
raise NotImplementedError
+ @jit.unroll_safe
def compute(self):
result = W_NDimArray(self.size, self.shape, self.find_dtype())
shapelen = len(self.shape)
@@ -757,6 +758,8 @@
class Reduce(VirtualArray):
+ _immutable_fields_ = ['dim', 'binfunc', 'dtype', 'identity']
+
def __init__(self, binfunc, name, dim, res_dtype, values, identity=None):
shape = values.shape[0:dim] + values.shape[dim + 1:len(values.shape)]
VirtualArray.__init__(self, name, shape, res_dtype)
@@ -789,11 +792,13 @@
value = self.identity.convert_to(self.dtype)
return value
+ @jit.unroll_safe
def compute(self):
dtype = self.dtype
result = W_NDimArray(self.size, self.shape, dtype)
self.values = self.values.get_concrete()
shapelen = len(result.shape)
+ identity = self.identity
sig = self.find_sig(res_shape=result.shape, arr=self.values)
ri = ArrayIterator(result.size)
frame = sig.create_frame(self.values, dim=self.dim)
@@ -804,9 +809,14 @@
value=value, sig=sig,
shapelen=shapelen, ri=ri,
nextval=nextval, dtype=dtype,
+ identity=identity,
result=result)
if frame.iterators[0].axis_done:
- value = self.get_identity(sig, frame, shapelen)
+ if identity is None:
+ value = sig.eval(frame, self.values).convert_to(dtype)
+ frame.next(shapelen)
+ else:
+ value = identity.convert_to(dtype)
ri = ri.next(shapelen)
assert isinstance(sig, signature.ReduceSignature)
nextval = sig.eval(frame, self.values).convert_to(dtype)
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
@@ -744,13 +744,11 @@
from numpypy import arange
a = arange(15).reshape(5, 3)
assert a.sum() == 105
+ assert a.max() == 14
assert (a.sum(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()
- b = a.copy()
- #b should be an array, not a view
- assert (b.sum(1) == [3, 12, 21, 30, 39]).all()
def test_identity(self):
from numpypy import identity, array
diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -127,9 +127,17 @@
def test_axissum(self):
result = self.run("axissum")
assert result == 30
- self.check_simple_loop({"getinteriorfield_raw": 2, "float_add": 2,
- "int_add": 1, "int_ge": 1, "guard_false": 1,
- "jump": 1, 'arraylen_gc': 1})
+ self.check_simple_loop({'arraylen_gc': 1,
+ 'call': 1,
+ 'getfield_gc': 3,
+ "getinteriorfield_raw": 1,
+ "guard_class": 1,
+ "guard_false": 2,
+ 'guard_no_exception': 1,
+ "float_add": 1,
+ "jump": 1,
+ 'setinteriorfield_raw': 1,
+ })
def define_prod():
return """
More information about the pypy-commit
mailing list