MCPcopy
hub / github.com/numpy/numpy / test_args

Method test_args

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

Source from the content-addressed store, hash-verified

1118 assert_array_equal(gradient(v), dx)
1119
1120 def test_args(self):
1121 dx = np.cumsum(np.ones(5))
1122 dx_uneven = [1., 2., 5., 9., 11.]
1123 f_2d = np.arange(25).reshape(5, 5)
1124
1125 # distances must be scalars or have size equal to gradient[axis]
1126 gradient(np.arange(5), 3.)
1127 gradient(np.arange(5), np.array(3.))
1128 gradient(np.arange(5), dx)
1129 # dy is set equal to dx because scalar
1130 gradient(f_2d, 1.5)
1131 gradient(f_2d, np.array(1.5))
1132
1133 gradient(f_2d, dx_uneven, dx_uneven)
1134 # mix between even and uneven spaces and
1135 # mix between scalar and vector
1136 gradient(f_2d, dx, 2)
1137
1138 # 2D but axis specified
1139 gradient(f_2d, dx, axis=1)
1140
1141 # 2d coordinate arguments are not yet allowed
1142 assert_raises_regex(ValueError, '.*scalars or 1d',
1143 gradient, f_2d, np.stack([dx] * 2, axis=-1), 1)
1144
1145 def test_badargs(self):
1146 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