Chris@87
|
1 from __future__ import division, absolute_import, print_function
|
Chris@87
|
2
|
Chris@87
|
3 import numpy as np
|
Chris@87
|
4 import numpy.matlib
|
Chris@87
|
5 from numpy.testing import assert_array_equal, assert_, run_module_suite
|
Chris@87
|
6
|
Chris@87
|
7 def test_empty():
|
Chris@87
|
8 x = np.matlib.empty((2,))
|
Chris@87
|
9 assert_(isinstance(x, np.matrix))
|
Chris@87
|
10 assert_(x.shape, (1, 2))
|
Chris@87
|
11
|
Chris@87
|
12 def test_ones():
|
Chris@87
|
13 assert_array_equal(np.matlib.ones((2, 3)),
|
Chris@87
|
14 np.matrix([[ 1., 1., 1.],
|
Chris@87
|
15 [ 1., 1., 1.]]))
|
Chris@87
|
16
|
Chris@87
|
17 assert_array_equal(np.matlib.ones(2), np.matrix([[ 1., 1.]]))
|
Chris@87
|
18
|
Chris@87
|
19 def test_zeros():
|
Chris@87
|
20 assert_array_equal(np.matlib.zeros((2, 3)),
|
Chris@87
|
21 np.matrix([[ 0., 0., 0.],
|
Chris@87
|
22 [ 0., 0., 0.]]))
|
Chris@87
|
23
|
Chris@87
|
24 assert_array_equal(np.matlib.zeros(2), np.matrix([[ 0., 0.]]))
|
Chris@87
|
25
|
Chris@87
|
26 def test_identity():
|
Chris@87
|
27 x = np.matlib.identity(2, dtype=np.int)
|
Chris@87
|
28 assert_array_equal(x, np.matrix([[1, 0], [0, 1]]))
|
Chris@87
|
29
|
Chris@87
|
30 def test_eye():
|
Chris@87
|
31 x = np.matlib.eye(3, k=1, dtype=int)
|
Chris@87
|
32 assert_array_equal(x, np.matrix([[ 0, 1, 0],
|
Chris@87
|
33 [ 0, 0, 1],
|
Chris@87
|
34 [ 0, 0, 0]]))
|
Chris@87
|
35
|
Chris@87
|
36 def test_rand():
|
Chris@87
|
37 x = np.matlib.rand(3)
|
Chris@87
|
38 # check matrix type, array would have shape (3,)
|
Chris@87
|
39 assert_(x.ndim == 2)
|
Chris@87
|
40
|
Chris@87
|
41 def test_randn():
|
Chris@87
|
42 x = np.matlib.randn(3)
|
Chris@87
|
43 # check matrix type, array would have shape (3,)
|
Chris@87
|
44 assert_(x.ndim == 2)
|
Chris@87
|
45
|
Chris@87
|
46 def test_repmat():
|
Chris@87
|
47 a1 = np.arange(4)
|
Chris@87
|
48 x = np.matlib.repmat(a1, 2, 2)
|
Chris@87
|
49 y = np.array([[0, 1, 2, 3, 0, 1, 2, 3],
|
Chris@87
|
50 [0, 1, 2, 3, 0, 1, 2, 3]])
|
Chris@87
|
51 assert_array_equal(x, y)
|
Chris@87
|
52
|
Chris@87
|
53
|
Chris@87
|
54 if __name__ == "__main__":
|
Chris@87
|
55 run_module_suite()
|