diff options
author | alex <argriffi@ncsu.edu> | 2014-07-31 20:23:56 -0400 |
---|---|---|
committer | alex <argriffi@ncsu.edu> | 2014-07-31 20:23:56 -0400 |
commit | fdedd16f31ee8f35b500d3585bf934b97154d878 (patch) | |
tree | e096bb7c8f6f2018157a48213ad54c9d117761e9 /numpy/matrixlib/tests/test_defmatrix.py | |
parent | 7bfa929d3ce90f647dd4e4e228312491df517928 (diff) | |
download | numpy-fdedd16f31ee8f35b500d3585bf934b97154d878.tar.gz |
MAINT: restore optional ravel order and add tests and more docstring lines
Diffstat (limited to 'numpy/matrixlib/tests/test_defmatrix.py')
-rw-r--r-- | numpy/matrixlib/tests/test_defmatrix.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py index a06a564aa..d2a89bd51 100644 --- a/numpy/matrixlib/tests/test_defmatrix.py +++ b/numpy/matrixlib/tests/test_defmatrix.py @@ -386,6 +386,7 @@ class TestNewScalarIndexing(TestCase): assert_array_equal(x[:, [1, 0]], x[:, ::-1]) assert_array_equal(x[[2, 1, 0],:], x[::-1,:]) + class TestPower(TestCase): def test_returntype(self): a = array([[0, 1], [0, 0]]) @@ -396,5 +397,51 @@ class TestPower(TestCase): def test_list(self): assert_array_equal(matrix_power([[0, 1], [0, 0]], 2), [[0, 0], [0, 0]]) + +class TestShape(TestCase): + def setUp(self): + self.a = array([[1], [2]]) + self.m = matrix([[1], [2]]) + + def test_shape(self): + assert_equal(self.a.shape, (2, 1)) + assert_equal(self.m.shape, (2, 1)) + + def test_numpy_ravel(self): + assert_equal(np.ravel(self.a).shape, (2,)) + assert_equal(np.ravel(self.m).shape, (2,)) + + def test_member_ravel(self): + assert_equal(self.a.ravel().shape, (2,)) + assert_equal(self.m.ravel().shape, (1, 2)) + + def test_member_flatten(self): + assert_equal(self.a.flatten().shape, (2,)) + assert_equal(self.m.flatten().shape, (1, 2)) + + def test_numpy_ravel_order(self): + for t in array, matrix: + x = t([[1, 2, 3], [4, 5, 6]]) + assert_equal(np.ravel(x), [1, 2, 3, 4, 5, 6]) + assert_equal(np.ravel(x, order='F'), [1, 4, 2, 5, 3, 6]) + assert_equal(np.ravel(x.T), [1, 4, 2, 5, 3, 6]) + assert_equal(np.ravel(x.T, order='A'), [1, 2, 3, 4, 5, 6]) + + def test_matrix_ravel_order(self): + x = matrix([[1, 2, 3], [4, 5, 6]]) + assert_equal(x.ravel(), [[1, 2, 3, 4, 5, 6]]) + assert_equal(x.ravel(order='F'), [[1, 4, 2, 5, 3, 6]]) + assert_equal(x.T.ravel(), [[1, 4, 2, 5, 3, 6]]) + assert_equal(x.T.ravel(order='A'), [[1, 2, 3, 4, 5, 6]]) + + def test_array_memory_sharing(self): + assert_(np.may_share_memory(self.a, self.a.ravel())) + assert_(not np.may_share_memory(self.a, self.a.flatten())) + + def test_matrix_memory_sharing(self): + assert_(np.may_share_memory(self.m, self.m.ravel())) + assert_(not np.may_share_memory(self.m, self.m.flatten())) + + if __name__ == "__main__": run_module_suite() |