From e37a90c8bd1bf99f89b537ce47492095d6ae147c Mon Sep 17 00:00:00 2001 From: "Per A. Brodtkorb" Date: Tue, 13 Dec 2011 23:01:22 +0100 Subject: ENH: enhance meshgrid to generate 3D grids, sparse grids, matrix indexing. --- numpy/lib/tests/test_function_base.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index ba6b336ff..af85be326 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1025,6 +1025,24 @@ class TestMeshgrid(TestCase): [5, 5, 5], [6, 6, 6], [7, 7, 7]]))) + def test_indexing(self): + [X, Y] = meshgrid([1, 2, 3], [4, 5, 6, 7], indexing='ij') + assert_(all(X == array([[1, 1, 1, 1], + [2, 2, 2, 2], + [3, 3, 3, 3]]))) + assert_(all(Y == array([[4, 5, 6, 7], + [4, 5, 6, 7], + [4, 5, 6, 7]]))) + + def test_sparse(self): + [X, Y] = meshgrid([1, 2, 3], [4, 5, 6, 7], sparse=True) + assert_(all(X == array([[1, 2, 3]]))) + assert_(all(Y == array([[4], + [5], + [6], + [7]]))) + + class TestPiecewise(TestCase): -- cgit v1.2.1 From 37d723cb629e3e8cb4d9ed7b85702fbd6350818d Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Tue, 13 Dec 2011 23:24:47 +0100 Subject: MAINT: clean up docstring and some minor items in meshgrid. Remove ndgrid. --- numpy/lib/tests/test_function_base.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index af85be326..83532e70d 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1043,8 +1043,6 @@ class TestMeshgrid(TestCase): [7]]))) - - class TestPiecewise(TestCase): def test_simple(self): # Condition is single bool list -- cgit v1.2.1 From 4e571172a210612bdeba1db0135b7d5fbc44ee0c Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Wed, 28 Dec 2011 10:01:42 +0100 Subject: BUG: meshgrid: raise error on single input. --- numpy/lib/tests/test_function_base.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 83532e70d..eda919df6 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1025,6 +1025,10 @@ class TestMeshgrid(TestCase): [5, 5, 5], [6, 6, 6], [7, 7, 7]]))) + + def test_single_input(self): + assert_raises(ValueError, meshgrid, np.arange(5)) + def test_indexing(self): [X, Y] = meshgrid([1, 2, 3], [4, 5, 6, 7], indexing='ij') assert_(all(X == array([[1, 1, 1, 1], -- cgit v1.2.1 From 3fb541ef51ca60cf5a903ed83f69120fe3f5373a Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Wed, 28 Dec 2011 10:30:08 +0100 Subject: TST: meshgrid: test expected shapes for Cartesian and matrix indexing. --- numpy/lib/tests/test_function_base.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index eda919df6..57bfee61b 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1030,7 +1030,9 @@ class TestMeshgrid(TestCase): assert_raises(ValueError, meshgrid, np.arange(5)) def test_indexing(self): - [X, Y] = meshgrid([1, 2, 3], [4, 5, 6, 7], indexing='ij') + x = [1, 2, 3] + y = [4, 5, 6, 7] + [X, Y] = meshgrid(x, y, indexing='ij') assert_(all(X == array([[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]))) @@ -1038,6 +1040,15 @@ class TestMeshgrid(TestCase): [4, 5, 6, 7], [4, 5, 6, 7]]))) + # Test expected shapes: + z = [8, 9] + assert_(meshgrid(x, y)[0].shape == (4, 3)) + assert_(meshgrid(x, y, indexing='ij')[0].shape == (3, 4)) + assert_(meshgrid(x, y, z)[0].shape == (4, 3, 2)) + assert_(meshgrid(x, y, z, indexing='ij')[0].shape == (3, 4, 2)) + + assert_raises(ValueError, meshgrid, x, y, indexing='notvalid') + def test_sparse(self): [X, Y] = meshgrid([1, 2, 3], [4, 5, 6, 7], sparse=True) assert_(all(X == array([[1, 2, 3]]))) -- cgit v1.2.1 From d48b756b232c99b6624d76db3188090052e0db60 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Sun, 5 Feb 2012 15:57:00 +0100 Subject: STY: meshgrid: some minor changes to address review comments. --- numpy/lib/tests/test_function_base.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'numpy/lib/tests/test_function_base.py') diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 57bfee61b..b38b39c94 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1052,10 +1052,7 @@ class TestMeshgrid(TestCase): def test_sparse(self): [X, Y] = meshgrid([1, 2, 3], [4, 5, 6, 7], sparse=True) assert_(all(X == array([[1, 2, 3]]))) - assert_(all(Y == array([[4], - [5], - [6], - [7]]))) + assert_(all(Y == array([[4], [5], [6], [7]]))) class TestPiecewise(TestCase): -- cgit v1.2.1