diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2012-10-22 13:25:41 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2012-10-22 13:25:41 +0200 |
commit | dbe4468825bd1626cd3e90edcbf69a72df3d5180 (patch) | |
tree | 097fbbbbf4b41fe32c1fd7887302cb5d18648935 | |
parent | dc4e38bb792825d7da23500c01b1cbd9dc4595b5 (diff) | |
download | numpy-dbe4468825bd1626cd3e90edcbf69a72df3d5180.tar.gz |
TST: Check if contiguous flags are correct in various situations
-rw-r--r-- | numpy/core/tests/test_api.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/numpy/core/tests/test_api.py b/numpy/core/tests/test_api.py index 7c6b11850..df26dd07a 100644 --- a/numpy/core/tests/test_api.py +++ b/numpy/core/tests/test_api.py @@ -202,5 +202,37 @@ def test_copy_order(): res = np.copy(c, order='K') check_copy_result(res, c, ccontig=False, fcontig=False, strides=True) +def test_contiguous_flags(): + a = np.ones((4,4,1))[::2,:,:] + a.strides = a.strides[:2] + (-123,) + b = np.ones((2,2,1,2,2)).swapaxes(3,4) + + def check_contig(a, ccontig, fcontig): + assert_(a.flags.c_contiguous == ccontig) + assert_(a.flags.f_contiguous == fcontig) + + # Check if new arrays are correct: + check_contig(a, False, False) + check_contig(b, False, False) + check_contig(np.empty((2,2,0,2,2)), True, True) + check_contig(np.array([[[1],[2]]], order='F'), True, True) + check_contig(np.empty((2,2)), True, False) + check_contig(np.empty((2,2), order='F'), False, True) + + # Check that np.array creates correct contiguous flags: + check_contig(np.array(a, copy=False), False, False) + check_contig(np.array(a, copy=False, order='C'), True, False) + check_contig(np.array(a, ndmin=4, copy=False, order='F'), False, True) + + # Check slicing update of flags and : + check_contig(a[0], True, True) + check_contig(a[None,::4,...,None], True, True) + check_contig(b[0,0,...], False, True) + check_contig(b[:,:,0:0,:,:], True, True) + + # Test ravel and squeeze. + check_contig(a.ravel(), True, True) + check_contig(np.ones((1,3,1)).squeeze(), True, True) + if __name__ == "__main__": run_module_suite() |