Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
test_matlib.py60 linesDownload Raw Back to tests
1import numpy as np
2import numpy.matlib
3from numpy.testing import assert_, assert_array_equal
4
5
6def test_empty():
7    x = numpy.matlib.empty((2,))
8    assert_(isinstance(x, np.matrix))
9    assert_(x.shape, (1, 2))
10
11def test_ones():
12    assert_array_equal(numpy.matlib.ones((2, 3)),
13                       np.matrix([[ 1.,  1.,  1.],
14                                  [ 1.,  1.,  1.]]))
15
16    assert_array_equal(numpy.matlib.ones(2), np.matrix([[ 1.,  1.]]))
17
18def test_zeros():
19    assert_array_equal(numpy.matlib.zeros((2, 3)),
20                       np.matrix([[ 0.,  0.,  0.],
21                                  [ 0.,  0.,  0.]]))
22
23    assert_array_equal(numpy.matlib.zeros(2), np.matrix([[0.,  0.]]))
24
25def test_identity():
26    x = numpy.matlib.identity(2, dtype=int)
27    assert_array_equal(x, np.matrix([[1, 0], [0, 1]]))
28
29def test_eye():
30    xc = numpy.matlib.eye(3, k=1, dtype=int)
31    assert_array_equal(xc, np.matrix([[ 0,  1,  0],
32                                      [ 0,  0,  1],
33                                      [ 0,  0,  0]]))
34    assert xc.flags.c_contiguous
35    assert not xc.flags.f_contiguous
36
37    xf = numpy.matlib.eye(3, 4, dtype=int, order='F')
38    assert_array_equal(xf, np.matrix([[ 1,  0,  0,  0],
39                                      [ 0,  1,  0,  0],
40                                      [ 0,  0,  1,  0]]))
41    assert not xf.flags.c_contiguous
42    assert xf.flags.f_contiguous
43
44def test_rand():
45    x = numpy.matlib.rand(3)
46    # check matrix type, array would have shape (3,)
47    assert_(x.ndim == 2)
48
49def test_randn():
50    x = np.matlib.randn(3)
51    # check matrix type, array would have shape (3,)
52    assert_(x.ndim == 2)
53
54def test_repmat():
55    a1 = np.arange(4)
56    x = numpy.matlib.repmat(a1, 2, 2)
57    y = np.array([[0, 1, 2, 3, 0, 1, 2, 3],
58                  [0, 1, 2, 3, 0, 1, 2, 3]])
59    assert_array_equal(x, y)
60 
codekingpro/portable-devtools · Team Ai