From 3cdb33f02298c3544f7a3bc312c42422a2a7b971 Mon Sep 17 00:00:00 2001 From: DCtheTall Date: Wed, 31 Mar 2021 17:11:41 -0400 Subject: Add tests np.meshgrid for higher dimensional grids. --- numpy/lib/tests/test_function_base.py | 15 +++++++++++++++ 1 file changed, 15 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 afcb81eff..4201afac3 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2219,6 +2219,7 @@ class TestMsort: [0.64864341, 0.79115165, 0.96098397]])) +# Run test using: python3 runtests.py -t numpy.lib.tests.test_function_base class TestMeshgrid: def test_simple(self): @@ -2307,6 +2308,20 @@ class TestMeshgrid: assert_equal(x[0, :], 0) assert_equal(x[1, :], X) + def test_higher_dimensions(self): + a, b, c = np.meshgrid([0], [1, 1], [2, 2]) + assert_equal(a, [[[0, 0]], [[0, 0]]]) + assert_equal(b, [[[1, 1]], [[1, 1]]]) + assert_equal(c, [[[2, 2]], [[2, 2]]]) + + a, b, c, d, e = np.meshgrid(*([0] * i for i in range(1, 6))) + expected_shape = (2, 1, 3, 4, 5) + assert_equal(a.shape, expected_shape) + assert_equal(b.shape, expected_shape) + assert_equal(c.shape, expected_shape) + assert_equal(d.shape, expected_shape) + assert_equal(e.shape, expected_shape) + class TestPiecewise: -- cgit v1.2.1 From 2a880214c0ffb9c21b12ab51fbb364d71aa17cd1 Mon Sep 17 00:00:00 2001 From: DCtheTall Date: Wed, 31 Mar 2021 17:12:37 -0400 Subject: rm comment --- numpy/lib/tests/test_function_base.py | 1 - 1 file changed, 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 4201afac3..8dcbaa034 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2219,7 +2219,6 @@ class TestMsort: [0.64864341, 0.79115165, 0.96098397]])) -# Run test using: python3 runtests.py -t numpy.lib.tests.test_function_base class TestMeshgrid: def test_simple(self): -- cgit v1.2.1 From 9f339758e3faeb447a629d600f7640c8735a6c4a Mon Sep 17 00:00:00 2001 From: DCtheTall Date: Mon, 5 Apr 2021 15:50:16 -0400 Subject: review comments --- numpy/lib/tests/test_function_base.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 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 8dcbaa034..761ea83a3 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -2307,12 +2307,7 @@ class TestMeshgrid: assert_equal(x[0, :], 0) assert_equal(x[1, :], X) - def test_higher_dimensions(self): - a, b, c = np.meshgrid([0], [1, 1], [2, 2]) - assert_equal(a, [[[0, 0]], [[0, 0]]]) - assert_equal(b, [[[1, 1]], [[1, 1]]]) - assert_equal(c, [[[2, 2]], [[2, 2]]]) - + def test_nd_shape(self): a, b, c, d, e = np.meshgrid(*([0] * i for i in range(1, 6))) expected_shape = (2, 1, 3, 4, 5) assert_equal(a.shape, expected_shape) @@ -2321,6 +2316,18 @@ class TestMeshgrid: assert_equal(d.shape, expected_shape) assert_equal(e.shape, expected_shape) + def test_nd_values(self): + a, b, c = np.meshgrid([0], [1, 2], [3, 4, 5]) + assert_equal(a, [[[0, 0, 0]], [[0, 0, 0]]]) + assert_equal(b, [[[1, 1, 1]], [[2, 2, 2]]]) + assert_equal(c, [[[3, 4, 5]], [[3, 4, 5]]]) + + def test_nd_indexing(self): + a, b, c = np.meshgrid([0], [1, 2], [3, 4, 5], indexing='ij') + assert_equal(a, [[[0, 0, 0], [0, 0, 0]]]) + assert_equal(b, [[[1, 1, 1], [2, 2, 2]]]) + assert_equal(c, [[[3, 4, 5], [3, 4, 5]]]) + class TestPiecewise: -- cgit v1.2.1