[pypy-commit] pypy numpy-setslice: setslice seems to be all working. needs more tests.
justinpeel
noreply at buildbot.pypy.org
Mon Jul 18 20:28:57 CEST 2011
Author: Justin Peel <notmuchtotell at gmail.com>
Branch: numpy-setslice
Changeset: r45720:2e37d616a1ee
Date: 2011-07-18 12:28 -0600
http://bitbucket.org/pypy/pypy/changeset/2e37d616a1ee/
Log: setslice seems to be all working. needs more tests.
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
@@ -402,6 +402,7 @@
BaseArray.__init__(self)
self.signature = signature
self.parent = parent
+ self.storage = parent.storage
self.invalidates = parent.invalidates
def get_concrete(self):
@@ -432,9 +433,14 @@
def __init__(self, start, stop, step, slice_length, parent, signature):
ViewArray.__init__(self, parent, signature)
- self.start = start
- self.stop = stop
- self.step = step
+ if isinstance(parent, SingleDimSlice):
+ self.start = parent.calc_index(start)
+ self.stop = parent.calc_index(stop)
+ self.step = parent.step * self.step
+ else:
+ self.start = start
+ self.stop = stop
+ self.step = step
self.size = slice_length
def find_size(self):
@@ -448,7 +454,7 @@
while i < stop:
slice_driver1.jit_merge_point(signature=signature, self=self,
step=step, stop=stop, i=i, j=j, arr=arr)
- self.parent.setitem(i, arr.eval(j))
+ self.storage[i] = arr.eval(j)
j += 1
i += step
@@ -460,21 +466,15 @@
while i > stop:
slice_driver2.jit_merge_point(signature=signature, self=self,
step=step, stop=stop, i=i, j=j, arr=arr)
- self.parent.setitem(i, arr.eval(j))
+ self.storage[i] = arr.eval(j)
j += 1
i += step
def setslice(self, space, start, stop, step, slice_length, arr):
- # can't set a slice of a slice yet
- if stop < 0:
- stop += self.find_size()
- if step > 0:
- stop = min(stop, self.find_size())
- else:
- stop = max(stop, 0)
arr = convert_to_array(space, arr)
start = self.calc_index(start)
- stop = self.calc_index(stop)
+ if stop != -1:
+ stop = self.calc_index(stop)
step = self.step * step
if step > 0:
self._sliceloop1(start, stop, step, arr)
@@ -553,12 +553,12 @@
def setslice(self, space, start, stop, step, slice_length, arr):
i = start
- if stop < 0:
- stop += self.find_size()
- if step > 0:
- stop = min(stop, self.find_size())
- else:
- stop = max(stop, 0)
+ #if stop < 0:
+ # stop += self.find_size()
+ #if step > 0:
+ # stop = min(stop, self.find_size())
+ #else:
+ # stop = max(stop, 0)
if not isinstance(arr, BaseArray):
arr = convert_to_array(space, arr)
if step > 0:
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
@@ -67,11 +67,16 @@
a[1:4:2] = b
assert a[1] == 0.
assert a[3] == 1.
- # a[1:4:2][::-1] = b # does not work yet
- c=a[1:4:2][::-1]
- c[:] = b
+ a[::2] = array([9., 10., 11.])
+ assert a[0] == 9.
+ assert a[2] == 10.
+ assert a[4] == 11.
+ a[1:4:2][::-1] = b
+ assert a[0] == 9.
assert a[1] == 1.
+ assert a[2] == 10.
assert a[3] == 0.
+ assert a[4] == 11.
def test_setslice_list(self):
from numpy import array
More information about the pypy-commit
mailing list