[pypy-commit] pypy numpy-multidim: fix until all tests pass, except test_zjit
fijal
noreply at buildbot.pypy.org
Thu Oct 27 19:09:07 CEST 2011
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-multidim
Changeset: r48522:79e8268eceeb
Date: 2011-10-27 19:08 +0200
http://bitbucket.org/pypy/pypy/changeset/79e8268eceeb/
Log: fix until all tests pass, except test_zjit
diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -5,7 +5,7 @@
applevel_name = 'numpy'
interpleveldefs = {
- 'array': 'interp_numarray.SingleDimArray',
+ 'array': 'interp_numarray.NDimArray',
'dtype': 'interp_dtype.W_Dtype',
'ufunc': 'interp_ufuncs.W_Ufunc',
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
@@ -213,8 +213,7 @@
def descr_repr(self, space):
# Simple implementation so that we can see the array. Needs work.
concrete = self.get_concrete()
- #res = "array([" + ", ".join(concrete._getnums(False)) + "]"
- res = 'array()'
+ res = "array([" + ", ".join(concrete._getnums(False)) + "]"
dtype = concrete.find_dtype()
if (dtype is not space.fromcache(interp_dtype.W_Float64Dtype) and
dtype is not space.fromcache(interp_dtype.W_Int64Dtype)) or not self.find_size():
@@ -229,18 +228,27 @@
def _single_item_at_index(self, space, w_idx):
# we assume C ordering for now
- if len(self.shape) == 1:
- return space.int_w(w_idx)
+ if space.isinstance_w(w_idx, space.w_int):
+ idx = space.int_w(w_idx)
+ if idx < 0:
+ idx = self.shape[0] + idx
+ if idx < 0 or idx >= self.shape[0]:
+ raise OperationError(space.w_IndexError,
+ space.wrap("index out of range"))
+ return idx
index = [space.int_w(w_item)
for w_item in space.fixedview(w_idx)]
item = 0
for i in range(len(index)):
+ v = index[i]
+ if v < 0:
+ v += self.shape[i]
+ if v < 0 or v >= self.shape[i]:
+ raise OperationError(space.w_IndexError,
+ space.wrap("index (%d) out of range (0<=index<%d" % (index[i], self.shape[i])))
if i != 0:
item *= self.shape[i]
- if index[i] >= self.shape[i]:
- raise OperationError(space.w_IndexError,
- space.wrap("index (%d) out of range (0<=index<%d" % (index[i], self.shape[i])))
- item += index[i]
+ item += v
return item
def len_of_shape(self):
@@ -257,9 +265,10 @@
if shape_len == 1:
if space.isinstance_w(w_idx, space.w_int):
return True
- return False
- if (space.isinstance_w(w_idx, space.w_slice) or
- space.isinstance_w(w_idx, space.w_int)):
+ if space.isinstance_w(w_idx, space.w_slice):
+ return False
+ elif (space.isinstance_w(w_idx, space.w_slice) or
+ space.isinstance_w(w_idx, space.w_int)):
return False
lgt = space.len_w(w_idx)
if lgt > shape_len:
@@ -279,10 +288,10 @@
if (space.isinstance_w(w_idx, space.w_int) or
space.isinstance_w(w_idx, space.w_slice)):
start, stop, step, lgt = space.decode_index4(w_idx, self.shape[0])
- if lgt == 1:
+ if step == 0:
shape = self.shape[1:]
else:
- shape = self.shape
+ shape = [lgt] + self.shape[1:]
chunks = [(start, stop, step, lgt)]
else:
chunks = []
@@ -291,7 +300,7 @@
start, stop, step, lgt = space.decode_index4(w_item,
self.shape[i])
chunks.append((start, stop, step, lgt))
- if lgt == 1:
+ if step == 0:
shape[i] = -1
else:
shape[i] = lgt
@@ -368,8 +377,8 @@
"""
Class for representing virtual arrays, such as binary ops or ufuncs
"""
- def __init__(self, signature, res_dtype):
- BaseArray.__init__(self)
+ def __init__(self, signature, shape, res_dtype):
+ BaseArray.__init__(self, shape)
self.forced_result = None
self.signature = signature
self.res_dtype = res_dtype
@@ -419,8 +428,8 @@
class Call1(VirtualArray):
- def __init__(self, signature, res_dtype, values):
- VirtualArray.__init__(self, signature, res_dtype)
+ def __init__(self, signature, shape, res_dtype, values):
+ VirtualArray.__init__(self, signature, shape, res_dtype)
self.values = values
def _del_sources(self):
@@ -445,8 +454,8 @@
"""
Intermediate class for performing binary operations.
"""
- def __init__(self, signature, calc_dtype, res_dtype, left, right):
- VirtualArray.__init__(self, signature, res_dtype)
+ def __init__(self, signature, shape, calc_dtype, res_dtype, left, right):
+ VirtualArray.__init__(self, signature, shape, res_dtype)
self.left = left
self.right = right
self.calc_dtype = calc_dtype
@@ -505,7 +514,9 @@
raise NotImplementedError
def descr_len(self, space):
- return space.wrap(self.shape[0])
+ if self.shape:
+ return space.wrap(self.shape[0])
+ return space.wrap(1)
def calc_index(self, item):
raise NotImplementedError
@@ -531,10 +542,10 @@
return self.parent.find_dtype()
def setslice(self, space, w_value):
- assert isinstance(w_value, NDimArray)
- if self.shape != w_value.shape:
- raise OperationError(space.w_TypeError, space.wrap(
- "wrong assignment"))
+ if isinstance(w_value, NDimArray):
+ if self.shape != w_value.shape:
+ raise OperationError(space.w_TypeError, space.wrap(
+ "wrong assignment"))
self._sliceloop(w_value)
def _sliceloop(self, source):
@@ -575,7 +586,7 @@
item *= shape[k]
k += 1
start, stop, step, lgt = chunk
- if lgt == 1:
+ if step == 0:
# we don't consume an index
item += start
else:
diff --git a/pypy/module/micronumpy/interp_support.py b/pypy/module/micronumpy/interp_support.py
--- a/pypy/module/micronumpy/interp_support.py
+++ b/pypy/module/micronumpy/interp_support.py
@@ -19,7 +19,7 @@
"string length %d not divisable by %d" % (length, FLOAT_SIZE)))
dtype = space.fromcache(W_Float64Dtype)
- a = NDimArray(number, dtype=dtype)
+ a = NDimArray(number, [number], dtype=dtype)
start = 0
end = FLOAT_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
@@ -105,7 +105,7 @@
return self.func(res_dtype, w_obj.value.convert_to(res_dtype)).wrap(space)
new_sig = signature.Signature.find_sig([self.signature, w_obj.signature])
- w_res = Call1(new_sig, res_dtype, w_obj)
+ w_res = Call1(new_sig, w_obj.shape, res_dtype, w_obj)
w_obj.add_invalidates(w_res)
return w_res
@@ -147,7 +147,8 @@
new_sig = signature.Signature.find_sig([
self.signature, w_lhs.signature, w_rhs.signature
])
- w_res = Call2(new_sig, calc_dtype, res_dtype, w_lhs, w_rhs)
+ w_res = Call2(new_sig, w_lhs.shape or w_rhs.shape, calc_dtype,
+ res_dtype, w_lhs, w_rhs)
w_lhs.add_invalidates(w_res)
w_rhs.add_invalidates(w_res)
return w_res
diff --git a/pypy/module/micronumpy/test/test_base.py b/pypy/module/micronumpy/test/test_base.py
--- a/pypy/module/micronumpy/test/test_base.py
+++ b/pypy/module/micronumpy/test/test_base.py
@@ -13,7 +13,7 @@
def test_binop_signature(self, space):
float64_dtype = space.fromcache(interp_dtype.W_Float64Dtype)
- ar = NDimArray(10, dtype=float64_dtype)
+ ar = NDimArray(10, [10], dtype=float64_dtype)
v1 = ar.descr_add(space, ar)
v2 = ar.descr_add(space, Scalar(float64_dtype, 2.0))
assert v1.signature is not v2.signature
@@ -22,7 +22,7 @@
v4 = ar.descr_add(space, ar)
assert v1.signature is v4.signature
- bool_ar = NDimArray(10, dtype=space.fromcache(interp_dtype.W_BoolDtype))
+ bool_ar = NDimArray(10, [10], dtype=space.fromcache(interp_dtype.W_BoolDtype))
v5 = ar.descr_add(space, bool_ar)
assert v5.signature is not v1.signature
assert v5.signature is not v2.signature
@@ -30,7 +30,7 @@
assert v5.signature is v6.signature
def test_slice_signature(self, space):
- ar = NDimArray(10, dtype=space.fromcache(interp_dtype.W_Float64Dtype))
+ ar = NDimArray(10, [10], dtype=space.fromcache(interp_dtype.W_Float64Dtype))
v1 = ar.descr_getitem(space, space.wrap(slice(1, 5, 1)))
v2 = ar.descr_getitem(space, space.wrap(slice(4, 6, 1)))
assert v1.signature is v2.signature
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
@@ -42,6 +42,8 @@
b = a.copy()
for i in xrange(5):
assert b[i] == a[i]
+ a[3] = 22
+ assert b[3] == 3
def test_iterator_init(self):
from numpy import array
More information about the pypy-commit
mailing list