diff options
author | Nathaniel J. Smith <njs@pobox.com> | 2012-10-01 17:36:01 +0100 |
---|---|---|
committer | Nathaniel J. Smith <njs@pobox.com> | 2012-10-01 17:36:01 +0100 |
commit | 1a71edc55b227e590022d402e5b6558d3a9921f1 (patch) | |
tree | aebff885c98c49db41eebf18d718d6e9840d0536 /numpy/lib/tests/test_function_base.py | |
parent | e18e7441700db0ff2fd8f51901aa416c63e35cbc (diff) | |
download | numpy-1a71edc55b227e590022d402e5b6558d3a9921f1.tar.gz |
[FIX] preserve memory order in np.copy()
This switches us back to the behaviour seen in numpy 1.6 and earlier,
which it turns out that scikit-learn (and probably others) relied on.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index da3eb2b84..49544b22b 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -42,6 +42,32 @@ class TestAll(TestCase): assert_array_equal(np.alltrue(y1, axis=1), [0, 0, 1]) +class TestCopy(TestCase): + def test_basic(self): + a = np.array([[1, 2], [3, 4]]) + a_copy = np.copy(a) + assert_array_equal(a, a_copy) + a_copy[0, 0] = 10 + assert_equal(a[0, 0], 1) + assert_equal(a_copy[0, 0], 10) + + def test_order(self): + # It turns out that people rely on np.copy() preserving order by + # default; changing this broke scikit-learn: + # https://github.com/scikit-learn/scikit-learn/commit/7842748cf777412c506a8c0ed28090711d3a3783 + a = np.array([[1, 2], [3, 4]]) + assert_(a.flags.c_contiguous) + assert_(not a.flags.f_contiguous) + a_fort = np.array([[1, 2], [3, 4]], order="F") + assert_(not a_fort.flags.c_contiguous) + assert_(a_fort.flags.f_contiguous) + a_copy = np.copy(a) + assert_(a_copy.flags.c_contiguous) + assert_(not a_copy.flags.f_contiguous) + a_fort_copy = np.copy(a_fort) + assert_(not a_fort_copy.flags.c_contiguous) + assert_(a_fort_copy.flags.f_contiguous) + class TestAverage(TestCase): def test_basic(self): y1 = np.array([1, 2, 3]) |