MCPcopy
hub / github.com/numpy/numpy / test_second_order_accurate

Method test_second_order_accurate

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

Source from the content-addressed store, hash-verified

1186 assert_array_equal(x2.mask, [False, False, True, False, False])
1187
1188 def test_second_order_accurate(self):
1189 # Testing that the relative numerical error is less that 3% for
1190 # this example problem. This corresponds to second order
1191 # accurate finite differences for all interior and boundary
1192 # points.
1193 x = np.linspace(0, 1, 10)
1194 dx = x[1] - x[0]
1195 y = 2 * x ** 3 + 4 * x ** 2 + 2 * x
1196 analytical = 6 * x ** 2 + 8 * x + 2
1197 num_error = np.abs((np.gradient(y, dx, edge_order=2) / analytical) - 1)
1198 assert_(np.all(num_error < 0.03) == True)
1199
1200 # test with unevenly spaced
1201 rng = np.random.default_rng(0)
1202 x = np.sort(rng.random(10))
1203 y = 2 * x ** 3 + 4 * x ** 2 + 2 * x
1204 analytical = 6 * x ** 2 + 8 * x + 2
1205 num_error = np.abs((np.gradient(y, x, edge_order=2) / analytical) - 1)
1206 assert_(np.all(num_error < 0.03) == True)
1207
1208 def test_spacing(self):
1209 f = np.array([0, 2., 3., 4., 5., 5.])

Callers

nothing calls this directly

Calls 5

assert_Function · 0.90
linspaceMethod · 0.80
randomMethod · 0.80
allMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected