[pypy-commit] pypy matrixmath-dot: test for slice of transposed array fails
mattip
noreply at buildbot.pypy.org
Fri Jan 20 15:41:52 CET 2012
Author: mattip
Branch: matrixmath-dot
Changeset: r51540:bb1838ae2306
Date: 2012-01-20 16:40 +0200
http://bitbucket.org/pypy/pypy/changeset/bb1838ae2306/
Log: test for slice of transposed array fails
diff --git a/pypy/module/micronumpy/dot.py b/pypy/module/micronumpy/dot.py
--- a/pypy/module/micronumpy/dot.py
+++ b/pypy/module/micronumpy/dot.py
@@ -6,10 +6,13 @@
from pypy.rlib import jit
+def dot_printable_location(shapelen, sig):
+ return 'numpy dot [%d dims]' % (shapelen)
+
dot_driver = jit.JitDriver(
greens=['shape_len', 'left'],
- reds=['lefti', 'righti', 'outi', 'result', 'right'],
- get_printable_location=new_printable_location('dot'),
+ reds=['lefti', 'righti', 'outi', 'result', 'right','sig','dtype'],
+ get_printable_location=dot_printable_location,
name='dot',
)
@@ -41,31 +44,35 @@
''' assumes left, right are concrete arrays
given left.shape == [3, 5, 7],
right.shape == [2, 7, 4]
+ then
result.shape == [3, 5, 2, 4]
- broadcast shape should be [3, 5, 2, 7, 4]
- result should skip dims 3 which is results.ndims - 1
- left should skip 2, 4 which is a.ndims-1 + range(right.ndims)
+ broadcast shape should be [3, 5, 2, 7, 4]
+ result should skip dims 3 which is len(result_shape) - 1
+ (note that if right is 1d, result should
+ skip len(result_shape))
+ left should skip 2, 4 which is a.ndims-1 + range(right.ndims)
except where it==(right.ndims-2)
- right should skip 0, 1
+ right should skip 0, 1
'''
- mul = interp_ufuncs.get(space).multiply.func
- add = interp_ufuncs.get(space).add.func
broadcast_shape = left.shape[:-1] + right.shape
+ shape_len = len(broadcast_shape)
left_skip = [len(left.shape) - 1 + i for i in range(len(right.shape))
if i != right_critical_dim]
right_skip = range(len(left.shape) - 1)
- result_skip = [len(result.shape) - 1]
- shape_len = len(broadcast_shape)
+ result_skip = [len(result.shape) - (len(right.shape) > 1)]
_r = calculate_dot_strides(result.strides, result.backstrides,
broadcast_shape, result_skip)
- outi = ViewIterator(0, _r[0], _r[1], broadcast_shape)
+ outi = ViewIterator(result.start, _r[0], _r[1], broadcast_shape)
_r = calculate_dot_strides(left.strides, left.backstrides,
broadcast_shape, left_skip)
- lefti = ViewIterator(0, _r[0], _r[1], broadcast_shape)
+ lefti = ViewIterator(left.start, _r[0], _r[1], broadcast_shape)
_r = calculate_dot_strides(right.strides, right.backstrides,
broadcast_shape, right_skip)
- righti = ViewIterator(0, _r[0], _r[1], broadcast_shape)
+ righti = ViewIterator(right.start, _r[0], _r[1], broadcast_shape)
+ if right.size==4:
+ xxx
while not outi.done():
+ '''
dot_driver.jit_merge_point(left=left,
right=right,
shape_len=shape_len,
@@ -73,10 +80,17 @@
righti=righti,
outi=outi,
result=result,
+ dtype=dtype,
+ sig=None, #For get_printable_location
)
- v = mul(dtype, left.getitem(lefti.offset),
- right.getitem(righti.offset))
- value = add(dtype, v, result.getitem(outi.offset))
+ '''
+ lval = left.getitem(lefti.offset).convert_to(dtype)
+ rval = right.getitem(righti.offset).convert_to(dtype)
+ outval = result.getitem(outi.offset).convert_to(dtype)
+ v = dtype.itemtype.mul(lval, rval)
+ value = dtype.itemtype.add(v, outval)
+ #Do I need to convert it to result.dtype or does settiem do that?
+ assert outi.offset < result.size
result.setitem(outi.offset, value)
outi = outi.next(shape_len)
righti = righti.next(shape_len)
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
@@ -890,7 +890,7 @@
c = dot(a, b)
assert (c == [[[14, 38, 62], [38, 126, 214], [62, 214, 366]],
[[86, 302, 518], [110, 390, 670], [134, 478, 822]]]).all()
- c = dot(a, b[:, :, 2])
+ c = dot(a, b[:, 2])
assert (c == [[38, 126, 214], [302, 390, 478]]).all()
def test_dot_constant(self):
More information about the pypy-commit
mailing list