[pypy-commit] pypy default: an attempt to improve nditer performance in simple cases
fijal
noreply at buildbot.pypy.org
Sun Nov 30 17:41:15 CET 2014
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r74763:9a68fb120de2
Date: 2014-11-30 18:40 +0200
http://bitbucket.org/pypy/pypy/changeset/9a68fb120de2/
Log: an attempt to improve nditer performance in simple cases
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
@@ -47,6 +47,7 @@
def setitem(self, index, value):
self.dtype.itemtype.store(self, index, 0, value)
+ @jit.unroll_safe
def setslice(self, space, arr):
if len(arr.get_shape()) > 0 and len(self.get_shape()) == 0:
raise oefmt(space.w_ValueError,
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -88,6 +88,21 @@
reds = 'auto')
def setslice(space, shape, target, source):
+ if not shape:
+ # XXX - simplify
+ target_iter, target_state = target.create_iter(shape)
+ source_iter, source_state = source.create_iter(shape)
+ dtype = target.dtype
+ val = source_iter.getitem(source_state)
+ if dtype.is_str_or_unicode():
+ val = dtype.coerce(space, val)
+ else:
+ val = val.convert_to(space, dtype)
+ target_iter.setitem(target_state, val)
+ return target
+ return _setslice(space, shape, target, source)
+
+def _setslice(space, shape, target, source):
# note that unlike everything else, target and source here are
# array implementations, not arrays
target_iter, target_state = target.create_iter(shape)
diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py
--- a/pypy/module/micronumpy/nditer.py
+++ b/pypy/module/micronumpy/nditer.py
@@ -1,3 +1,4 @@
+from rpython.rlib import jit
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
@@ -264,8 +265,8 @@
self.index = [0] * len(shape)
self.backward = backward
+ @jit.unroll_safe
def next(self):
- # TODO It's probably possible to refactor all the "next" method from each iterator
for i in range(len(self.shape) - 1, -1, -1):
if self.index[i] < self.shape[i] - 1:
self.index[i] += 1
More information about the pypy-commit
mailing list