summaryrefslogtreecommitdiff
path: root/numpy/tests/test_matlib.py
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-07-31 11:49:25 +0000
committerPauli Virtanen <pav@iki.fi>2010-07-31 11:49:25 +0000
commit62ebd8eb6a761fc7fc8e28f16b4c7a4a3d0465ac (patch)
treeb265bd7150a9f081a1eb3a04844f8e615805b5e4 /numpy/tests/test_matlib.py
parentd7bf2b58c6cd351a5a9400391ba5060ff669de4f (diff)
downloadnumpy-62ebd8eb6a761fc7fc8e28f16b4c7a4a3d0465ac.tar.gz
TST: Add tests for matlib. Closes #1242.
(From Ralf Gommers.)
Diffstat (limited to 'numpy/tests/test_matlib.py')
-rw-r--r--numpy/tests/test_matlib.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/numpy/tests/test_matlib.py b/numpy/tests/test_matlib.py
new file mode 100644
index 000000000..076676495
--- /dev/null
+++ b/numpy/tests/test_matlib.py
@@ -0,0 +1,53 @@
+import numpy as np
+import numpy.matlib
+from numpy.testing import assert_array_equal, assert_
+
+def test_empty():
+ x = np.matlib.empty((2,))
+ assert_(isinstance(x, np.matrix))
+ assert_(x.shape, (1,2))
+
+def test_ones():
+ assert_array_equal(np.matlib.ones((2, 3)),
+ np.matrix([[ 1., 1., 1.],
+ [ 1., 1., 1.]]))
+
+ assert_array_equal(np.matlib.ones(2), np.matrix([[ 1., 1.]]))
+
+def test_zeros():
+ assert_array_equal(np.matlib.zeros((2, 3)),
+ np.matrix([[ 0., 0., 0.],
+ [ 0., 0., 0.]]))
+
+ assert_array_equal(np.matlib.zeros(2), np.matrix([[ 0., 0.]]))
+
+def test_identity():
+ x = np.matlib.identity(2, dtype=np.int)
+ assert_array_equal(x, np.matrix([[1, 0], [0, 1]]))
+
+def test_eye():
+ x = np.matlib.eye(3, k=1, dtype=int)
+ assert_array_equal(x, np.matrix([[ 0, 1, 0],
+ [ 0, 0, 1],
+ [ 0, 0, 0]]))
+
+def test_rand():
+ x = np.matlib.rand(3)
+ # check matrix type, array would have shape (3,)
+ assert_(x.ndim == 2)
+
+def test_randn():
+ x = np.matlib.randn(3)
+ # check matrix type, array would have shape (3,)
+ assert_(x.ndim == 2)
+
+def test_repmat():
+ a1 = np.arange(4)
+ x = np.matlib.repmat(a1, 2, 2)
+ y = np.array([[0, 1, 2, 3, 0, 1, 2, 3],
+ [0, 1, 2, 3, 0, 1, 2, 3]])
+ assert_array_equal(x, y)
+
+
+if __name__ == "__main__":
+ run_module_suite()