Author: Matti Picus <[email protected]>
Branch: ndarray-subtype
Changeset: r65185:6a19e19e18a7
Date: 2013-07-04 23:21 +0300
http://bitbucket.org/pypy/pypy/changeset/6a19e19e18a7/
Log: fix tests, fix obvious mistakes
diff --git a/pypy/module/micronumpy/base.py b/pypy/module/micronumpy/base.py
--- a/pypy/module/micronumpy/base.py
+++ b/pypy/module/micronumpy/base.py
@@ -41,7 +41,7 @@
impl = concrete.ConcreteArray(shape, dtype.base, order, strides,
backstrides)
if subtype:
- ret = space.allocate_instance(W_NDimArray, subtype)
+ ret = space.allocate_instance(W_NDimArray, space.type(subtype))
W_NDimArray.__init__(ret, impl)
return ret
return W_NDimArray(impl)
@@ -59,7 +59,7 @@
impl = concrete.ConcreteArrayNotOwning(shape, dtype, order,
strides,
backstrides, storage)
if subtype:
- ret = space.allocate_instance(W_NDimArray, subtype)
+ ret = space.allocate_instance(W_NDimArray, space.type(subtype))
W_NDimArray.__init__(ret, impl)
return ret
return W_NDimArray(impl)
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
@@ -454,8 +454,7 @@
s = s[1:]
dtype = interp_dtype.get_dtype_cache(space).dtypes_by_name[s]
contig = self.implementation.astype(space, dtype)
- assert isinstance(contig, W_NDimArray)
- return contig.implementation.argsort(space, w_axis)
+ return contig.argsort(space, w_axis)
def descr_astype(self, space, w_dtype):
dtype = space.interp_w(interp_dtype.W_Dtype,
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
@@ -182,7 +182,7 @@
if out:
dtype = out.get_dtype()
temp = W_NDimArray.from_shape(space, temp_shape, dtype,
- subtype=self)
+ subtype=obj)
elif keepdims:
shape = obj_shape[:axis] + [1] + obj_shape[axis + 1:]
else:
@@ -208,7 +208,7 @@
)
dtype = out.get_dtype()
else:
- out = W_NDimArray.from_shape(space, shape, dtype, subtype=self)
+ out = W_NDimArray.from_shape(space, shape, dtype, subtype=obj)
return loop.do_axis_reduce(shape, self.func, obj, dtype, axis, out,
self.identity, cumultative, temp)
if cumultative:
@@ -217,7 +217,7 @@
raise OperationError(space.w_ValueError, space.wrap(
"out of incompatible size"))
else:
- out = W_NDimArray.from_shape(space, [obj.get_size()], dtype,
subtype=self)
+ out = W_NDimArray.from_shape(space, [obj.get_size()], dtype,
subtype=obj)
loop.compute_reduce_cumultative(obj, out, dtype, self.func,
self.identity)
return out
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
@@ -24,8 +24,8 @@
def get_size(self):
return 1
-def create_slice(a, chunks):
- return Chunks(chunks).apply(W_NDimArray(a)).implementation
+def create_slice(space, a, chunks):
+ return Chunks(chunks).apply(space, W_NDimArray(a)).implementation
def create_array(*args, **kwargs):
@@ -46,100 +46,100 @@
return self.space.newtuple(args_w)
def test_strides_f(self):
- a = create_array([10, 5, 3], MockDtype(), order='F')
+ a = create_array(self.space, [10, 5, 3], MockDtype(), order='F')
assert a.strides == [1, 10, 50]
assert a.backstrides == [9, 40, 100]
def test_strides_c(self):
- a = create_array([10, 5, 3], MockDtype(), order='C')
+ a = create_array(self.space, [10, 5, 3], MockDtype(), order='C')
assert a.strides == [15, 3, 1]
assert a.backstrides == [135, 12, 2]
- a = create_array([1, 0, 7], MockDtype(), order='C')
+ a = create_array(self.space, [1, 0, 7], MockDtype(), order='C')
assert a.strides == [7, 7, 1]
assert a.backstrides == [0, 0, 6]
def test_create_slice_f(self):
- a = create_array([10, 5, 3], MockDtype(), order='F')
- s = create_slice(a, [Chunk(3, 0, 0, 1)])
+ a = create_array(self.space, [10, 5, 3], MockDtype(), order='F')
+ s = create_slice(self.space, a, [Chunk(3, 0, 0, 1)])
assert s.start == 3
assert s.strides == [10, 50]
assert s.backstrides == [40, 100]
- s = create_slice(a, [Chunk(1, 9, 2, 4)])
+ s = create_slice(self.space, a, [Chunk(1, 9, 2, 4)])
assert s.start == 1
assert s.strides == [2, 10, 50]
assert s.backstrides == [6, 40, 100]
- s = create_slice(a, [Chunk(1, 5, 3, 2), Chunk(1, 2, 1, 1), Chunk(1, 0,
0, 1)])
+ s = create_slice(self.space, a, [Chunk(1, 5, 3, 2), Chunk(1, 2, 1, 1),
Chunk(1, 0, 0, 1)])
assert s.shape == [2, 1]
assert s.strides == [3, 10]
assert s.backstrides == [3, 0]
- s = create_slice(a, [Chunk(0, 10, 1, 10), Chunk(2, 0, 0, 1)])
+ s = create_slice(self.space, a, [Chunk(0, 10, 1, 10), Chunk(2, 0, 0,
1)])
assert s.start == 20
assert s.shape == [10, 3]
def test_create_slice_c(self):
- a = create_array([10, 5, 3], MockDtype(), order='C')
- s = create_slice(a, [Chunk(3, 0, 0, 1)])
+ a = create_array(self.space, [10, 5, 3], MockDtype(), order='C')
+ s = create_slice(self.space, a, [Chunk(3, 0, 0, 1)])
assert s.start == 45
assert s.strides == [3, 1]
assert s.backstrides == [12, 2]
- s = create_slice(a, [Chunk(1, 9, 2, 4)])
+ s = create_slice(self.space, a, [Chunk(1, 9, 2, 4)])
assert s.start == 15
assert s.strides == [30, 3, 1]
assert s.backstrides == [90, 12, 2]
- s = create_slice(a, [Chunk(1, 5, 3, 2), Chunk(1, 2, 1, 1),
+ s = create_slice(self.space, a, [Chunk(1, 5, 3, 2), Chunk(1, 2, 1, 1),
Chunk(1, 0, 0, 1)])
assert s.start == 19
assert s.shape == [2, 1]
assert s.strides == [45, 3]
assert s.backstrides == [45, 0]
- s = create_slice(a, [Chunk(0, 10, 1, 10), Chunk(2, 0, 0, 1)])
+ s = create_slice(self.space, a, [Chunk(0, 10, 1, 10), Chunk(2, 0, 0,
1)])
assert s.start == 6
assert s.shape == [10, 3]
def test_slice_of_slice_f(self):
- a = create_array([10, 5, 3], MockDtype(), order='F')
- s = create_slice(a, [Chunk(5, 0, 0, 1)])
+ a = create_array(self.space, [10, 5, 3], MockDtype(), order='F')
+ s = create_slice(self.space, a, [Chunk(5, 0, 0, 1)])
assert s.start == 5
- s2 = create_slice(s, [Chunk(3, 0, 0, 1)])
+ s2 = create_slice(self.space, s, [Chunk(3, 0, 0, 1)])
assert s2.shape == [3]
assert s2.strides == [50]
assert s2.parent is a
assert s2.backstrides == [100]
assert s2.start == 35
- s = create_slice(a, [Chunk(1, 5, 3, 2)])
- s2 = create_slice(s, [Chunk(0, 2, 1, 2), Chunk(2, 0, 0, 1)])
+ s = create_slice(self.space, a, [Chunk(1, 5, 3, 2)])
+ s2 = create_slice(self.space, s, [Chunk(0, 2, 1, 2), Chunk(2, 0, 0,
1)])
assert s2.shape == [2, 3]
assert s2.strides == [3, 50]
assert s2.backstrides == [3, 100]
assert s2.start == 1 * 15 + 2 * 3
def test_slice_of_slice_c(self):
- a = create_array([10, 5, 3], MockDtype(), order='C')
- s = create_slice(a, [Chunk(5, 0, 0, 1)])
+ a = create_array(self.space, [10, 5, 3], MockDtype(), order='C')
+ s = create_slice(self.space, a, [Chunk(5, 0, 0, 1)])
assert s.start == 15 * 5
- s2 = create_slice(s, [Chunk(3, 0, 0, 1)])
+ s2 = create_slice(self.space, s, [Chunk(3, 0, 0, 1)])
assert s2.shape == [3]
assert s2.strides == [1]
assert s2.parent is a
assert s2.backstrides == [2]
assert s2.start == 5 * 15 + 3 * 3
- s = create_slice(a, [Chunk(1, 5, 3, 2)])
- s2 = create_slice(s, [Chunk(0, 2, 1, 2), Chunk(2, 0, 0, 1)])
+ s = create_slice(self.space, a, [Chunk(1, 5, 3, 2)])
+ s2 = create_slice(self.space, s, [Chunk(0, 2, 1, 2), Chunk(2, 0, 0,
1)])
assert s2.shape == [2, 3]
assert s2.strides == [45, 1]
assert s2.backstrides == [45, 2]
assert s2.start == 1 * 15 + 2 * 3
def test_negative_step_f(self):
- a = create_array([10, 5, 3], MockDtype(), order='F')
- s = create_slice(a, [Chunk(9, -1, -2, 5)])
+ a = create_array(self.space, [10, 5, 3], MockDtype(), order='F')
+ s = create_slice(self.space, a, [Chunk(9, -1, -2, 5)])
assert s.start == 9
assert s.strides == [-2, 10, 50]
assert s.backstrides == [-8, 40, 100]
def test_negative_step_c(self):
- a = create_array([10, 5, 3], MockDtype(), order='C')
- s = create_slice(a, [Chunk(9, -1, -2, 5)])
+ a = create_array(self.space, [10, 5, 3], MockDtype(), order='C')
+ s = create_slice(self.space, a, [Chunk(9, -1, -2, 5)])
assert s.start == 135
assert s.strides == [-30, 3, 1]
assert s.backstrides == [-120, 12, 2]
@@ -207,7 +207,8 @@
raw_storage_setitem(storage, i, rffi.cast(rffi.UCHAR, i))
#
dtypes = get_dtype_cache(self.space)
- w_array = W_NDimArray.from_shape_and_storage([2, 2], storage,
dtypes.w_int8dtype)
+ w_array = W_NDimArray.from_shape_and_storage(self.space, [2, 2],
+ storage, dtypes.w_int8dtype)
def get(i, j):
return w_array.getitem(self.space, [i, j]).value
assert get(0, 0) == 0
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit