MCPcopy Create free account
hub / github.com/numpy/numpy / test_args

Method test_args

numpy/lib/tests/test_function_base.py:979–1002  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 4

gradientFunction · 0.90
assert_raises_regexFunction · 0.90
cumsumMethod · 0.80
reshapeMethod · 0.80

Tested by

no test coverage detected