Author: mattip
Branch: matrixmath-dot
Changeset: r50045:c40572851869
Date: 2011-12-01 00:17 +0200
http://bitbucket.org/pypy/pypy/changeset/c40572851869/
Log: shape matching, output creation implemented
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
@@ -513,10 +513,40 @@
w_other = convert_to_array(space, w_other)
if isinstance(w_other, Scalar):
return self.descr_mul(space, w_other)
- else:
+ elif len(self.shape) < 2 and len(w_other.shape) < 2:
w_res = self.descr_mul(space, w_other)
assert isinstance(w_res, BaseArray)
return w_res.descr_sum(space)
+ #Do the dims match?
+ my_critical_dim_size = self.shape[-1]
+ other_critical_dim_size = w_other.shape[0]
+ if len(w_other.shape) > 2:
+ other_critical_dim_size = w_other.shape[-2]
+ if my_critical_dim_size != other_critical_dim_size:
+ raise OperationError(space.w_ValueError, space.wrap(
+ "objects are not aligned"))
+ out_shape = self.shape[:-1] + w_other.shape[0:-2] + w_other.shape[-1:]
+ out_size = 1
+ for os in out_shape:
+ out_size *= os
+ dtype = interp_ufuncs.find_binop_result_dtype(space,
+ self.find_dtype(), w_other.find_dtype())
+ #TODO: what should the order be? C or F?
+ arr = NDimArray(out_size, out_shape, dtype=dtype)
+ return arr
+ out_iter = ArrayIterator(out_size)
+ me_iter = BroadcastIterator(self,self.shape[:len(self.size)-1] + [1])
+ other_iter = BroadcastIter(self,
+ w_other.shape[:-2] + [1] + w_other.shape[-1])
+ call2 = instantiate(Call2)
+ call2.left = self
+ call2.right = w_other
+ call2.calc_dtype = None
+ call2.size = my_critical_dim_size
+
+ while not out_iter.done():
+ pass
+
def get_concrete(self):
raise NotImplementedError
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
@@ -161,6 +161,7 @@
self.signature, w_lhs.signature, w_rhs.signature
])
new_shape = shape_agreement(space, w_lhs.shape, w_rhs.shape)
+ edf = jkl
w_res = Call2(new_sig, new_shape, calc_dtype,
res_dtype, w_lhs, w_rhs)
w_lhs.add_invalidates(w_res)
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
@@ -709,6 +709,7 @@
assert b.shape == (4, 3)
c = a.dot(b)
assert (c == [[[14, 38,62], [38, 126, 214], [62, 214, 366]],
+ [[86, 302, 518], [110, 390, 670], [134, 478, 822]]]).all()
def test_dot_constant(self):
from numpypy import array
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit