[pypy-commit] pypy default: merged upstream
jbs
noreply at buildbot.pypy.org
Wed Jun 27 23:40:26 CEST 2012
Author: jbs <jasper at dqi06.de>
Branch:
Changeset: r55865:f7fcfbf26301
Date: 2012-06-27 23:39 +0200
http://bitbucket.org/pypy/pypy/changeset/f7fcfbf26301/
Log: merged upstream
diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -163,6 +163,7 @@
'sum': 'app_numpy.sum',
'min': 'app_numpy.min',
'identity': 'app_numpy.identity',
+ 'eye': 'app_numpy.eye',
'max': 'app_numpy.max',
'arange': 'app_numpy.arange',
}
diff --git a/pypy/module/micronumpy/app_numpy.py b/pypy/module/micronumpy/app_numpy.py
--- a/pypy/module/micronumpy/app_numpy.py
+++ b/pypy/module/micronumpy/app_numpy.py
@@ -16,6 +16,26 @@
a[i][i] = 1
return a
+def eye(n, m=None, k=0, dtype=None):
+ if m is None:
+ m = n
+ a = _numpypy.zeros((n, m), dtype=dtype)
+ ni = 0
+ mi = 0
+
+ if k < 0:
+ p = n + k
+ ni = -k
+ else:
+ p = n - k
+ mi = k
+
+ while ni < n and mi < m:
+ a[ni][mi] = 1
+ ni += 1
+ mi += 1
+ return a
+
def sum(a,axis=None, out=None):
'''sum(a, axis=None)
Sum of array elements over a given axis.
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
@@ -1155,6 +1155,38 @@
assert d.shape == (3, 3)
assert d.dtype == dtype('int32')
assert (d == [[1, 0, 0], [0, 1, 0], [0, 0, 1]]).all()
+
+ def test_eye(self):
+ from _numpypy import eye, array
+ from _numpypy import int32, float64, dtype
+ a = eye(0)
+ assert len(a) == 0
+ assert a.dtype == dtype('float64')
+ assert a.shape == (0, 0)
+ b = eye(1, dtype=int32)
+ assert len(b) == 1
+ assert b[0][0] == 1
+ assert b.shape == (1, 1)
+ assert b.dtype == dtype('int32')
+ c = eye(2)
+ assert c.shape == (2, 2)
+ assert (c == [[1, 0], [0, 1]]).all()
+ d = eye(3, dtype='int32')
+ assert d.shape == (3, 3)
+ assert d.dtype == dtype('int32')
+ assert (d == [[1, 0, 0], [0, 1, 0], [0, 0, 1]]).all()
+ e = eye(3, 4)
+ assert e.shape == (3, 4)
+ assert (e == [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]]).all()
+ f = eye(2, 4, k=3)
+ assert f.shape == (2, 4)
+ assert (f == [[0, 0, 0, 1], [0, 0, 0, 0]]).all()
+ g = eye(3, 4, k=-1)
+ assert g.shape == (3, 4)
+ assert (g == [[0, 0, 0, 0], [1, 0, 0, 0], [0, 1, 0, 0]]).all()
+
+
+
def test_prod(self):
from _numpypy import array
More information about the pypy-commit
mailing list