(self)
| 977 | assert_array_equal(gradient(v), dx) |
| 978 | |
| 979 | def test_args(self): |
| 980 | dx = np.cumsum(np.ones(5)) |
| 981 | dx_uneven = [1., 2., 5., 9., 11.] |
| 982 | f_2d = np.arange(25).reshape(5, 5) |
| 983 | |
| 984 | # distances must be scalars or have size equal to gradient[axis] |
| 985 | gradient(np.arange(5), 3.) |
| 986 | gradient(np.arange(5), np.array(3.)) |
| 987 | gradient(np.arange(5), dx) |
| 988 | # dy is set equal to dx because scalar |
| 989 | gradient(f_2d, 1.5) |
| 990 | gradient(f_2d, np.array(1.5)) |
| 991 | |
| 992 | gradient(f_2d, dx_uneven, dx_uneven) |
| 993 | # mix between even and uneven spaces and |
| 994 | # mix between scalar and vector |
| 995 | gradient(f_2d, dx, 2) |
| 996 | |
| 997 | # 2D but axis specified |
| 998 | gradient(f_2d, dx, axis=1) |
| 999 | |
| 1000 | # 2d coordinate arguments are not yet allowed |
| 1001 | assert_raises_regex(ValueError, '.*scalars or 1d', |
| 1002 | gradient, f_2d, np.stack([dx]*2, axis=-1), 1) |
| 1003 | |
| 1004 | def test_badargs(self): |
| 1005 | f_2d = np.arange(25).reshape(5, 5) |
nothing calls this directly
no test coverage detected