From d86e3fee3c9906ce0fad36520de86d9ac306cee8 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 13 Jul 2017 12:40:05 +0100 Subject: BUG: Allow 0d arrays instead of scalars in gradient This fixes gh-8292 --- numpy/lib/tests/test_function_base.py | 5 ++++- 1 file changed, 4 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 4f21e261f..ee2cc166a 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -742,8 +742,11 @@ class TestGradient(TestCase): # distances must be scalars or have size equal to gradient[axis] gradient(np.arange(5), 3.) + gradient(np.arange(5), np.array(3.)) gradient(np.arange(5), dx) - gradient(f_2d, 1.5) # dy is set equal to dx because scalar + # dy is set equal to dx because scalar + gradient(f_2d, 1.5) + gradient(f_2d, np.array(1.5)) gradient(f_2d, dx_uneven, dx_uneven) # mix between even and uneven spaces and -- cgit v1.2.1 From 2bfec2c0dd92958694e6d736530ae6333d7d62d7 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 13 Jul 2017 12:40:32 +0100 Subject: BUG: Only allow 1d distance arrays 2d arrays would work, but in unpredictable and undocumented ways. This at least makes gh-9401 give a better error message. --- 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 ee2cc166a..d7d00758e 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -756,6 +756,10 @@ class TestGradient(TestCase): # 2D but axis specified gradient(f_2d, dx, axis=1) + # 2d coordinate arguments are not yet allowed + assert_raises_regex(ValueError, '.*scalars or 1d', + gradient, f_2d, np.stack([dx]*2, axis=-1), 1) + def test_badargs(self): f_2d = np.arange(25).reshape(5, 5) x = np.cumsum(np.ones(5)) -- cgit v1.2.1