Author: Matti Picus <[email protected]>
Branch: mtrand
Changeset: r64967:cef553310960
Date: 2013-06-24 23:32 +0300
http://bitbucket.org/pypy/pypy/changeset/cef553310960/

Log:    test, implement functions as calls to random.xxx

diff --git a/lib_pypy/numpypy/random/__init__.py 
b/lib_pypy/numpypy/random/__init__.py
new file mode 100644
diff --git a/lib_pypy/numpypy/random/mtrand.py 
b/lib_pypy/numpypy/random/mtrand.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/numpypy/random/mtrand.py
@@ -0,0 +1,17 @@
+import random
+from numpypy import zeros
+def random_sample(length=0):
+    if length == 0:
+        return random.random()
+    ret = zeros((length,))
+    for x in xrange(length):
+        ret[x] = random.random()
+    return ret
+
+def randn(length=0):
+    if length == 0:
+        return random.gauss(0., 1.)
+    ret = zeros((length,))
+    for x in xrange(length):
+        ret[x] = random.gauss(0., 1.)
+    return ret
diff --git a/pypy/module/test_lib_pypy/numpypy/random/test_random.py 
b/pypy/module/test_lib_pypy/numpypy/random/test_random.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/test_lib_pypy/numpypy/random/test_random.py
@@ -0,0 +1,21 @@
+import py
+try:
+    import numpypy
+except:
+    pass
+
+def test_mtrand():
+    from numpy.random import mtrand
+    a = mtrand.random_sample()
+    assert isinstance(a, float)
+    a = mtrand.random_sample(10)
+    assert a.shape == (10,)
+
+def test_randn():
+    from numpy.random.mtrand import randn
+    from numpy import array
+    a = array([randn() for i in xrange(1000)])
+    b = randn(1000)
+    assert -0.1 < a.mean() < 0.1
+    assert -0.1 < b.mean() < 0.1
+    assert b.shape == (1000,)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to