[pypy-commit] pypy refactor-signature: have ForcedSignature instead of ArraySignature (it's the same otherwise),
fijal
noreply at buildbot.pypy.org
Thu Dec 15 10:42:12 CET 2011
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: refactor-signature
Changeset: r50537:c2da6bb0433f
Date: 2011-12-15 11:41 +0200
http://bitbucket.org/pypy/pypy/changeset/c2da6bb0433f/
Log: have ForcedSignature instead of ArraySignature (it's the same
otherwise), cut down on number of ops
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
@@ -855,7 +855,7 @@
def create_sig(self):
if self.forced_result is not None:
- return self.forced_result.create_sig()
+ return signature.ForcedSignature(self.forced_result.dtype)
return signature.Call1(self.ufunc, self.name, self.values.create_sig())
class Call2(VirtualArray):
@@ -881,7 +881,7 @@
def create_sig(self):
if self.forced_result is not None:
- return self.forced_result.create_sig()
+ return signature.ForcedSignature(self.forced_result.dtype)
return signature.Call2(self.ufunc, self.name, self.calc_dtype,
self.left.create_sig(),
self.right.create_sig())
@@ -1019,6 +1019,8 @@
""" A class representing contiguous array. We know that each iteration
by say ufunc will increase the data index by one
"""
+ _immutable_fields_ = ['storage']
+
def __init__(self, size, shape, dtype, order='C'):
BaseArray.__init__(self, shape, order)
self.size = size
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -91,7 +91,8 @@
shapelen=shapelen, self=self,
value=value, obj=obj, frame=frame,
dtype=dtype)
- value = self.func(dtype, value, sig.eval(frame, obj).convert_to(dtype))
+ assert isinstance(sig, ReduceSignature)
+ value = sig.binfunc(dtype, value, sig.eval(frame, obj).convert_to(dtype))
frame.next(shapelen)
return value
diff --git a/pypy/module/micronumpy/signature.py b/pypy/module/micronumpy/signature.py
--- a/pypy/module/micronumpy/signature.py
+++ b/pypy/module/micronumpy/signature.py
@@ -104,18 +104,34 @@
def _create_iter(self, iterlist, arr):
from pypy.module.micronumpy.interp_numarray import W_NDimArray
- arr = arr.get_concrete()
assert isinstance(arr, W_NDimArray)
if self.iter_no >= len(iterlist):
iterlist.append(ArrayIterator(arr.size))
def eval(self, frame, arr):
from pypy.module.micronumpy.interp_numarray import W_NDimArray
- arr = arr.get_concrete()
assert isinstance(arr, W_NDimArray)
iter = frame.iterators[self.iter_no]
return self.dtype.getitem(arr.storage, iter.offset)
+class ForcedSignature(ArraySignature):
+ def debug_repr(self):
+ return 'ForcedArray'
+
+ def _create_iter(self, iterlist, arr):
+ from pypy.module.micronumpy.interp_numarray import VirtualArray
+ assert isinstance(arr, VirtualArray)
+ arr = arr.forced_result
+ if self.iter_no >= len(iterlist):
+ iterlist.append(ArrayIterator(arr.size))
+
+ def eval(self, frame, arr):
+ from pypy.module.micronumpy.interp_numarray import VirtualArray
+ assert isinstance(arr, VirtualArray)
+ arr = arr.forced_result
+ iter = frame.iterators[self.iter_no]
+ return self.dtype.getitem(arr.storage, iter.offset)
+
class ScalarSignature(ConcreteSignature):
def debug_repr(self):
return 'Scalar'
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
@@ -190,14 +190,12 @@
# This is the sum of the ops for both loops, however if you remove the
# optimization then you end up with 2 float_adds, so we can still be
# sure it was optimized correctly.
- # XXX the comment above is wrong now. We need preferrably a way to
- # count the two loops separately
- py.test.skip(":(")
- self.check_resops({'setinteriorfield_raw': 4, 'guard_nonnull': 1, 'getfield_gc': 41,
- 'guard_class': 22, 'int_add': 8, 'float_mul': 2,
- 'guard_isnull': 2, 'jump': 4, 'int_ge': 4,
+ self.check_resops({'setinteriorfield_raw': 4, 'getfield_gc': 19,
+ 'getfield_gc_pure': 6,
+ 'guard_class': 8, 'int_add': 8, 'float_mul': 2,
+ 'jump': 4, 'int_ge': 4,
'getinteriorfield_raw': 4, 'float_add': 2, 'guard_false': 4,
- 'guard_value': 2})
+ })
def define_ufunc():
return """
More information about the pypy-commit
mailing list