Author: mattip Branch: matrixmath-dot Changeset: r50044:1780af5403c8 Date: 2011-11-30 23:08 +0200 http://bitbucket.org/pypy/pypy/changeset/1780af5403c8/
Log: copy/paste test and doc string from numpy 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 @@ -501,6 +501,15 @@ descr_argmin = _reduce_argmax_argmin_impl("min") def descr_dot(self, space, w_other): + '''Dot product of two arrays. + + For 2-D arrays it is equivalent to matrix multiplication, and for 1-D + arrays to inner product of vectors (without complex conjugation). For + N dimensions it is a sum product over the last axis of `a` and + the second-to-last of `b`:: + + dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])''' + #numpy's doc string :) w_other = convert_to_array(space, w_other) if isinstance(w_other, Scalar): return self.descr_mul(space, w_other) 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 @@ -700,6 +700,15 @@ assert a.dot(range(5)) == 30 assert dot(range(5), range(5)) == 30 assert (dot(5, [1, 2, 3]) == [5, 10, 15]).all() + a = array([[range(4), range(4, 8), range(8, 12)], + [range(12, 16),range(16, 20),range(20, 24)]]) + raises(ValueError,"a.dot(a)") + b = a[0, :, :].T + #Superfluous shape test makes the intention of the test clearer + assert a.shape == (2, 3, 4) + assert b.shape == (4, 3) + c = a.dot(b) + assert (c == [[[14, 38,62], [38, 126, 214], [62, 214, 366]], def test_dot_constant(self): from numpypy import array _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit