Author: Maciej Fijalkowski <[email protected]>
Branch: numpy-refactor
Changeset: r57283:400b62643b06
Date: 2012-09-11 14:53 +0200
http://bitbucket.org/pypy/pypy/changeset/400b62643b06/
Log: cleanup
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
@@ -1,17 +1,4 @@
-from pypy.module.micronumpy.strides import calculate_dot_strides
from pypy.interpreter.error import OperationError
-from pypy.rlib import jit
-
-def dot_printable_location(shapelen):
- return 'numpy dot [%d]' % shapelen
-
-dot_driver = jit.JitDriver(
- greens=['shapelen'],
- reds=['lefti', 'righti', 'outi', 'result', 'right', 'dtype',
- 'left'],
- get_printable_location=dot_printable_location,
- name='dot',
-)
def match_dot_shapes(space, left, right):
left_shape = left.get_shape()
diff --git a/pypy/module/micronumpy/test/test_arrayops.py
b/pypy/module/micronumpy/test/test_arrayops.py
--- a/pypy/module/micronumpy/test/test_arrayops.py
+++ b/pypy/module/micronumpy/test/test_arrayops.py
@@ -40,3 +40,46 @@
b = where(a > 0, ones(5), zeros(5))
a[0] = 0
assert (b == [1, 1, 1, 0, 0]).all()
+
+
+ def test_dot(self):
+ from _numpypy import array, dot, arange
+ a = array(range(5))
+ assert dot(a, a) == 30.0
+
+ a = array(range(5))
+ assert a.dot(range(5)) == 30
+ assert dot(range(5), range(5)) == 30
+ assert (dot(5, [1, 2, 3]) == [5, 10, 15]).all()
+
+ a = arange(12).reshape(3, 4)
+ b = arange(12).reshape(4, 3)
+ c = a.dot(b)
+ assert (c == [[ 42, 48, 54], [114, 136, 158], [186, 224, 262]]).all()
+
+ a = arange(24).reshape(2, 3, 4)
+ 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 = 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])
+ assert (c == [[62, 214, 366], [518, 670, 822]]).all()
+ a = arange(3*2*6).reshape((3,2,6))
+ b = arange(3*2*6)[::-1].reshape((2,6,3))
+ assert dot(a, b)[2,0,1,2] == 1140
+ assert (dot([[1,2],[3,4]],[5,6]) == [17, 39]).all()
+
+ def test_dot_constant(self):
+ from _numpypy import array, dot
+ a = array(range(5))
+ b = a.dot(2.5)
+ for i in xrange(5):
+ assert b[i] == 2.5 * a[i]
+ c = dot(4, 3.0)
+ assert c == 12.0
+ c = array(3.0).dot(array(4))
+ assert c == 12.0
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
@@ -1262,48 +1262,6 @@
c = array([])
assert c.any() == False
- def test_dot(self):
- from _numpypy import array, dot, arange
- a = array(range(5))
- assert dot(a, a) == 30.0
-
- a = array(range(5))
- assert a.dot(range(5)) == 30
- assert dot(range(5), range(5)) == 30
- assert (dot(5, [1, 2, 3]) == [5, 10, 15]).all()
-
- a = arange(12).reshape(3, 4)
- b = arange(12).reshape(4, 3)
- c = a.dot(b)
- assert (c == [[ 42, 48, 54], [114, 136, 158], [186, 224, 262]]).all()
-
- a = arange(24).reshape(2, 3, 4)
- 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 = 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])
- assert (c == [[62, 214, 366], [518, 670, 822]]).all()
- a = arange(3*2*6).reshape((3,2,6))
- b = arange(3*2*6)[::-1].reshape((2,6,3))
- assert dot(a, b)[2,0,1,2] == 1140
- assert (dot([[1,2],[3,4]],[5,6]) == [17, 39]).all()
-
- def test_dot_constant(self):
- from _numpypy import array, dot
- a = array(range(5))
- b = a.dot(2.5)
- for i in xrange(5):
- assert b[i] == 2.5 * a[i]
- c = dot(4, 3.0)
- assert c == 12.0
- c = array(3.0).dot(array(4))
- assert c == 12.0
-
def test_dtype_guessing(self):
from _numpypy import array, dtype, float64, int8, bool_
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit